Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add list of finished files #1

Merged
merged 2 commits into from
May 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ydl_server/jobshandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ def worker(dl_queue):
dl_queue.put((Actions.DOWNLOAD, job))
queue.task_done()

def join():
if thread is not None:
return thread.join()
13 changes: 13 additions & 0 deletions ydl_server/static/js/youtubedl.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@ function get_download_logs(){
});
}

function get_finished_files(){
$.getJSON("api/finished", function (data) {
let finished_files = "";
$.each(data.files, function(key, file) {
finished_files += "<tr>";
finished_files += "<td><a href=\"api/finished/" + encodeURIComponent(file.name) + "\">" + file.name + "</a></td>";
finished_files += "<td>" + (new Date(file.modified)).toISOString() + "</td>";
finished_files += "</tr>";
});
$("#finished_files").html(finished_files);
});
}

function hide_logs_detail(){
$('td:nth-child(6),th:nth-child(6)').hide();
}
Expand Down
88 changes: 88 additions & 0 deletions ydl_server/templates/finished.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<!DOCTYPE html>
<html lang="en">

<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="Description" content="Web frontend for youtube-dl">

<!-- Bootstrap CSS -->
<link rel="stylesheet" href="static/css/bootstrap.min.css">
<link href="static/css/style.css" rel="stylesheet">

<title>youtube-dl - done</title>
</head>

<body>
<header>
<nav class="navbar navbar-expand-md navbar-dark">
<a class="navbar-brand abs" href="index">YoutubeDL</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#collapsingNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="navbar-collapse collapse" id="collapsingNavbar">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="logs">Logs</a>
</li>
<li class="nav-item">
<a class="nav-link" href="finished">Finished</a>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<span class="navbar-text">
Stats:
<span data-toggle="tooltip" data-placement="bottom" title="Pending" id='queue_pending_size' class="badge badge-secondary">-</span>
<span data-toggle="tooltip" data-placement="bottom" title="Running" id='running_size' class="badge badge-info">-</span>
<span data-toggle="tooltip" data-placement="bottom" title="Completed" id='completed_size' class="badge badge-success">-</span>
<span data-toggle="tooltip" data-placement="bottom" title="Failed" id='failed_size' class="badge badge-danger">-</span>
</span>
</li>
</ul>
</div>
</nav>
</header>

<div class="content">
<div class="container-fluid d-flex flex-column text-light text-center">
<div class="container-fluid flex-grow-1">
<h1 class="display-4">Finished Files</h1>
<button class="btn btn-dark" onclick="get_finished_files()">Refresh</button>
<br/>
<table class="col-md-16 table table-stripped table-md table-dark">
<thead>
<tr>
<th>Name</th>
<th>Date</th>
</tr>
<tbody id="finished_files">
</tbody>
</thead>
</table>
</div>
</div>
</div>
<footer class="footer text-light text-center">
<p class="text-muted">Web frontend for <a class="text-light" href="https://rg3.github.io/youtube-dl/">youtube-dl</a>,
code &amp; issues on <a class="text-light" href="https://github.com/nbr23/youtube-dl-server">GitHub</a>. Forked from <a class="text-light" href="https://github.com/manbearwiz/youtube-dl-server">@manbearwiz</a>.
</p>
</footer>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="static/js/jquery.min.js"></script>
<script src="static/js/popper.min.js"></script>
<script src="static/js/bootstrap.min.js"></script>
<script src="static/js/youtubedl.js"></script>
<script>
window.setInterval(update_stats, 5000);
update_stats();

window.setInterval(get_finished_files, 5000);
get_finished_files();
</script>
</body>

</html>
3 changes: 3 additions & 0 deletions ydl_server/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<li class="nav-item">
<a class="nav-link" href="logs">Logs</a>
</li>
<li class="nav-item">
<a class="nav-link" href="finished">Finished</a>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
Expand Down
3 changes: 3 additions & 0 deletions ydl_server/templates/logs.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
<li class="nav-item">
<a class="nav-link" href="logs">Logs</a>
</li>
<li class="nav-item">
<a class="nav-link" href="finished">Finished</a>
</li>
</ul>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
Expand Down
4 changes: 3 additions & 1 deletion ydl_server/ydlhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,6 @@ def resume_pending():
job.id = pending["id"]
jobshandler.put((Actions.RESUME, job))


def join():
if thread is not None:
return thread.join()
28 changes: 26 additions & 2 deletions youtube-dl-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import json
import os
from collections import ChainMap
from itertools import chain
from operator import itemgetter
from queue import Queue
from bottle import route, run, Bottle, request, static_file
from threading import Thread
Expand All @@ -22,6 +24,28 @@ def front_index():
def front_logs():
return static_file('templates/logs.html', root='./ydl_server')

@app.route('/finished')
def front_finished():
return static_file('templates/finished.html', root='./ydl_server')

@app.route('/api/finished')
def api_list_finished():
root_dir = Path(app_vars['YDL_OUTPUT_TEMPLATE']).parent
matches = chain(root_dir.glob('*'), root_dir.glob('*/*'))
files = [{
'name': f.relative_to(root_dir).as_posix(),
'modified': f.stat().st_mtime * 1000,
} for f in matches if not f.name.startswith('.') and f.is_file()]
files = sorted(files, key=itemgetter('modified'), reverse=True)
return {
"success": True,
"files": files
}

@app.route('/api/finished/:filename#.*#')
def api_serve_finished_file(filename):
root_dir = Path(app_vars['YDL_OUTPUT_TEMPLATE']).parent
return static_file(filename, root=root_dir)

@app.route('/static/:filename#.*#')
def server_static(filename):
Expand Down Expand Up @@ -92,5 +116,5 @@ def ydl_update():
debug=app_vars['YDL_DEBUG'])
ydlhandler.finish()
jobshandler.finish()
ydlhandler.thread.join()
jobshandler.thread.join()
ydlhandler.join()
jobshandler.join()