diff --git a/.gitignore b/.gitignore index 33ed238..0ae6422 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /songbook.sqlite -/public/ \ No newline at end of file +/static/clip/ +/__pycache__/ \ No newline at end of file diff --git a/app.py b/app.py new file mode 100644 index 0000000..e8d1ddf --- /dev/null +++ b/app.py @@ -0,0 +1,43 @@ +import flask +import sqlite3 + +app = flask.Flask('songbook') + +@app.route('/song/') +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 + ) \ No newline at end of file diff --git a/build_clips.py b/build_clips.py index 1dc6a06..e3c49fb 100644 --- a/build_clips.py +++ b/build_clips.py @@ -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) diff --git a/build_pages.py b/build_pages.py deleted file mode 100644 index dc240fd..0000000 --- a/build_pages.py +++ /dev/null @@ -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}") \ No newline at end of file diff --git a/notes.txt b/notes.txt index 9a644e7..a90521f 100644 --- a/notes.txt +++ b/notes.txt @@ -3,10 +3,10 @@ eorzea-songbook.com/ index.html /song - /name + /id /motif - /name + /id /album - /name \ No newline at end of file + /id \ No newline at end of file diff --git a/poetry.lock b/poetry.lock index 434e398..d6261b3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -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 = [] diff --git a/pyproject.toml b/pyproject.toml index 47d2742..19356cd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/templates/base.jinja b/templates/base.jinja new file mode 100644 index 0000000..0f422f8 --- /dev/null +++ b/templates/base.jinja @@ -0,0 +1,14 @@ + + + + {% block title %}{% endblock %} - Eorzea Songbook + + + + + + {% block content %}{% endblock %} + + + + \ No newline at end of file diff --git a/templates/songpage.jinja b/templates/song.jinja similarity index 63% rename from templates/songpage.jinja rename to templates/song.jinja index 5cbbeed..fb57ddb 100644 --- a/templates/songpage.jinja +++ b/templates/song.jinja @@ -1,12 +1,7 @@ - - - - title - - - - +{% extends "base.jinja" %} +{% block title %}{{ name }}{% endblock %} +{% block content %}

Now Playing: {{ id }}. {{ name }} ({% for _, _, _, album_code in album_info %}{{ album_code }}{% if not loop.last %}, {% endif %}{% endfor %})

Artist:

@@ -16,6 +11,10 @@
  • {{ album_name }} #{{ track }}
  • {% endfor %} +

    blah

    Clips:

    - - + +{% endblock %}