forked from khk4912/Yuda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
81 lines (70 loc) · 2.18 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from flask import *
from flask_compress import Compress
import os
import youtube_dl
from multiprocessing.pool import ThreadPool
compress = Compress()
app = Flask(__name__)
app.secret_key = os.urandom(12)
def downloading(form):
if form.get("type") == "영상 (mp4)":
ty = "mp4"
options = {
"format": "bestvideo[ext=mp4]+bestaudio[ext=m4a]",
"noplaylist": True,
"outtmpl": "static/downloads/%(title)s.%(ext)s",
"continuedl": True,
}
else:
ty = "mp3"
options = {
"format": "bestaudio/best",
"postprocessors": [
{
"key": "FFmpegExtractAudio",
"preferredcodec": "mp3",
"preferredquality": "192",
}
],
"noplaylist": True,
"outtmpl": "static/downloads/%(title)s.%(ext)s",
"continuedl": True,
}
with youtube_dl.YoutubeDL(options) as ydl:
info = ydl.extract_info(form.get("link"), download=True)
return info, ty
@app.route("/")
def main():
return render_template("main.html")
@app.route("/download_finish", methods=["POST", "GET"])
def download_page():
if request.method == "POST":
try:
form = request.form
# ydl.download([form.get("link")] )
pool = ThreadPool(processes=1)
async_result = pool.apply_async(downloading, (form,))
info = async_result.get()
info, ty = info
pool.close()
pool.join()
title = info["title"]
title = title.replace("/", "_")
title = title.replace("?", "")
return render_template(
"download_finish.html",
title=title,
uploader=info["uploader"],
ext=ty,
thumbnail=info["thumbnail"],
)
except:
return redirect(url_for("main"))
else:
return redirect(url_for("main"))
@app.route("/subs")
def subs():
return render_template("subs.html")
if __name__ == "__main__":
app.debug = True
app.run(host="0.0.0.0", threaded=True, port=80)