diff --git a/backend/download/src/yt_dlp_base.py b/backend/download/src/yt_dlp_base.py index 5cb2d81b..64baef61 100644 --- a/backend/download/src/yt_dlp_base.py +++ b/backend/download/src/yt_dlp_base.py @@ -12,7 +12,7 @@ from os import path import yt_dlp from appsettings.src.config import AppConfig from common.src.env_settings import EnvironmentSettings -from common.src.helper import deep_merge +from common.src.helper import deep_merge, rand_sleep from common.src.ta_redis import RedisArchivist from django.conf import settings @@ -20,6 +20,11 @@ from django.conf import settings class YtWrap: """wrap calls to yt""" + BOT_MESSAGES = [ + "not a bot", + ] + BOT_ERROR_LOG = "YouTube bot detection, abort!" + OBS_BASE = { "default_search": "ytsearch", "quiet": True, @@ -85,6 +90,10 @@ class YtWrap: print(f"{url}: failed to download with message {err}") if "Temporary failure in name resolution" in str(err): raise ConnectionError("lost the internet, abort!") from err + if any(m in str(err) for m in self.BOT_MESSAGES): + print(self.BOT_ERROR_LOG) + rand_sleep(self.config) + raise ConnectionError(self.BOT_ERROR_LOG) from err return False, str(err) @@ -113,6 +122,10 @@ class YtWrap: print(f"{url}: failed to get info from youtube: {err}") if "Temporary failure in name resolution" in str(err): raise ConnectionError("lost the internet, abort!") from err + if any(m in str(err) for m in self.BOT_MESSAGES): + print(self.BOT_ERROR_LOG) + rand_sleep(self.config) + raise ConnectionError(self.BOT_ERROR_LOG) from err return None, str(err)