Changes in UI. Running downloads get listed on Index now.

This commit is contained in:
Maximilian Wagner
2023-08-03 09:32:27 +02:00
parent b3f49fcacf
commit 06bb8d22dd
6 changed files with 119 additions and 50 deletions

View File

@@ -3,6 +3,7 @@ import yt_dlp as ydl
from yt_dlp import DownloadError from yt_dlp import DownloadError
import os import os
import zipfile import zipfile
from datetime import datetime
from base64 import b64encode from base64 import b64encode
from threading import Thread from threading import Thread
@@ -17,9 +18,14 @@ def enqueue_download(url, update=False):
t = Thread(target=process_general, args=(url,update)) t = Thread(target=process_general, args=(url,update))
thread_queue.append(t) thread_queue.append(t)
t.start() t.start()
return
def process_general(url, update=False): def process_general(url, update=False):
# get current time and put in list to be displayed on /index
current_time = datetime.now().time()
running_downloads.append([url, str(current_time.hour) + ':' + str(current_time.minute)])
# wait for previous thread to finish if not first / only in list # wait for previous thread to finish if not first / only in list
current_thread = threading.current_thread() current_thread = threading.current_thread()
if len(thread_queue) > 0 and thread_queue[0] is not current_thread: if len(thread_queue) > 0 and thread_queue[0] is not current_thread:
@@ -39,6 +45,11 @@ def process_general(url, update=False):
else: else:
process_download(url, parent, query, current_thread) process_download(url, parent, query, current_thread)
try:
running_downloads.pop(0)
except IndexError:
print('*** IndexError: download could not be removed from list of running downloads. ***')
return return

View File

@@ -2,3 +2,4 @@ ids = []
titles = [] titles = []
urls = [] urls = []
thread_queue = [] thread_queue = []
running_downloads = []

View File

@@ -21,12 +21,12 @@ nav.register_element('frontend_top', Navbar(
) )
# there's basically nothing on index # index has a list of running downloads
# todo: a nice homepage or even a login could be nice
# those that have a need for it and are able to make it secure, are invited to open a merge request
@frontend.route('/', methods=['GET']) @frontend.route('/', methods=['GET'])
def index(): def index():
return render_template('index.html') if not running_downloads:
flash('Currently, no downloads are running.')
return render_template('index.html', running_downloads=running_downloads, titles=titles, urls=urls, amount=len(urls))
@frontend.route('/downloader', methods=['GET', 'POST']) @frontend.route('/downloader', methods=['GET', 'POST'])
@@ -46,15 +46,14 @@ def downloader():
# if there has been a problem with the form (empty or error) or the link is not valid # if there has been a problem with the form (empty or error) or the link is not valid
if not form.validate_on_submit() or not valid_link: if not form.validate_on_submit() or not valid_link:
valid_link = True if url == 'None' else False # if url is empty, don't show error valid_link = True if url == 'None' else False # if url is empty, don't show error
return render_template('downloader.html', form=form, ytLink=valid_link, titles=titles, urls=urls, return render_template('downloader.html', form=form, ytLink=valid_link, amount=len(urls))
amount=len(titles))
# kick off download process # kick off download process
enqueue_download(url) enqueue_download(url)
# show download start confirmation # show download start confirmation
flash('Download enqueued and will finish in background.') flash('Download enqueued and will finish in background.')
return render_template('feedback-simple.html', titles=titles, urls=urls, amount=len(titles)) return render_template('feedback-simple.html', amount=len(urls))
# downloads a single file # downloads a single file
@@ -79,6 +78,8 @@ def download(file_path):
@frontend.route('/update', methods=['GET', 'POST']) @frontend.route('/update', methods=['GET', 'POST'])
def updater(): def updater():
downloads = query_db('SELECT name, ROWID FROM playlist') downloads = query_db('SELECT name, ROWID FROM playlist')
if not downloads:
flash('Library has no playlists yet. Try downloading some!')
return render_template('updater.html', downloads=downloads) return render_template('updater.html', downloads=downloads)
@@ -92,13 +93,16 @@ def update(url_rowid):
# show download start confirmation # show download start confirmation
flash('Update enqueued and will finish in background.') flash('Update enqueued and will finish in background.')
return render_template('feedback-simple.html', titles=titles, urls=urls, amount=len(titles)) return render_template('feedback-simple.html', titles=titles, urls=urls, amount=len(urls))
@frontend.route('/library', methods=['GET']) @frontend.route('/library', methods=['GET'])
def library(): def library():
videos = query_db("SELECT name, ext, path FROM video") videos = query_db("SELECT name, ext, path FROM video")
playlists = query_db("SELECT name, ROWID FROM playlist") playlists = query_db("SELECT name, ROWID FROM playlist")
if not playlists and not videos:
flash('Library ist currently empty. Try downloading something!')
return render_template('library.html', videos=videos, playlists=playlists, amount=len(playlists)) return render_template('library.html', videos=videos, playlists=playlists, amount=len(playlists))

