add rand_sleep

This commit is contained in:
Simon 2026-03-14 17:33:03 +07:00
parent 0cbabd7cad
commit dd55171d86
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
1 changed files with 8 additions and 7 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
@ -23,6 +23,7 @@ class YtWrap:
BOT_MESSAGES = [
"not a bot",
]
BOT_ERROR_LOG = "YouTube bot detection, abort!"
OBS_BASE = {
"default_search": "ytsearch",
@ -99,9 +100,9 @@ class YtWrap:
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):
raise ConnectionError(
"YouTube bot detection, abort!"
) from err
print(self.BOT_ERROR_LOG)
rand_sleep(self.config)
raise ConnectionError(self.BOT_ERROR_LOG) from err
return False, str(err)
@ -131,9 +132,9 @@ class YtWrap:
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):
raise ConnectionError(
"YouTube bot detection, abort!"
) from err
print(self.BOT_ERROR_LOG)
rand_sleep(self.config)
raise ConnectionError(self.BOT_ERROR_LOG) from err
return None, str(err)