halt downloads on YouTube bot detection (#1127)

* add configurable stop_on_bot setting to halt downloads on YouTube bot detection

* rework: BOT_MESSAGES list, drop config toggle, always stop on bot detection

* add rand_sleep

---------

Co-authored-by: Simon <simobilleter@gmail.com>
This commit is contained in:
Jordan May 2026-03-14 06:36:07 -04:00 committed by GitHub
parent 6a5d892883
commit e3cf3e13b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 1 deletions

View File

@ -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)