forked from khk4912/Yuda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_ssl.py
139 lines (124 loc) · 4.09 KB
/
app_ssl.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from flask import *
from flask_compress import Compress
import os
import youtube_dl
from multiprocessing.pool import ThreadPool
import ssl
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
return render_template("download_finish.html",title=info["title"], uploader=info["uploader"], ext=ty, thumbnail=info["thumbnail"])
except:
return redirect(url_for('main'))
else:
return redirect(url_for('main'))
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
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS)
ssl_context.load_cert_chain(certfile='certfile.crt', keyfile='private.key', password='password')
app.run(host="0.0.0.0", threaded=True, port=443, ssl_context=ssl_context)