From 4b00f454b713dfe9c99da168b0d425cbdbbd5608 Mon Sep 17 00:00:00 2001 From: simon Date: Tue, 24 May 2022 10:19:02 +0700 Subject: [PATCH] integrate new YtWrap class in yt_dlp handler --- .../home/src/download/yt_dlp_handler.py | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/tubearchivist/home/src/download/yt_dlp_handler.py b/tubearchivist/home/src/download/yt_dlp_handler.py index 2c24cb0..13a40d6 100644 --- a/tubearchivist/home/src/download/yt_dlp_handler.py +++ b/tubearchivist/home/src/download/yt_dlp_handler.py @@ -9,12 +9,11 @@ functionality: import os import shutil from datetime import datetime -from time import sleep -import yt_dlp from home.src.download.queue import PendingList from home.src.download.subscriptions import PlaylistSubscription from home.src.download.yt_cookie import CookieHandler +from home.src.download.yt_dlp_base import YtWrap from home.src.es.connect import ElasticWrap, IndexPaginate from home.src.index.channel import YoutubeChannel from home.src.index.playlist import YoutubePlaylist @@ -174,11 +173,10 @@ class VideoDownloader: if not youtube_id: break - try: - self._dl_single_vid(youtube_id) - except yt_dlp.utils.DownloadError: - print("failed to download " + youtube_id) + success = self._dl_single_vid(youtube_id) + if not success: continue + vid_dict = index_new_video( youtube_id, video_overwrites=self.video_overwrites ) @@ -348,13 +346,7 @@ class VideoDownloader: if youtube_id in file_name: obs["outtmpl"] = os.path.join(dl_cache, file_name) - with yt_dlp.YoutubeDL(obs) as ydl: - try: - ydl.download([youtube_id]) - except yt_dlp.utils.DownloadError: - print("retry failed download: " + youtube_id) - sleep(10) - ydl.download([youtube_id]) + success = YtWrap(obs).download(youtube_id) if self.obs["writethumbnail"]: # webp files don't get cleaned up automatically @@ -364,6 +356,8 @@ class VideoDownloader: file_path = os.path.join(dl_cache, file_name) os.remove(file_path) + return success + def move_to_archive(self, vid_dict): """move downloaded video from cache to archive""" videos = self.config["application"]["videos"]