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