From 38b3a0980cdf7580f5db94a21da8eb246beecac6 Mon Sep 17 00:00:00 2001 From: dirkf Date: Sat, 19 Oct 2024 17:01:24 +0100 Subject: [PATCH] [YandexMusic] Fix CAPTCHA check * correct logic in _download_webpage() hook (yt-dlp/yt-dlp#4432) * improve error message. --- youtube_dl/extractor/yandexmusic.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/youtube_dl/extractor/yandexmusic.py b/youtube_dl/extractor/yandexmusic.py index 8da5b430f..91b731673 100644 --- a/youtube_dl/extractor/yandexmusic.py +++ b/youtube_dl/extractor/yandexmusic.py @@ -30,17 +30,20 @@ class YandexMusicBaseIE(InfoExtractor): @staticmethod def _raise_captcha(): raise ExtractorError( - 'YandexMusic has considered youtube-dl requests automated and ' - 'asks you to solve a CAPTCHA. You can either wait for some ' - 'time until unblocked and optionally use --sleep-interval ' - 'in future or alternatively you can go to https://music.yandex.ru/ ' - 'solve CAPTCHA, then export cookies and pass cookie file to ' - 'youtube-dl with --cookies', + 'YandexMusic has considered youtube-dl requests automated ' + 'and asks you to solve a CAPTCHA. You can wait for some time ' + 'until unblocked and optionally use --sleep-interval in future; ' + 'otherwise solve the CAPTCHA at https://music.yandex.ru/, ' + 'then export cookies and pass the cookie file to youtube-dl ' + 'with --cookies.', expected=True) def _download_webpage_handle(self, *args, **kwargs): webpage = super(YandexMusicBaseIE, self)._download_webpage_handle(*args, **kwargs) - if 'Нам очень жаль, но запросы, поступившие с вашего IP-адреса, похожи на автоматические.' in webpage: + blocked_ip_msg = ( + 'Нам очень жаль, но запросы, поступившие с ' + 'вашего IP-адреса, похожи на автоматические.') + if blocked_ip_msg in (webpage or [''])[0]: self._raise_captcha() return webpage