Changes in UI. Running downloads get listed on Index now.
This commit is contained in:
11
backend.py
11
backend.py
@@ -3,6 +3,7 @@ import yt_dlp as ydl
|
||||
from yt_dlp import DownloadError
|
||||
import os
|
||||
import zipfile
|
||||
from datetime import datetime
|
||||
|
||||
from base64 import b64encode
|
||||
from threading import Thread
|
||||
@@ -17,9 +18,14 @@ def enqueue_download(url, update=False):
|
||||
t = Thread(target=process_general, args=(url,update))
|
||||
thread_queue.append(t)
|
||||
t.start()
|
||||
return
|
||||
|
||||
|
||||
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
|
||||
current_thread = threading.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:
|
||||
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
|
||||
|
||||
|
||||
|
||||
@@ -2,3 +2,4 @@ ids = []
|
||||
titles = []
|
||||
urls = []
|
||||
thread_queue = []
|
||||
running_downloads = []
|
||||
|
||||
20
frontend.py
20
frontend.py
@@ -21,12 +21,12 @@ nav.register_element('frontend_top', Navbar(
|
||||
)
|
||||
|
||||
|
||||
# there's basically nothing on index
|
||||
# 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
|
||||
# index has a list of running downloads
|
||||
@frontend.route('/', methods=['GET'])
|
||||
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'])
|
||||
@@ -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 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
|
||||
return render_template('downloader.html', form=form, ytLink=valid_link, titles=titles, urls=urls,
|
||||
amount=len(titles))
|
||||
return render_template('downloader.html', form=form, ytLink=valid_link, amount=len(urls))
|
||||
|
||||
# kick off download process
|
||||
enqueue_download(url)
|
||||
|
||||
# show download start confirmation
|
||||
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
|
||||
@@ -79,6 +78,8 @@ def download(file_path):
|
||||
@frontend.route('/update', methods=['GET', 'POST'])
|
||||
def updater():
|
||||
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)
|
||||
|
||||
|
||||
@@ -92,13 +93,16 @@ def update(url_rowid):
|
||||
|
||||
# show download start confirmation
|
||||
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'])
|
||||
def library():
|
||||
videos = query_db("SELECT name, ext, path FROM video")
|
||||
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))
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,59 @@
|
||||
|
||||
{% block content %}
|
||||
{{ super() }}
|
||||
<div class="container">
|
||||
<a href="http://pythonhosted.org/Flask-Bootstrap">Documentation</a>. </p>
|
||||
<div class="container" style="width: fit-content(105%)">
|
||||
{% 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>
|
||||
{%- endblock %}
|
||||
@@ -29,29 +29,32 @@
|
||||
{% endif %}
|
||||
|
||||
<br><br>
|
||||
<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">Title</th>
|
||||
<th scope="col" class="text-center">Download</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for video in videos %}
|
||||
|
||||
{% if videos %}
|
||||
<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>
|
||||
<td class="text-center">{{ video['name'] }}</td>
|
||||
<td class="text-center"><a href="/download/{{ video['path'] + video['name'] + video['ext'] }}" download>Link</a></td>
|
||||
<th scope="col" class="text-center">Title</th>
|
||||
<th scope="col" class="text-center">Download</th>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for video in videos %}
|
||||
<tr>
|
||||
<td class="text-center">{{ video['name'] }}</td>
|
||||
<td class="text-center"><a href="/download/{{ video['path'] + video['name'] + video['ext'] }}" download>Link</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
{%- endblock %}
|
||||
@@ -2,30 +2,28 @@
|
||||
|
||||
{% block content %}
|
||||
{{ super() }}
|
||||
<div class="container">
|
||||
<div class="container" style="width: fit-content(105%)">
|
||||
{% if downloads %}
|
||||
<div class="card" style="width: 100%">
|
||||
<div class="card">
|
||||
<ul class="list-group list-group-flush">
|
||||
<li class="list-group-item">
|
||||
<div class="row">
|
||||
<div class="col-md-5">
|
||||
<table id="videos" class="table">
|
||||
<thead>
|
||||
<table id="videos" class="table">
|
||||
<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>
|
||||
<th scope="col" class="text-center">Title</th>
|
||||
<th scope="col" class="text-center">Update</th>
|
||||
<td class="text-center">{{ d[0] }}</td>
|
||||
<td class="text-center"><a href="/update/{{ d[1] }}">Start</a></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for d in downloads %}
|
||||
<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>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
Reference in New Issue
Block a user