From 088e87bccff2b6500190478e3776095ceccbcb98 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 30 Apr 2022 17:27:57 +0700 Subject: [PATCH] add cookiefile to PendingList and VideoDownloader --- tubearchivist/home/src/download/queue.py | 29 +++++++++++++------ .../home/src/download/yt_dlp_handler.py | 4 +++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/tubearchivist/home/src/download/queue.py b/tubearchivist/home/src/download/queue.py index d898b82..5ec4a19 100644 --- a/tubearchivist/home/src/download/queue.py +++ b/tubearchivist/home/src/download/queue.py @@ -13,8 +13,10 @@ from home.src.download.subscriptions import ( PlaylistSubscription, ) from home.src.download.thumbnails import ThumbManager +from home.src.download.yt_cookie import CookieHandler from home.src.es.connect import ElasticWrap, IndexPaginate from home.src.index.playlist import YoutubePlaylist +from home.src.ta.config import AppConfig from home.src.ta.helper import DurationConverter from home.src.ta.ta_redis import RedisArchivist @@ -119,12 +121,29 @@ class PendingInteract: class PendingList(PendingIndex): """manage the pending videos list""" + yt_obs = { + "default_search": "ytsearch", + "quiet": True, + "check_formats": "selected", + "noplaylist": True, + "writethumbnail": True, + "simulate": True, + } + def __init__(self, youtube_ids=False): super().__init__() + self.process_config() self.youtube_ids = youtube_ids self.to_skip = False self.missing_videos = False + def process_config(self): + """add user config to yt_obs""" + config = AppConfig().config + if config["downloads"]["cookie_import"]: + cookie_path = CookieHandler().use() + self.yt_obs.update({"cookiefile": cookie_path}) + def parse_url_list(self): """extract youtube ids from list""" self.missing_videos = [] @@ -223,16 +242,8 @@ class PendingList(PendingIndex): def get_youtube_details(self, youtube_id): """get details from youtubedl for single pending video""" - obs = { - "default_search": "ytsearch", - "quiet": True, - "check_formats": "selected", - "noplaylist": True, - "writethumbnail": True, - "simulate": True, - } try: - vid = yt_dlp.YoutubeDL(obs).extract_info(youtube_id) + vid = yt_dlp.YoutubeDL(self.yt_obs).extract_info(youtube_id) except yt_dlp.utils.DownloadError: print("failed to extract info for: " + youtube_id) return False diff --git a/tubearchivist/home/src/download/yt_dlp_handler.py b/tubearchivist/home/src/download/yt_dlp_handler.py index 31d8ce9..9712f95 100644 --- a/tubearchivist/home/src/download/yt_dlp_handler.py +++ b/tubearchivist/home/src/download/yt_dlp_handler.py @@ -14,6 +14,7 @@ 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.es.connect import ElasticWrap, IndexPaginate from home.src.index.channel import YoutubeChannel from home.src.index.playlist import YoutubePlaylist @@ -290,6 +291,9 @@ class VideoDownloader: self.obs["ratelimit"] = ( self.config["downloads"]["limit_speed"] * 1024 ) + if self.config["downloads"]["cookie_import"]: + cookie_path = CookieHandler().use() + self.obs["cookiefile"] = cookie_path throttle = self.config["downloads"]["throttledratelimit"] if throttle: