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:
parent
6a5d892883
commit
e3cf3e13b2
|
|
@ -12,7 +12,7 @@ from os import path
|
||||||
import yt_dlp
|
import yt_dlp
|
||||||
from appsettings.src.config import AppConfig
|
from appsettings.src.config import AppConfig
|
||||||
from common.src.env_settings import EnvironmentSettings
|
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 common.src.ta_redis import RedisArchivist
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
|
|
@ -20,6 +20,11 @@ from django.conf import settings
|
||||||
class YtWrap:
|
class YtWrap:
|
||||||
"""wrap calls to yt"""
|
"""wrap calls to yt"""
|
||||||
|
|
||||||
|
BOT_MESSAGES = [
|
||||||
|
"not a bot",
|
||||||
|
]
|
||||||
|
BOT_ERROR_LOG = "YouTube bot detection, abort!"
|
||||||
|
|
||||||
OBS_BASE = {
|
OBS_BASE = {
|
||||||
"default_search": "ytsearch",
|
"default_search": "ytsearch",
|
||||||
"quiet": True,
|
"quiet": True,
|
||||||
|
|
@ -85,6 +90,10 @@ class YtWrap:
|
||||||
print(f"{url}: failed to download with message {err}")
|
print(f"{url}: failed to download with message {err}")
|
||||||
if "Temporary failure in name resolution" in str(err):
|
if "Temporary failure in name resolution" in str(err):
|
||||||
raise ConnectionError("lost the internet, abort!") from 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)
|
return False, str(err)
|
||||||
|
|
||||||
|
|
@ -113,6 +122,10 @@ class YtWrap:
|
||||||
print(f"{url}: failed to get info from youtube: {err}")
|
print(f"{url}: failed to get info from youtube: {err}")
|
||||||
if "Temporary failure in name resolution" in str(err):
|
if "Temporary failure in name resolution" in str(err):
|
||||||
raise ConnectionError("lost the internet, abort!") from 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)
|
return None, str(err)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue