From 537ed68684587fc9aa191275154f0c350f5a452a Mon Sep 17 00:00:00 2001 From: 0xvd <199783523+0xvd@users.noreply.github.com> Date: Thu, 20 Aug 2026 04:49:30 +0530 Subject: [PATCH] [ie/BFMTV] Fix extractor (#16905) Closes #16864 Authored by: 0xvd --- yt_dlp/extractor/bfmtv.py | 50 ++++++++++++++------------------------- 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/yt_dlp/extractor/bfmtv.py b/yt_dlp/extractor/bfmtv.py index 49d4819a3d..50cdf3ccc2 100644 --- a/yt_dlp/extractor/bfmtv.py +++ b/yt_dlp/extractor/bfmtv.py @@ -7,30 +7,23 @@ from ..utils import ExtractorError, extract_attributes class BFMTVBaseIE(InfoExtractor): _VALID_URL_BASE = r'https?://(?:www\.|rmc\.)?bfmtv\.com/' _VALID_URL_TMPL = _VALID_URL_BASE + r'(?:[^/]+/)*[^/?&#]+_%s[A-Z]-(?P\d{12})\.html' - _VIDEO_BLOCK_REGEX = r'(]+class="video_block[^"]*"[^>]*>.*?)' - _VIDEO_ELEMENT_REGEX = r'(]+>)' + _VIDEO_BLOCK_REGEX = r'(]+\bdata-video-id=[^>]+>.*?)' 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 video class 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 video class 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