aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordirkf <fieldhouse@gmx.net>2025-03-25 21:49:21 +0000
committerdirkf <fieldhouse@gmx.net>2025-03-25 22:35:05 +0000
commita464c159e61ab5c2c3babc8a4eb1d3e7923f1fe0 (patch)
tree0e6cd2a0030693f2b4874059b2365632bfb4f03f
parent7dca08eff01c0e8a25be38ec76c63170f26ac118 (diff)
[YouTube] Make `_extract_player_info()` use `_search_regex()`
-rw-r--r--test/test_youtube_signature.py3
-rw-r--r--youtube_dl/extractor/youtube.py16
2 files changed, 9 insertions, 10 deletions
diff --git a/test/test_youtube_signature.py b/test/test_youtube_signature.py
index 7726b1943..24d84dc20 100644
--- a/test/test_youtube_signature.py
+++ b/test/test_youtube_signature.py
@@ -280,8 +280,9 @@ class TestPlayerInfo(unittest.TestCase):
('https://s.ytimg.com/yts/jsbin/html5player-en_US-vflXGBaUN.js', 'vflXGBaUN'),
('https://s.ytimg.com/yts/jsbin/html5player-en_US-vflKjOTVq/html5player.js', 'vflKjOTVq'),
)
+ ie = YoutubeIE(FakeYDL({'cachedir': False}))
for player_url, expected_player_id in PLAYER_URLS:
- player_id = YoutubeIE._extract_player_info(player_url)
+ player_id = ie._extract_player_info(player_url)
self.assertEqual(player_id, expected_player_id)
diff --git a/youtube_dl/extractor/youtube.py b/youtube_dl/extractor/youtube.py
index 50527c98c..a0adee7b8 100644
--- a/youtube_dl/extractor/youtube.py
+++ b/youtube_dl/extractor/youtube.py
@@ -1626,15 +1626,13 @@ class YoutubeIE(YoutubeBaseInfoExtractor):
""" Return a string representation of a signature """
return '.'.join(compat_str(len(part)) for part in example_sig.split('.'))
- @classmethod
- def _extract_player_info(cls, player_url):
- for player_re in cls._PLAYER_INFO_RE:
- id_m = re.search(player_re, player_url)
- if id_m:
- break
- else:
- raise ExtractorError('Cannot identify player %r' % player_url)
- return id_m.group('id')
+ def _extract_player_info(self, player_url):
+ try:
+ return self._search_regex(
+ self._PLAYER_INFO_RE, player_url, 'player info', group='id')
+ except ExtractorError as e:
+ raise ExtractorError(
+ 'Cannot identify player %r' % (player_url,), cause=e)
def _load_player(self, video_id, player_url, fatal=True, player_id=None):
if not player_id: