diff --git a/tubearchivist/home/apps.py b/tubearchivist/home/apps.py index 6ae55559..ef98c800 100644 --- a/tubearchivist/home/apps.py +++ b/tubearchivist/home/apps.py @@ -8,6 +8,7 @@ from home.src.es.connect import ElasticWrap from home.src.es.index_setup import index_check from home.src.es.snapshot import ElasticSnapshot from home.src.ta.config import AppConfig as ArchivistConfig +from home.src.ta.helper import clear_dl_cache from home.src.ta.ta_redis import RedisArchivist @@ -27,6 +28,7 @@ class StartupCheck: print("run startup checks") self.es_version_check() self.release_lock() + clear_dl_cache(self.config_handler.config) index_check() self.sync_redis_state() self.set_redis_conf() diff --git a/tubearchivist/home/src/ta/helper.py b/tubearchivist/home/src/ta/helper.py index 8e51e3ef..68d49b88 100644 --- a/tubearchivist/home/src/ta/helper.py +++ b/tubearchivist/home/src/ta/helper.py @@ -3,6 +3,7 @@ Loose collection of helper functions - don't import AppConfig class here to avoid circular imports """ +import os import random import re import string @@ -117,6 +118,15 @@ def time_parser(timestamp): return int(hours) * 60 * 60 + int(minutes) * 60 + float(seconds) +def clear_dl_cache(config): + """clear leftover files from dl cache""" + print("clear download cache") + cache_dir = os.path.join(config["application"]["cache_dir"], "download") + for cached in os.listdir(cache_dir): + to_delete = os.path.join(cache_dir, cached) + os.remove(to_delete) + + class UrlListParser: """take a multi line string and detect valid youtube ids""" diff --git a/tubearchivist/home/tasks.py b/tubearchivist/home/tasks.py index ae8e43e9..7bd4dea8 100644 --- a/tubearchivist/home/tasks.py +++ b/tubearchivist/home/tasks.py @@ -25,7 +25,7 @@ from home.src.index.filesystem import ( scan_filesystem, ) from home.src.ta.config import AppConfig, ScheduleBuilder -from home.src.ta.helper import UrlListParser +from home.src.ta.helper import UrlListParser, clear_dl_cache from home.src.ta.ta_redis import RedisArchivist, RedisQueue CONFIG = AppConfig().config @@ -192,11 +192,7 @@ def kill_dl(task_id): _ = RedisArchivist().del_message("dl_queue_id") RedisQueue().clear() - # clear cache - cache_dir = os.path.join(CONFIG["application"]["cache_dir"], "download") - for cached in os.listdir(cache_dir): - to_delete = os.path.join(cache_dir, cached) - os.remove(to_delete) + clear_dl_cache(CONFIG) # notify mess_dict = {