UI improvements
This commit is contained in:
@@ -12,7 +12,6 @@ from shutil import rmtree
|
||||
|
||||
from db_tools import (
|
||||
add_new_video_to_collection,
|
||||
query_db,
|
||||
query_db_threaded,
|
||||
db_add_via_update,
|
||||
db_add_via_download,
|
||||
|
||||
24
db_tools.py
24
db_tools.py
@@ -96,29 +96,27 @@ def update_playlist_folder_by_rowid(folder, rowid):
|
||||
|
||||
|
||||
# removes a single video
|
||||
def remove_video(file_name: str) -> bool:
|
||||
def remove_video(file_name):
|
||||
folder, name, ext = dissect_file_name(file_name)
|
||||
|
||||
rowid = query_db('DELETE FROM video '
|
||||
'WHERE name = :name AND path = :path AND ext = :ext '
|
||||
'RETURNING ROWID',
|
||||
{'name': name, 'path': folder, 'ext': ext},
|
||||
True)
|
||||
query_db('DELETE FROM video '
|
||||
'WHERE name = :name AND path = :path AND ext = :ext',
|
||||
{'name': name, 'path': folder, 'ext': ext})
|
||||
|
||||
return True if rowid else False
|
||||
return
|
||||
|
||||
|
||||
# removes playlist and all contained videos from db
|
||||
def remove_playlist(folder):
|
||||
rescued = rescue_videos(folder)
|
||||
|
||||
query_db_threaded('DELETE FROM playlist '
|
||||
'WHERE folder = :folder',
|
||||
{'folder': folder})
|
||||
query_db('DELETE FROM playlist '
|
||||
'WHERE folder = :folder',
|
||||
{'folder': folder})
|
||||
|
||||
query_db_threaded('DELETE FROM collection '
|
||||
'WHERE playlist = :folder ',
|
||||
{'folder': folder})
|
||||
query_db('DELETE FROM collection '
|
||||
'WHERE playlist = :folder ',
|
||||
{'folder': folder})
|
||||
|
||||
query_db('DELETE FROM video '
|
||||
'WHERE path = :path ',
|
||||
|
||||
43
frontend.py
43
frontend.py
@@ -1,9 +1,14 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
from flask import Blueprint, request, render_template, flash, send_from_directory, send_file
|
||||
|
||||
from forms.download import DownloadForm
|
||||
from flask import (
|
||||
Blueprint,
|
||||
request,
|
||||
render_template,
|
||||
redirect,
|
||||
flash,
|
||||
send_from_directory,
|
||||
send_file
|
||||
)
|
||||
from backend import (
|
||||
zip_folder,
|
||||
zip_folder_not_in_directory,
|
||||
@@ -11,6 +16,7 @@ from backend import (
|
||||
internet_available,
|
||||
delete_file_or_playlist
|
||||
)
|
||||
from forms.download import DownloadForm
|
||||
from db_tools import query_db
|
||||
from file_cache import *
|
||||
from utils import downloads_path, dissect_file_name
|
||||
@@ -91,14 +97,16 @@ def library_playlist():
|
||||
|
||||
|
||||
# sends file or playlist to client
|
||||
@frontend.route('/download/<path:file_path>', methods=['GET'])
|
||||
def download(file_path):
|
||||
@frontend.route('/download', methods=['GET'])
|
||||
def download():
|
||||
file_path = request.args.get('file')
|
||||
# if the path does not end with a slash, a single file is requested
|
||||
if '.' in file_path:
|
||||
path, name, _ = dissect_file_name(file_path)
|
||||
path, name, ext = dissect_file_name(file_path)
|
||||
|
||||
video = query_db('SELECT path, name, ext FROM video WHERE name = :name AND path = :path',
|
||||
{'name': name, 'path': path},
|
||||
video = query_db('SELECT path, name, ext FROM video '
|
||||
'WHERE name = :name AND path = :path AND ext = :ext',
|
||||
{'name': name, 'path': path, 'ext': ext},
|
||||
True)
|
||||
|
||||
return send_from_directory(
|
||||
@@ -119,8 +127,9 @@ def download(file_path):
|
||||
)
|
||||
|
||||
|
||||
@frontend.route('/delete/<path:file_name>', methods=['GET'])
|
||||
def delete(file_name):
|
||||
@frontend.route('/delete', methods=['GET'])
|
||||
def delete():
|
||||
file_name = request.args.get('file')
|
||||
delete_file_or_playlist(file_name)
|
||||
|
||||
if '.' in file_name:
|
||||
@@ -128,20 +137,22 @@ def delete(file_name):
|
||||
else:
|
||||
flash('Playlist has been deleted.', 'primary')
|
||||
|
||||
return render_template('flash-message.html')
|
||||
return redirect('/library')
|
||||
|
||||
|
||||
@frontend.route('/update/<int:url_rowid>', methods=['GET'])
|
||||
def update(url_rowid):
|
||||
@frontend.route('/update', methods=['GET'])
|
||||
def update():
|
||||
url_rowid = request.args.get('list')
|
||||
url = query_db('SELECT url FROM playlist WHERE ROWID = :url_rowid',
|
||||
{'url_rowid': url_rowid})[0][0]
|
||||
{'url_rowid': url_rowid},
|
||||
True)[0]
|
||||
|
||||
# kick off download process
|
||||
enqueue_download(url, update=True)
|
||||
|
||||
# show download start confirmation
|
||||
flash('Update enqueued and will finish in background.', 'primary')
|
||||
return render_template('flash-message.html', titles=titles, urls=urls, amount=len(urls))
|
||||
return redirect(request.args.get('from'))
|
||||
|
||||
|
||||
# player as well as serve are placeholders for now
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
{% for video in videos %}
|
||||
<tr>
|
||||
<td class="text-center">{{ video['name'] }}</td>
|
||||
<td class="text-center"><a class="btn btn-link" href="/download/{{ video['path'] + video['name'] + video['ext'] }}" download>Download</a></td>
|
||||
<td class="text-center"><a class="btn btn-link" href="/download?file={{ video['path'] + video['name'] + video['ext'] }}" download>Download</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
@@ -25,12 +25,19 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="container" style="padding: 1.5%">
|
||||
<form action="/delete/{{ folder }}">
|
||||
<form action="/delete">
|
||||
<input type="hidden" name="file" value="{{ folder }}">
|
||||
<input type="submit" class="btn btn-danger float-start" value="Delete playlist">
|
||||
</form>
|
||||
<form action="/download/{{ folder }}">
|
||||
<form action="/download">
|
||||
<input type="hidden" name="file" value="{{ folder }}">
|
||||
<input type="submit" class="btn btn-primary float-end" value="Download all"/>
|
||||
</form>
|
||||
<form action="/update" style="padding-right: 30%">
|
||||
<input type="hidden" name="list" value="{{ request.args.get('playlist') }}">
|
||||
<input type="hidden" name="from" value="/library-playlist?playlist={{ request.args.get('playlist') }}">
|
||||
<input type="submit" class="btn btn-primary float-end" value="Update playlist"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{%- endblock %}
|
||||
@@ -27,14 +27,5 @@
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if form.errors %}
|
||||
{{ form.errors['url'][0][:-1] + ', try again.' }}
|
||||
{% endif %}
|
||||
|
||||
{% if not ytLink %}
|
||||
Please enter a full, valid YouTube URL.
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
{%- endblock %}
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
<br><br>
|
||||
|
||||
{% if titles %}
|
||||
{% if titles and titles[0] not in running_downloads[0][0] %}
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<table class="table">
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
{% for playlist in playlists %}
|
||||
<tr>
|
||||
<td class="text-center align-middle"><a class="btn btn-link" href="/library-playlist?playlist={{ playlist['ROWID'] }}">{{ playlist['name'] }}</a></td>
|
||||
<td class="text-center align-middle"><a class="btn btn-link" href="/update/{{ playlist[1] }}">Start</a></td>
|
||||
<td class="text-center align-middle"><a class="btn btn-link" href="/update?list={{ playlist[1] }}&from=/library">Start</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
@@ -36,6 +36,7 @@
|
||||
<tr>
|
||||
<th scope="col" class="text-center align-middle">Titles not in any playlist</th>
|
||||
<th scope="col" class="text-center align-middle">Download</th>
|
||||
<th scope="col" class="text-center align-middle">Delete</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -43,14 +44,16 @@
|
||||
{% if 'mp3' in video['ext'] %}
|
||||
<tr>
|
||||
<td class="text-center align-middle">{{ video['name'] }}</td>
|
||||
<td class="text-center align-middle"><a class="btn btn-link" href="/download/{{ video['path'] + video['name'] + video['ext'] }}" download>Download</a></td>
|
||||
<td class="text-center align-middle"><a class="btn btn-link" href="/download?file={{ video['path'] + video['name'] + video['ext'] }}" download>Download</a></td>
|
||||
<td class="text-center align-middle"><a class="btn btn-danger" href="/delete?file={{ video['path'] + video['name'] + video['ext'] }}&from=/library"> </a></td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
|
||||
{% if 'mp4' in video['ext'] %}
|
||||
<tr>
|
||||
<td class="text-center align-middle">{{ video['name'] }}</td>
|
||||
<td class="text-center align-middle"><a class="btn btn-link" href="/player?file={{ video['path'] + video['name'] + video['ext'] }}">Watch</a></td>
|
||||
<td class="text-center align-middle"><a class="btn btn-link" href="/player?file={{ video['path'] + video['name'] + video['ext'] }}">{{ video['name'] }}</a></td>
|
||||
<td class="text-center align-middle"><a class="btn btn-link" href="/download?file={{ video['path'] + video['name'] + video['ext'] }}" download>Download</a></td>
|
||||
<td class="text-center align-middle"><a class="btn btn-danger" href="/delete?file={{ video['path'] + video['name'] + video['ext'] }}&from=library"> </a>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
Reference in New Issue
Block a user