orders database queries and adds motif types
This commit is contained in:
parent
6c8a9b1da0
commit
1d39f61d48
103
app.py
103
app.py
@ -3,6 +3,100 @@ import sqlite3
|
||||
|
||||
app = flask.Flask('songbook')
|
||||
|
||||
# BLANK PAGE
|
||||
|
||||
# @app.route('/album/<int:id>')
|
||||
# def page(id):
|
||||
|
||||
# db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True)
|
||||
|
||||
# return flask.render_template('motif.jinja',
|
||||
# )
|
||||
|
||||
# ALBUM PAGES
|
||||
|
||||
@app.route('/album/<int:id>')
|
||||
def albumpage(id):
|
||||
|
||||
db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True)
|
||||
|
||||
album_info = db.execute('''
|
||||
select
|
||||
name, date
|
||||
from
|
||||
album
|
||||
where
|
||||
id = ?
|
||||
''',
|
||||
(id,)
|
||||
).fetchone()
|
||||
|
||||
song_info = db.execute('''
|
||||
select
|
||||
song_id, track, song.name, song.name_jp
|
||||
from
|
||||
song_album
|
||||
join
|
||||
song
|
||||
on
|
||||
song_album.song_id=song.id
|
||||
where
|
||||
album_id = ?
|
||||
''',
|
||||
(id,)
|
||||
).fetchall()
|
||||
|
||||
return flask.render_template('album.jinja',
|
||||
album_info=album_info,
|
||||
song_info=song_info
|
||||
)
|
||||
|
||||
# MOTIF PAGES
|
||||
|
||||
@app.route('/motif/<int:id>')
|
||||
def motifpage(id):
|
||||
|
||||
db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True)
|
||||
|
||||
# query motif
|
||||
|
||||
name, = db.execute('''
|
||||
select
|
||||
name
|
||||
from
|
||||
motif
|
||||
where
|
||||
id = ?
|
||||
''',
|
||||
(id,)
|
||||
).fetchone()
|
||||
|
||||
# query clips
|
||||
|
||||
clip_info = db.execute('''
|
||||
select
|
||||
song_id, motif_id, song.name
|
||||
from
|
||||
clip
|
||||
join
|
||||
song
|
||||
on
|
||||
clip.song_id=song.id
|
||||
where
|
||||
motif_id = ?
|
||||
order by
|
||||
song_id
|
||||
''',
|
||||
(id,)
|
||||
).fetchall()
|
||||
|
||||
return flask.render_template('motif.jinja',
|
||||
name=name,
|
||||
clip_info=clip_info
|
||||
)
|
||||
|
||||
# SONG PAGES
|
||||
|
||||
@app.route('/song/<int:id>')
|
||||
def songpage(id):
|
||||
|
||||
@ -25,7 +119,7 @@ def songpage(id):
|
||||
|
||||
album_info = db.execute('''
|
||||
select
|
||||
track, album.name, album.code
|
||||
album_id, track, album.name, album.code
|
||||
from
|
||||
song_album
|
||||
join
|
||||
@ -34,6 +128,8 @@ def songpage(id):
|
||||
song_album.album_id=album.id
|
||||
where
|
||||
song_id = ?
|
||||
order by
|
||||
album_id
|
||||
''',
|
||||
(id,)
|
||||
).fetchall()
|
||||
@ -55,6 +151,9 @@ def songpage(id):
|
||||
song_artist.credit_id=credit.id
|
||||
where
|
||||
song_id = ?
|
||||
order by
|
||||
credit_id,
|
||||
artist.name_rm
|
||||
''',
|
||||
(id,)
|
||||
).fetchall()
|
||||
@ -72,6 +171,8 @@ def songpage(id):
|
||||
clip.motif_id=motif.id
|
||||
where
|
||||
song_id = ?
|
||||
order by
|
||||
song_id
|
||||
''',
|
||||
(id,)
|
||||
).fetchall()
|
||||
|
||||
14
build_db.py
14
build_db.py
@ -10,8 +10,8 @@ cur = db.cursor()
|
||||
with open('db.sql') as file:
|
||||
db.executescript(file.read())
|
||||
|
||||
data = pyexcel_odsr.get_data('reference.ods')
|
||||
clipdata = pyexcel_odsr.get_data('reference_clips.ods')
|
||||
data = pyexcel_odsr.get_data('reference.ods', skip_empty_rows=True)
|
||||
clipdata = pyexcel_odsr.get_data('reference_clips.ods', skip_empty_rows=True)
|
||||
|
||||
# import song
|
||||
cur.executemany(
|
||||
@ -37,18 +37,16 @@ cur.executemany(
|
||||
data['Credit'][1:]
|
||||
)
|
||||
|
||||
print(clipdata['Motif'][1:])
|
||||
|
||||
# import motif
|
||||
cur.executemany(
|
||||
'insert into motif(id,name) values(?, ?)',
|
||||
clipdata['Motif'][1:]
|
||||
'insert into motif(id,name,type) values(?, ?, ?)',
|
||||
((row[0],row[1],'' if len(row)<3 else row[2]) for row in clipdata['Motif'][1:])
|
||||
)
|
||||
|
||||
# import clip
|
||||
cur.executemany(
|
||||
'insert into clip(start_ms,duration_ms,song_id,motif_id) values (?, ?, ?, ?)',
|
||||
clipdata['Clip'][1:]
|
||||
'insert into clip(start_ms,duration_ms,song_id,motif_id,feature) values (?, ?, ?, ?, ?)',
|
||||
((row[0],row[1],row[2],row[3],0 if len(row)<5 else row[4]) for row in clipdata['Clip'][1:])
|
||||
)
|
||||
|
||||
# import song x album
|
||||
|
||||
4
db.sql
4
db.sql
@ -31,7 +31,8 @@ create table credit(
|
||||
|
||||
create table motif(
|
||||
id int primary key,
|
||||
name text not null
|
||||
name text not null,
|
||||
type int not null
|
||||
);
|
||||
|
||||
create table clip(
|
||||
@ -39,6 +40,7 @@ create table clip(
|
||||
motif_id int not null references motif(id),
|
||||
start_ms int not null,
|
||||
duration_ms int not null,
|
||||
feature int not null,
|
||||
primary key(song_id,motif_id)
|
||||
);
|
||||
|
||||
|
||||
BIN
reference.ods
BIN
reference.ods
Binary file not shown.
Binary file not shown.
16
templates/album.jinja
Normal file
16
templates/album.jinja
Normal file
@ -0,0 +1,16 @@
|
||||
{% extends "base.jinja" %}
|
||||
{% block title %}{{ album_info[0] }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>{{ album_info[0] }}</h1>
|
||||
<p>Released: {{ album_info[1] }}
|
||||
|
||||
<!-- List songs -->
|
||||
<ul>
|
||||
{% for id, track, name, name_jp in song_info %}
|
||||
<li><a href="/song/{{ id }}">#{{ track }}: {{name}} / {{name_jp}}</li></a>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
{% endblock %}
|
||||
22
templates/motif.jinja
Normal file
22
templates/motif.jinja
Normal file
@ -0,0 +1,22 @@
|
||||
{% extends "base.jinja" %}
|
||||
|
||||
{% block title %}{{ name }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1> Motif: {{ name }} </h1>
|
||||
|
||||
<!-- Clips -->
|
||||
|
||||
<p>Clips: </p>
|
||||
<ul>
|
||||
{% for song_id, motif_id, song in clip_info %}
|
||||
<li>
|
||||
<audio
|
||||
controls
|
||||
src = "/static/clip/{{ '%04d' % song_id }}-{{ '%03d' % motif_id }}.flac">
|
||||
</audio>
|
||||
<a href="/song/{{ song_id }}">{{ song }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
||||
{% endblock %}
|
||||
@ -2,7 +2,7 @@
|
||||
{% block title %}{{ name }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Now Playing: {{ id }}. {{ name }} ({% for _, _, album_code in album_info %}{{ album_code }}{% if not loop.last %}, {% endif %}{% endfor %})
|
||||
<h1>Now Playing: {{ id }}. {{ name }} ({% for _, _, _, album_code in album_info %}{{ album_code }}{% if not loop.last %}, {% endif %}{% endfor %})
|
||||
</h1>
|
||||
|
||||
<!-- Artist info -->
|
||||
@ -18,11 +18,13 @@
|
||||
|
||||
<p>Album: </p>
|
||||
<ul>
|
||||
{% for track, album_name, album_code in album_info %}
|
||||
<li>{{ album_name }} #{{ track }}</li>
|
||||
{% for id, track, album_name, album_code in album_info %}
|
||||
<li><a href="/album/{{ id }}">{{ album_name }}</a> #{{ track }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<!-- Clips -->
|
||||
|
||||
<p>Clips: </p>
|
||||
<ul>
|
||||
{% for song_id, motif_id, motif in clip_info %}
|
||||
@ -30,7 +32,8 @@
|
||||
<audio
|
||||
controls
|
||||
src = "/static/clip/{{ '%04d' % song_id }}-{{ '%03d' % motif_id }}.flac">
|
||||
</audio> {{ motif }}
|
||||
</audio>
|
||||
<a href = "/motif/{{ motif_id }}"> {{ motif }} </a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user