Skip to content

Commit 4901ba6

Browse files
When downloading video with yt-dlp, the module must wait until yt-dlp exits after the download is finished. Then the file is moved to the download folder, otherwise there is a possibility of an error.
Changes to be committed: modified: persepolis/scripts/ytdlp_downloader.py
1 parent 59d1ddf commit 4901ba6

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

persepolis/scripts/ytdlp_downloader.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def __init__(self, add_link_dictionary, main_window, gid, single_video_link=Fals
8787
self.download_percent = 0
8888
self.error_message = ''
8989
self.single_video_link = single_video_link
90+
self.yt_dlp_exited = False
9091

9192
# this flag notify that download finished(stopped, complete or error)
9293
# in this situation download status must be written to the database
@@ -409,6 +410,8 @@ def download(self):
409410
'error_message': self.error_message}
410411
self.main_window.persepolis_db.updateVideoFinderTable2(dict_)
411412

413+
self.yt_dlp_exited = True
414+
412415
def start(self):
413416
# Create download_path if not existed
414417
try:
@@ -518,7 +521,10 @@ def downloadCompleteAction(self, new_download_path):
518521
self.file_name = returnNewFileName(new_download_path, self.file_name)
519522
new_file_path = os.path.join(new_download_path, self.file_name)
520523

521-
# move the file to the download folder
524+
# move the file to the download folder but first make sure yt-dlp has finished.
525+
while not (self.yt_dlp_exited):
526+
time.sleep(0.1)
527+
522528
move_answer = moveFile(str(self.file_path), str(new_file_path), 'file')
523529

524530
if not (move_answer):

0 commit comments

Comments
 (0)