From 641698c350c031d47ff63a17a49a0f66b10d1715 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 9 Sep 2021 12:28:25 +0700 Subject: [PATCH] moove limit_count functionality into VideoDownload class to avoid having to reload the celery worker on config change --- tubearchivist/home/src/download.py | 4 ++++ tubearchivist/home/tasks.py | 9 ++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tubearchivist/home/src/download.py b/tubearchivist/home/src/download.py index 01caba4..2f185fd 100644 --- a/tubearchivist/home/src/download.py +++ b/tubearchivist/home/src/download.py @@ -375,6 +375,10 @@ class VideoDownloader: def download_list(self): """ download the list of youtube_ids """ + limit_count = self.config['downloads']['limit_count'] + if limit_count: + self.youtube_id_list = self.youtube_id_list[:limit_count] + for youtube_id in self.youtube_id_list: try: self.dl_single_vid(youtube_id) diff --git a/tubearchivist/home/tasks.py b/tubearchivist/home/tasks.py index 51cf8fb..3fd756f 100644 --- a/tubearchivist/home/tasks.py +++ b/tubearchivist/home/tasks.py @@ -17,7 +17,6 @@ from home.src.config import AppConfig CONFIG = AppConfig().config -LIMIT_COUNT = CONFIG['downloads']['limit_count'] REDIS_HOST = CONFIG['application']['REDIS_HOST'] os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'home.settings') @@ -41,12 +40,8 @@ def download_pending(): """ download latest pending videos """ pending_handler = PendingList() pending_vids = pending_handler.get_all_pending()[0] - pending = [i['youtube_id'] for i in pending_vids] - pending.reverse() - if LIMIT_COUNT: - to_download = pending[:LIMIT_COUNT] - else: - to_download = pending + to_download = [i['youtube_id'] for i in pending_vids] + to_download.reverse() if to_download: download_handler = VideoDownloader(to_download) download_handler.download_list()