Working list of songs in library

This commit is contained in:
Maximilian Wagner
2023-07-29 23:22:48 +02:00
parent ee47dcaf00
commit 1f070ece5d
10 changed files with 177 additions and 23 deletions

5
.gitignore vendored
View File

@@ -351,4 +351,7 @@ $RECYCLE.BIN/
*.msp
# Windows shortcuts
*.lnk
*.lnk
### Databse ###
*.sqlite

17
.idea/dataSources.xml generated Normal file
View File

@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="files" uuid="7a89bcd0-4ee3-427b-8de5-eb2982c0f7ac">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
<jdbc-url>jdbc:sqlite:C:\Users\maxwe\Documents\VCS\yt-dls\files.sqlite</jdbc-url>
<working-dir>$ProjectFileDir$</working-dir>
<libraries>
<library>
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.40.1/org/xerial/sqlite-jdbc/3.40.1.0/sqlite-jdbc-3.40.1.0.jar</url>
</library>
</libraries>
</data-source>
</component>
</project>

7
.idea/sqldialects.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/schema.sql" dialect="SQLite" />
<file url="PROJECT" dialect="SQLite" />
</component>
</project>

1
.idea/yt-dls.iml generated
View File

@@ -5,6 +5,7 @@
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.11 (yt-dls)" jdkType="Python SDK" />

21
app.py
View File

@@ -1,16 +1,33 @@
from flask import Flask
from flask import Flask, current_app, g
from flask_bootstrap import Bootstrap
from frontend import frontend
from frontend import frontend, get_db
from nav import nav
def init_db():
with current_app.app_context():
db = get_db()
with current_app.open_resource('schema.sql', mode='r') as schema:
db.cursor().executescript(schema.read())
def create_app():
app = Flask(__name__)
Bootstrap(app)
app.config['BOOTSTRAP_SERVE_LOCAL'] = True
app.register_blueprint(frontend)
app.app_context().push()
nav.init_app(app)
init_db()
return app
@frontend.teardown_request
def close_connection(exception):
db = getattr(g, '_database', None)
if db is not None:
db.close()

View File

@@ -1,7 +1,7 @@
from flask import Blueprint, render_template, flash, redirect, url_for
from flask_bootstrap import __version__ as BOOTSTRAP_VERSION
from flask_nav3.elements import Navbar, View, Subgroup, Link, Text, Separator
from markupsafe import escape
from flask import Blueprint, render_template, send_from_directory, request, current_app, g
from flask_nav3.elements import Navbar, View
import sqlite3
import os
from nav import nav
@@ -16,21 +16,58 @@ nav.register_element('frontend_top', Navbar(
)
@frontend.route('/')
@frontend.route('/', methods=['GET'])
def index():
return render_template('index.html')
@frontend.route('/downloader')
@frontend.route('/downloader', methods=['GET', 'POST'])
def downloader():
return render_template('downloader.html')
if request.method == 'GET':
return render_template('downloader.html')
else:
return 'Hello there!'
@frontend.route('/update')
@frontend.route('/download/<path:file>', methods=['GET'])
def download(file):
dir = os.path.join(current_app.root_path, 'downloads/')
return send_from_directory(dir, )
@frontend.route('/update', methods=['GET', 'POST'])
def updater():
return render_template('updater.html')
@frontend.route('/library')
@frontend.route('/library', methods=['GET'])
def library():
return render_template('library.html')
videos = query_db("SELECT name FROM video")
playlists = query_db("SELECT name FROM playlist")
return render_template('library.html', videos=videos, playlists=playlists)
@frontend.route("/collection")
def collection():
query = query_db("""
SELECT video.name FROM video
INNER JOIN collection ON collection.path = video.path
INNER JOIN playlist ON playlist.ROWID = collection.playlist
WHERE video.name IS ?;
""", ("",))
return render_template('collection.html', query=query)
def get_db():
db = getattr(g, '_database', None)
if db is None:
db = g._database = sqlite3.connect('files.sqlite')
db.row_factory = sqlite3.Row
return db
def query_db(query, args=(), one=False):
cur = get_db().execute(query, args)
res = cur.fetchall()
cur.close()
return (res[0] if res else None) if one else res

View File

@@ -3,3 +3,4 @@ flask_sqlalchemy
flask_bootstrap
flask_nav3
flask_login
flask_wtf

13
schema.sql Normal file
View File

@@ -0,0 +1,13 @@
CREATE TABLE IF NOT EXISTS video (
filename TEXT PRIMARY KEY NOT NULL,
name TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS playlist (
name TEXT NOT NULL
);
CREATE TABLE IF NOT EXISTS collection (
playlist INTEGER NOT NULL,
path TEXT NOT NULL
);

28
templates/collection.html Normal file
View File

@@ -0,0 +1,28 @@
{%- extends "base.html" %}
{% import "bootstrap/utils.html" as utils %}
{% block content %}
<div class="container">
{%- with messages = get_flashed_messages(with_categories=True) %}
{%- if messages %}
<div class="row">
<div class="col-md-12">
{{utils.flashed_messages(messages)}}
</div>
</div>
{%- endif %}
{%- endwith %}
</div>
<div class="container">
<table id="library" style="width:80%">
{% for name in query %}
<tr>
<td>{{ name }}</td>
<td>Download</td>
</tr>
{% endfor %}
</table>
</div>
{%- endblock %}

View File

@@ -3,15 +3,45 @@
{% import "bootstrap/utils.html" as utils %}
{% block content %}
<div class="container">
{%- with messages = get_flashed_messages(with_categories=True) %}
{%- if messages %}
<div class="row">
<div class="col-md-12">
{{utils.flashed_messages(messages)}}
</div>
</div>
{%- endif %}
{%- endwith %}
<div class="container">
<div class="row">
<div class="col-md-5">
<table id="videos" class="table">
<thead>
<tr>
<th scope="col" class="text-center">Song</th>
<th scope="col" class="text-center">Download</th>
</tr>
</thead>
<tbody>
{% for video in videos %}
<tr>
<td class="text-center">{{ video['name'] }}</td>
<td class="text-center">Link</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="col-md-1"></div>
<div class="col-md-2">
<table id="playlists" class="table">
<thead>
<tr>
<th scope="col" class="text-center">Playlists</th>
</tr>
</thead>
<tbody>
{% for playlist in playlists %}
<tr>
<td class="text-center">{{ playlist['name'] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
{%- endblock %}