Skip to content

Commit 383ff31

Browse files
authored
Download videos in a separate thread
1 parent 6b0c535 commit 383ff31

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

dl.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import tempfile
33
import shutil
4+
from threading import Thread
45

56
from youtube_dl import YoutubeDL
67
from flask import Flask, request
@@ -11,16 +12,8 @@
1112
VID_PATH = "/mnt/Data/Public/Videos/Other/Youtubes/vids/"
1213
TMP_PATH = "/mnt/Data/Public/Videos/Other/Youtubes/downloader/temp"
1314

14-
@app.route("/dlvid", methods=["GET"])
15-
def dlvid():
16-
url = request.args.get('url')
17-
18-
if 'results' in url and 'search_query' in url:
19-
# This is a search page
20-
return ""
21-
15+
def download(url):
2216
f = open(os.path.join(original_path, "log.txt"), "a")
23-
2417
try:
2518
info_dict = ydl.extract_info(url, download=False)
2619
filename = ydl.prepare_filename(info_dict)
@@ -39,9 +32,15 @@ def dlvid():
3932
f.write("Downloaded " + url + '\n')
4033
except Exception as e:
4134
f.write("FAILED " + url + ' . because ' + e.message + '\n')
42-
4335
f.close()
4436

37+
@app.route("/dlvid", methods=["GET"])
38+
def dlvid():
39+
url = request.args.get('url')
40+
if 'results' in url and 'search_query' in url:
41+
# This is a search page
42+
return ""
43+
Thread(target=download, args=(url,)).start()
4544
return ""
4645

4746
if __name__ == "__main__":

0 commit comments

Comments
 (0)