View File

@@ -4,7 +4,59 @@
{% block content %} {% block content %}
{{ super() }} {{ super() }}
<div class="container"> <div class="container" style="width: fit-content(105%)">
<a href="http://pythonhosted.org/Flask-Bootstrap">Documentation</a>. </p> {% if running_downloads %}
<div class="card">
<ul class="list-group list-group-flush">
<li class="list-group-item">
<div class="row">
<table id="videos" class="table">
<thead>
<tr>
<th scope="col" class="text-center">Queue</th>
<th scope="col" class="text-center">Started at</th>
</tr>
</thead>
<tbody>
{% for entry in running_downloads %}
<tr>
<td class="text-center"><a href="{{ entry[0] }}" target="_blank">{{ entry[0] }}</a></td>
<td class="text-center">{{ entry[1] }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</li>
</ul>
</div>
<br><br>
{% if titles %}
<div class="card">
<ul class="list-group list-group-flush">
<li class="list-group-item">
<div class="row">
<table id="videos" class="table">
<thead>
<tr>
<th scope="col" class="text-center">Currently processing</th>
</tr>
</thead>
<tbody>
{% for i in range(amount) %}
<tr>
<td class="text-center"><a href="{{ urls[i] }}" target="_blank">{{ titles[i] }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</li>
</ul>
</div>
{% endif %}
{% endif %}
</div> </div>
{%- endblock %} {%- endblock %}

View File

@@ -29,29 +29,32 @@
{% endif %} {% endif %}
<br><br> <br><br>
<div class="card">
<ul class="list-group list-group-flush"> {% if videos %}
<li class="list-group-item"> <div class="card">
<div class="row"> <ul class="list-group list-group-flush">
<table id="videos" class="table"> <li class="list-group-item">
<thead> <div class="row">
<tr> <table id="videos" class="table">
<th scope="col" class="text-center">Title</th> <thead>
<th scope="col" class="text-center">Download</th>
</tr>
</thead>
<tbody>
{% for video in videos %}
<tr> <tr>
<td class="text-center">{{ video['name'] }}</td> <th scope="col" class="text-center">Title</th>
<td class="text-center"><a href="/download/{{ video['path'] + video['name'] + video['ext'] }}" download>Link</a></td> <th scope="col" class="text-center">Download</th>
</tr> </tr>
{% endfor %} </thead>
</tbody> <tbody>
</table> {% for video in videos %}
</div> <tr>
</li> <td class="text-center">{{ video['name'] }}</td>
</ul> <td class="text-center"><a href="/download/{{ video['path'] + video['name'] + video['ext'] }}" download>Link</a></td>
</div> </tr>
{% endfor %}
</tbody>
</table>
</div>
</li>
</ul>
</div>
{% endif %}
</div> </div>
{%- endblock %} {%- endblock %}

View File

@@ -2,30 +2,28 @@
{% block content %} {% block content %}
{{ super() }} {{ super() }}
<div class="container"> <div class="container" style="width: fit-content(105%)">
{% if downloads %} {% if downloads %}
<div class="card" style="width: 100%"> <div class="card">
<ul class="list-group list-group-flush"> <ul class="list-group list-group-flush">
<li class="list-group-item"> <li class="list-group-item">
<div class="row"> <div class="row">
<div class="col-md-5"> <table id="videos" class="table">
<table id="videos" class="table"> <thead>
<thead> <tr>
<th scope="col" class="text-center">Title</th>
<th scope="col" class="text-center">Update</th>
</tr>
</thead>
<tbody>
{% for d in downloads %}
<tr> <tr>
<th scope="col" class="text-center">Title</th> <td class="text-center">{{ d[0] }}</td>
<th scope="col" class="text-center">Update</th> <td class="text-center"><a href="/update/{{ d[1] }}">Start</a></td>
</tr> </tr>
</thead> {% endfor %}
<tbody> </tbody>
{% for d in downloads %} </table>
<tr>
<td class="text-center">{{ d[0] }}</td>
<td class="text-center"><a href="/update/{{ d[1] }}">Start</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div> </div>
</li> </li>
</ul> </ul>