summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@open-infrastructure.net>2020-03-24 15:24:46 +0000
committerDaniel Baumann <daniel.baumann@open-infrastructure.net>2020-03-24 16:02:45 +0000
commit9b176e972b8f31cd3d9d65da094517ef6f79e08f (patch)
tree0ac33683600e299a83c0cfb3bca4fc89491818a3
parentInitial commit. (diff)
downloadyoutube-dl-9b176e972b8f31cd3d9d65da094517ef6f79e08f.tar.xz
youtube-dl-9b176e972b8f31cd3d9d65da094517ef6f79e08f.zip
Updating.
Signed-off-by: Daniel Baumann <daniel.baumann@open-infrastructure.net>
-rwxr-xr-xdownload.py72
-rw-r--r--html/download.html58
-rw-r--r--index.html43
3 files changed, 173 insertions, 0 deletions
diff --git a/download.py b/download.py
new file mode 100755
index 0000000..f085411
--- /dev/null
+++ b/download.py
@@ -0,0 +1,72 @@
+#!/usr/bin/env python3
+
+from cgi import FieldStorage
+from datetime import datetime
+from sys import exit
+
+import html
+import os
+import subprocess
+import urllib.parse
+
+# Static settings
+Storage = '/mnt/smb.hdd.rbd/HKB/MUS-EP-2020'
+
+# Dynamic settings
+Address = html.escape(os.environ["REMOTE_ADDR"])
+User = html.escape(os.environ["REMOTE_USER"])
+
+def get_response(Command):
+ return subprocess.Popen(Command, stdout=subprocess.PIPE, shell=True).communicate()
+
+def get_return(Command):
+ return subprocess.Popen(Command, stdout=subprocess.PIPE, shell=True).wait()
+
+def print_html(html_file):
+ with open(html_file, 'r') as file:
+ html = file.read()
+
+ if form.getvalue('url'):
+ URL = form.getvalue('url')
+
+ print('Content-Type: text/html\n\n')
+ print(html.format(**locals()))
+
+if __name__ == '__main__':
+ form = FieldStorage()
+
+ if form.getvalue('url'):
+ File = form.getvalue('file')
+ URL = form.getvalue('url')
+ Directory = str(form.getvalue('directory'))
+
+ Date = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
+
+ if File:
+ Command = 'youtube-dl --get-filename --restrict-filenames -o \'' + File + '.%(ext)s\' ' + URL
+ else:
+ Command = 'youtube-dl --get-filename --restrict-filenames ' + URL
+
+ Video = get_response(Command)[0].strip().decode('utf-8')
+
+ Command = 'cd ' + Storage + '/' + Directory + ' && sudo youtube-dl --restrict-filenames -o ' + Video + ' ' + URL
+
+ Error = get_return(Command)
+
+ print('Content-Type: text/html\n\n')
+
+ if Error == 0:
+ print('\n\nDownloaded successful: <a href="/' + Directory + '/' + urllib.parse.quote(Video) + '">'+ Directory + '/' + Video + '</a><br><br /><a href="/download.py">download next file</a>...')
+ Status = 'successful'
+ else:
+ print('\n\nDownload unsuccessful, try <a href="/download.py">again</a>...')
+ Status = 'unsuccessful'
+
+ with open('download.txt', 'a') as file:
+ file.write(Date + ' ' + User + ' ' + Status + ' ' + Directory + '/' + Video + ' ' + URL + '\n')
+
+ exit()
+
+ # Show html form
+ print_html('html/download.html')
+ exit()
diff --git a/html/download.html b/html/download.html
new file mode 100644
index 0000000..88e8acf
--- /dev/null
+++ b/html/download.html
@@ -0,0 +1,58 @@
+<html>
+ <head>
+ <title>YouTube Download</title>
+ <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
+ </head>
+
+ <body>
+ <div class="container">
+ <div style="margin-top: 2rem"></div>
+
+ <h1>YouTube Download</h1>
+
+ <form action="download.py" method="post">
+ <div class="form-group">
+ <input type="text" name="file" class="form-control" placeholder="Dateiname (optional)" autofocus>
+
+ <div style="margin-top: 1rem"></div>
+
+ <input type="text" name="url" class="form-control" placeholder="URL">
+
+ <div style="margin-top: 1rem"></div>
+
+ <select name="directory" class="form-control">
+ <option value="BA_Jazz">BA Jazz</option>
+ <option value="BA_Klassik">BA Klassik</option>
+ <option value="BA_MuB">BA MuB</option>
+ <option value="BA_Sound_Arts">BA Sound Arts</option>
+ <option value="MA_Comp_Jazz">MA Comp Jazz</option>
+ <option value="MA_Comp_cr_P">MA Comp cr P</option>
+ <option value="MA_Ped_Jazz">MA Ped Jazz</option>
+ <option value="MA_Ped_Klassik">MA Ped Klassik</option>
+ <option value="MA_Ped_Rhythmik">MA Ped Rhythmik</option>
+ <option value="MA_Ped_SII">MA Ped SII</option>
+ <option value="MA_Perf_Jazz">MA Perf Jazz</option>
+ <option value="MA_Perf_Klassik">MA Perf Klassik</option>
+ <option value="MA_sp_Perf_Klassik">MA sp Perf Klassik</option>
+ <option value="MA_sp_Perf_Oper">MA sp Perf Oper</option>
+ <option value="test">test</option>
+ </select>
+
+ <button type="submit" class="btn btn-success">Download</button>
+ </div>
+ </form>
+ </div>
+
+ <br /><br /><br />
+
+ <h4>TODO:</h4>
+
+ <ul>
+ <li>show youtube-dl process output waehrend download</li>
+ <li>aktuell wird immer "bestes" format runtergeladen; falls das nicht mp4 ist, automatisch nach mp4 transcoden</li>
+ </ul>
+
+ <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
+ </body>
+</html>
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..f676ac2
--- /dev/null
+++ b/index.html
@@ -0,0 +1,43 @@
+<html>
+ <head>
+ <title>YouTube Download</title>
+ <link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet" />
+ </head>
+
+ <body>
+ <div class="container">
+ <div style="margin-top: 2rem"></div>
+
+ <h1>MUS-EP-2020</h1>
+
+ <h2>Download</h2>
+
+ <ul>
+ <li><a href="BA_Jazz">BA Jazz</a></li>
+ <li><a href="BA_Klassik">BA Klassik</a></li>
+ <li><a href="BA_MuB">BA MuB</a></li>
+ <li><a href="BA_Sound_Arts">BA Sound Arts</a></li>
+ <li><a href="MA_Comp_Jazz">MA Comp Jazz</a></li>
+ <li><a href="MA_Comp_cr_P">MA Comp cr P</a></li>
+ <li><a href="MA_Ped_Jazz">MA Ped Klassik</a></li>
+ <li><a href="MA_Ped_Rhythmik">MA Ped Rhythmik</a></li>
+ <li><a href="MA_Ped_SII">MA Ped SII</a></li>
+ <li><a href="MA_Perf_Jazz">MA Perf Jazz</a></li>
+ <li><a href="MA_Perf_Klassik">MA Perf Klassik</a></li>
+ <li><a href="MA_sp_Perf_Klassik">MA sp Perf Klassik</a></li>
+ <li><a href="MA_sp_Perf_Oper">MA sp Perf Oper</a></li>
+ <li><a href="test">test</a></li>
+ </ul>
+
+ <h2>Upload</h2>
+
+ <ul>
+ <li><a href="download.py">YouTube Download</a></li>
+ <li><a href="download.txt">Logfile</a></li>
+ </ul>
+ </div>
+
+ <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
+ <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
+ </body>
+</html>