diff --git a/tubearchivist/home/src/download/yt_dlp_base.py b/tubearchivist/home/src/download/yt_dlp_base.py index 2ce9c7a..54f61de 100644 --- a/tubearchivist/home/src/download/yt_dlp_base.py +++ b/tubearchivist/home/src/download/yt_dlp_base.py @@ -95,15 +95,35 @@ class CookieHandler: """revoke cookie""" RedisArchivist().del_message("cookie") RedisArchivist().set_message( - "config", False, path=".downloads.cookie_import" + "config", False, path=".downloads.cookie_import", expire=False ) print("cookie: revoked") def validate(self): """validate cookie using the liked videos playlist""" + print("validating cookie") obs_request = { "skip_download": True, "extract_flat": True, } - response = YtWrap(obs_request, self.config).extract("LL") + validator = YtWrap(obs_request, self.config) + response = validator.extract("LL") + + # update in redis to avoid expiring + modified = validator.obs["cookiefile"].getvalue() + if modified: + RedisArchivist().set_message("cookie", modified, expire=False) + + if not response: + mess_dict = { + "status": "message:download", + "level": "error", + "title": "Cookie validation failed, exiting...", + "message": "", + } + RedisArchivist().set_message( + "message:download", mess_dict, expire=4 + ) + print("cookie validation failed, exiting...") + return bool(response) diff --git a/tubearchivist/home/src/download/yt_dlp_handler.py b/tubearchivist/home/src/download/yt_dlp_handler.py index e82b6c5..482463c 100644 --- a/tubearchivist/home/src/download/yt_dlp_handler.py +++ b/tubearchivist/home/src/download/yt_dlp_handler.py @@ -12,7 +12,7 @@ from datetime import datetime from home.src.download.queue import PendingList from home.src.download.subscriptions import PlaylistSubscription -from home.src.download.yt_dlp_base import YtWrap +from home.src.download.yt_dlp_base import CookieHandler, YtWrap from home.src.es.connect import ElasticWrap, IndexPaginate from home.src.index.channel import YoutubeChannel from home.src.index.playlist import YoutubePlaylist @@ -155,10 +155,7 @@ class VideoDownloader: def run_queue(self): """setup download queue in redis loop until no more items""" - pending = PendingList() - pending.get_download() - pending.get_channels() - self.video_overwrites = pending.video_overwrites + self._setup_queue() queue = RedisQueue() @@ -185,7 +182,9 @@ class VideoDownloader: "title": "Moving....", "message": "Moving downloaded file to storage folder", } - RedisArchivist().set_message("message:download", mess_dict, False) + RedisArchivist().set_message( + "message:download", mess_dict, expire=False + ) self.move_to_archive(vid_dict) mess_dict = { @@ -201,6 +200,18 @@ class VideoDownloader: self._add_subscribed_channels() DownloadPostProcess(self).run() + def _setup_queue(self): + """setup required and validate""" + if self.config["downloads"]["cookie_import"]: + valid = CookieHandler(self.config).validate() + if not valid: + return + + pending = PendingList() + pending.get_download() + pending.get_channels() + self.video_overwrites = pending.video_overwrites + @staticmethod def add_pending(): """add pending videos to download queue""" diff --git a/tubearchivist/home/src/index/reindex.py b/tubearchivist/home/src/index/reindex.py index 5e85f95..e79ab30 100644 --- a/tubearchivist/home/src/index/reindex.py +++ b/tubearchivist/home/src/index/reindex.py @@ -12,6 +12,7 @@ from time import sleep from home.src.download.queue import PendingList from home.src.download.thumbnails import ThumbManager +from home.src.download.yt_dlp_base import CookieHandler from home.src.download.yt_dlp_handler import VideoDownloader from home.src.es.connect import ElasticWrap from home.src.index.channel import YoutubeChannel @@ -40,6 +41,13 @@ class Reindex: self.all_channel_ids = False self.all_playlist_ids = False + def check_cookie(self): + """validate cookie if enabled""" + if self.config["downloads"]["cookie_import"]: + valid = CookieHandler(self.config).validate() + if not valid: + return + def _get_daily(self): """get daily refresh values""" total_videos = self._get_total_hits("ta_video")