A feature-rich command-line audio/video downloader
[ie/BFMTV] Fix extractor (#16905)
0xvd537ed6868458
diff --git a/yt_dlp/extractor/bfmtv.py b/yt_dlp/extractor/bfmtv.pyindex 49d4819a3d..50cdf3ccc2 100644--- a/yt_dlp/extractor/bfmtv.py+++ b/yt_dlp/extractor/bfmtv.py@@ -7,30 +7,23 @@ from ..utils import ExtractorError, extract_attributesclass BFMTVBaseIE(InfoExtractor):_VALID_URL_BASE = r'https?://(?:www\.|rmc\.)?bfmtv\.com/'_VALID_URL_TMPL = _VALID_URL_BASE + r'(?:[^/]+/)*[^/?&#]+_%s[A-Z]-(?P<id>\d{12})\.html'- _VIDEO_BLOCK_REGEX = r'(<div[^>]+class="video_block[^"]*"[^>]*>.*?</div>)'- _VIDEO_ELEMENT_REGEX = r'(<video-js[^>]+>)'+ _VIDEO_BLOCK_REGEX = r'(<div[^>]+\bdata-video-id=[^>]+>.*?</div>)'BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/%s_default/index.html?videoId=%s'- def _extract_video(self, video_block):- video_element = self._search_regex(- self._VIDEO_ELEMENT_REGEX, video_block, 'video element', default=None)- if video_element:- video_element_attrs = extract_attributes(video_element)- video_id = video_element_attrs.get('data-video-id')- if not video_id:- return- account_id = video_element_attrs.get('data-account') or '876450610001'- player_id = video_element_attrs.get('adjustplayer') or '19dszYXgm'- else:- video_block_attrs = extract_attributes(video_block)- video_id = video_block_attrs.get('videoid')- if not video_id:- return- account_id = video_block_attrs.get('accountid') or '876630703001'- player_id = video_block_attrs.get('playerid') or 'KbPwEbuHx'- return self.url_result(- self.BRIGHTCOVE_URL_TEMPLATE % (account_id, player_id, video_id),- 'BrightcoveNew', video_id)+ def _extract_video(self, video_block, fatal=True):+ video_block_attrs = extract_attributes(video_block)+ video_id = video_block_attrs.get('data-video-id')+ if not video_id:+ msg = 'Unable to extract Brightcove video id'+ if not fatal:+ self.report_warning(msg)+ return {}+ raise ExtractorError(msg)++ account_id = video_block_attrs.get('data-account-id') or '876450612001'+ player_id = video_block_attrs.get('playerid') or 'default'++ return self.url_result(self.BRIGHTCOVE_URL_TEMPLATE % (account_id, player_id, video_id), 'BrightcoveNew', video_id)class BFMTVIE(BFMTVBaseIE):@@ -55,11 +48,8 @@ class BFMTVIE(BFMTVBaseIE):def _real_extract(self, url):bfmtv_id = self._match_id(url)webpage = self._download_webpage(url, bfmtv_id)- video = self._extract_video(self._search_regex(+ return self._extract_video(self._search_regex(self._VIDEO_BLOCK_REGEX, webpage, 'video block'))- if not video:- raise ExtractorError('Failed to extract video')- return videoclass BFMTVLiveIE(BFMTVBaseIE):@@ -76,7 +66,6 @@ class BFMTVLiveIE(BFMTVBaseIE):'timestamp': 1706887572,'live_status': 'is_live','thumbnail': r're:https://.+/image\.jpg',- 'tags': [],},'params': {'skip_download': True,@@ -89,11 +78,8 @@ class BFMTVLiveIE(BFMTVBaseIE):def _real_extract(self, url):bfmtv_id = self._match_id(url)webpage = self._download_webpage(url, bfmtv_id)- video = self._extract_video(self._search_regex(+ return self._extract_video(self._search_regex(self._VIDEO_BLOCK_REGEX, webpage, 'video block'))- if not video:- raise ExtractorError('Failed to extract video')- return videoclass BFMTVArticleIE(BFMTVBaseIE):@@ -130,7 +116,7 @@ class BFMTVArticleIE(BFMTVBaseIE):def _entries(self, webpage):for video_block_el in re.findall(self._VIDEO_BLOCK_REGEX, webpage):- video = self._extract_video(video_block_el)+ video = self._extract_video(video_block_el, fatal=False)if video:yield video