make it use flask and not be static pages anymore
This commit is contained in:
parent
6880b57844
commit
1f6d448c74
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/songbook.sqlite
|
||||
/public/
|
||||
/static/clip/
|
||||
/__pycache__/
|
||||
43
app.py
Normal file
43
app.py
Normal file
@ -0,0 +1,43 @@
|
||||
import flask
|
||||
import sqlite3
|
||||
|
||||
app = flask.Flask('songbook')
|
||||
|
||||
@app.route('/song/<int:id>')
|
||||
def songpage(id):
|
||||
|
||||
db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True)
|
||||
|
||||
name, = db.execute('''
|
||||
select
|
||||
name
|
||||
from
|
||||
song
|
||||
where
|
||||
id = ?
|
||||
''',
|
||||
(id,)
|
||||
).fetchone()
|
||||
|
||||
# query album info
|
||||
|
||||
album_info = db.execute('''
|
||||
select
|
||||
album_id, track, album.name, album.code
|
||||
from
|
||||
song_album
|
||||
join
|
||||
album
|
||||
on
|
||||
song_album.album_id=album.id
|
||||
where
|
||||
song_id = ?
|
||||
''',
|
||||
(id,)
|
||||
).fetchall()
|
||||
|
||||
return flask.render_template('song.jinja',
|
||||
name=name,
|
||||
id=id,
|
||||
album_info=album_info
|
||||
)
|
||||
@ -4,8 +4,8 @@ import glob
|
||||
import shutil
|
||||
import sox
|
||||
|
||||
shutil.rmtree('public/clip')
|
||||
os.makedirs('public/clip', exist_ok=True)
|
||||
shutil.rmtree('static/clip')
|
||||
os.makedirs('static/clip', exist_ok=True)
|
||||
|
||||
db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True)
|
||||
|
||||
@ -37,7 +37,7 @@ for song, motif, start, duration, album, track in db.execute('''
|
||||
|
||||
# get clip filename
|
||||
|
||||
destination = f'public/clip/{song:04}-{motif:03}.flac'
|
||||
destination = f'static/clip/{song:04}-{motif:03}.flac'
|
||||
|
||||
print(destination)
|
||||
|
||||
|
||||
@ -1,54 +0,0 @@
|
||||
import sqlite3
|
||||
import jinja2
|
||||
import os
|
||||
import shutil
|
||||
|
||||
for dirname in [
|
||||
"public/song",
|
||||
"public/motif",
|
||||
"public/album"
|
||||
]:
|
||||
os.makedirs(dirname, exist_ok=True)
|
||||
|
||||
environment = jinja2.Environment(loader=jinja2.FileSystemLoader("templates/"))
|
||||
songplate = environment.get_template("songpage.jinja")
|
||||
|
||||
db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True)
|
||||
|
||||
# generate song pages
|
||||
|
||||
for id, name, name_jp in db.execute('''
|
||||
select
|
||||
id, name, name_jp
|
||||
from
|
||||
song
|
||||
'''):
|
||||
|
||||
# query album info
|
||||
|
||||
album_info = db.execute('''
|
||||
select
|
||||
album_id, track, album.name, album.code
|
||||
from
|
||||
song_album
|
||||
join
|
||||
album
|
||||
on
|
||||
song_album.album_id=album.id
|
||||
where
|
||||
song_id = ?
|
||||
''',
|
||||
(id,)
|
||||
).fetchall()
|
||||
|
||||
print(album_info)
|
||||
|
||||
filename = f"public/song/{id:04}"
|
||||
content = songplate.render(
|
||||
name=name,
|
||||
id=id,
|
||||
album_info=album_info
|
||||
)
|
||||
with open(filename, mode="w") as file:
|
||||
file.write(content)
|
||||
print(f"... wrote {filename}")
|
||||
@ -3,10 +3,10 @@ eorzea-songbook.com/
|
||||
index.html
|
||||
|
||||
/song
|
||||
/name
|
||||
/id
|
||||
|
||||
/motif
|
||||
/name
|
||||
/id
|
||||
|
||||
/album
|
||||
/name
|
||||
/id
|
||||
76
poetry.lock
generated
76
poetry.lock
generated
@ -1,3 +1,57 @@
|
||||
[[package]]
|
||||
name = "blinker"
|
||||
version = "1.6.2"
|
||||
description = "Fast, simple object-to-object and broadcast signaling"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[[package]]
|
||||
name = "click"
|
||||
version = "8.1.3"
|
||||
description = "Composable command line interface toolkit"
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[package.dependencies]
|
||||
colorama = {version = "*", markers = "platform_system == \"Windows\""}
|
||||
|
||||
[[package]]
|
||||
name = "colorama"
|
||||
version = "0.4.6"
|
||||
description = "Cross-platform colored terminal text."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
|
||||
|
||||
[[package]]
|
||||
name = "flask"
|
||||
version = "2.3.2"
|
||||
description = "A simple framework for building complex web applications."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
|
||||
[package.dependencies]
|
||||
blinker = ">=1.6.2"
|
||||
click = ">=8.1.3"
|
||||
itsdangerous = ">=2.1.2"
|
||||
Jinja2 = ">=3.1.2"
|
||||
Werkzeug = ">=2.3.3"
|
||||
|
||||
[package.extras]
|
||||
async = ["asgiref (>=3.2)"]
|
||||
dotenv = ["python-dotenv"]
|
||||
|
||||
[[package]]
|
||||
name = "itsdangerous"
|
||||
version = "2.1.2"
|
||||
description = "Safely pass data to untrusted environments and back."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
|
||||
[[package]]
|
||||
name = "jinja2"
|
||||
version = "3.1.2"
|
||||
@ -93,12 +147,31 @@ numpy = ">=1.9.0"
|
||||
docs = ["sphinx (==1.2.3)", "sphinxcontrib-napoleon", "sphinx-rtd-theme", "numpydoc"]
|
||||
tests = ["pytest", "pytest-cov", "pytest-pep8", "pysoundfile (>=0.9.0)"]
|
||||
|
||||
[[package]]
|
||||
name = "werkzeug"
|
||||
version = "2.3.4"
|
||||
description = "The comprehensive WSGI web application library."
|
||||
category = "main"
|
||||
optional = false
|
||||
python-versions = ">=3.8"
|
||||
|
||||
[package.dependencies]
|
||||
MarkupSafe = ">=2.1.1"
|
||||
|
||||
[package.extras]
|
||||
watchdog = ["watchdog (>=2.3)"]
|
||||
|
||||
[metadata]
|
||||
lock-version = "1.1"
|
||||
python-versions = "^3.10"
|
||||
content-hash = "e2e818660fff102eebe62dc32854ab0171cf72c277a25897ee4ee2f732e8498d"
|
||||
content-hash = "eb105df2967c9247e5d32c49b9996442ba31976fb4da0c99bffa003aa8242182"
|
||||
|
||||
[metadata.files]
|
||||
blinker = []
|
||||
click = []
|
||||
colorama = []
|
||||
flask = []
|
||||
itsdangerous = []
|
||||
jinja2 = []
|
||||
lml = []
|
||||
lxml = []
|
||||
@ -107,3 +180,4 @@ numpy = []
|
||||
pyexcel-io = []
|
||||
pyexcel-odsr = []
|
||||
sox = []
|
||||
werkzeug = []
|
||||
|
||||
@ -9,6 +9,7 @@ python = "^3.10"
|
||||
sox = "^1.4.1"
|
||||
Jinja2 = "^3.1.2"
|
||||
pyexcel-odsr = "^0.6.0"
|
||||
Flask = "^2.3.2"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
|
||||
|
||||
14
templates/base.jinja
Normal file
14
templates/base.jinja
Normal file
@ -0,0 +1,14 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>{% block title %}{% endblock %} - Eorzea Songbook</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<script src="script.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
{% block content %}{% endblock %}
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -1,12 +1,7 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>title</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<script src="script.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
{% extends "base.jinja" %}
|
||||
{% 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>
|
||||
<p>Artist: </p>
|
||||
@ -16,6 +11,10 @@
|
||||
<li>{{ album_name }} #{{ track }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<p>blah</p>
|
||||
<p>Clips: </p>
|
||||
</body>
|
||||
</html>
|
||||
<audio
|
||||
controls
|
||||
src = "/static/clip/0001-001.flac">
|
||||
</audio>
|
||||
{% endblock %}
|
||||
Loading…
Reference in New Issue
Block a user