[ie/BFMTV] Fix extractor (#16905)

Closes #16864
Authored by: 0xvd
This commit is contained in:
0xvd
2026-08-19 23:19:30 +00:00
committed by GitHub
parent 370f7820ea
commit 537ed68684
+18 -32
View File
@@ -7,30 +7,23 @@ from ..utils import ExtractorError, extract_attributes
class BFMTVBaseIE(InfoExtractor): class BFMTVBaseIE(InfoExtractor):
_VALID_URL_BASE = r'https?://(?:www\.|rmc\.)?bfmtv\.com/' _VALID_URL_BASE = r'https?://(?:www\.|rmc\.)?bfmtv\.com/'
_VALID_URL_TMPL = _VALID_URL_BASE + r'(?:[^/]+/)*[^/?&#]+_%s[A-Z]-(?P<id>\d{12})\.html' _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_BLOCK_REGEX = r'(<div[^>]+\bdata-video-id=[^>]+>.*?</div>)'
_VIDEO_ELEMENT_REGEX = r'(<video-js[^>]+>)'
BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/%s_default/index.html?videoId=%s' BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/%s_default/index.html?videoId=%s'
def _extract_video(self, video_block): def _extract_video(self, video_block, fatal=True):
video_element = self._search_regex( video_block_attrs = extract_attributes(video_block)
self._VIDEO_ELEMENT_REGEX, video_block, 'video element', default=None) video_id = video_block_attrs.get('data-video-id')
if video_element: if not video_id:
video_element_attrs = extract_attributes(video_element) msg = 'Unable to extract Brightcove video id'
video_id = video_element_attrs.get('data-video-id') if not fatal:
if not video_id: self.report_warning(msg)
return return {}
account_id = video_element_attrs.get('data-account') or '876450610001' raise ExtractorError(msg)
player_id = video_element_attrs.get('adjustplayer') or '19dszYXgm'
else: account_id = video_block_attrs.get('data-account-id') or '876450612001'
video_block_attrs = extract_attributes(video_block) player_id = video_block_attrs.get('playerid') or 'default'
video_id = video_block_attrs.get('videoid')
if not video_id: return self.url_result(self.BRIGHTCOVE_URL_TEMPLATE % (account_id, player_id, video_id), 'BrightcoveNew', 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)
class BFMTVIE(BFMTVBaseIE): class BFMTVIE(BFMTVBaseIE):
@@ -55,11 +48,8 @@ class BFMTVIE(BFMTVBaseIE):
def _real_extract(self, url): def _real_extract(self, url):
bfmtv_id = self._match_id(url) bfmtv_id = self._match_id(url)
webpage = self._download_webpage(url, bfmtv_id) 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')) self._VIDEO_BLOCK_REGEX, webpage, 'video block'))
if not video:
raise ExtractorError('Failed to extract video')
return video
class BFMTVLiveIE(BFMTVBaseIE): class BFMTVLiveIE(BFMTVBaseIE):
@@ -76,7 +66,6 @@ class BFMTVLiveIE(BFMTVBaseIE):
'timestamp': 1706887572, 'timestamp': 1706887572,
'live_status': 'is_live', 'live_status': 'is_live',
'thumbnail': r're:https://.+/image\.jpg', 'thumbnail': r're:https://.+/image\.jpg',
'tags': [],
}, },
'params': { 'params': {
'skip_download': True, 'skip_download': True,
@@ -89,11 +78,8 @@ class BFMTVLiveIE(BFMTVBaseIE):
def _real_extract(self, url): def _real_extract(self, url):
bfmtv_id = self._match_id(url) bfmtv_id = self._match_id(url)
webpage = self._download_webpage(url, bfmtv_id) 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')) self._VIDEO_BLOCK_REGEX, webpage, 'video block'))
if not video:
raise ExtractorError('Failed to extract video')
return video
class BFMTVArticleIE(BFMTVBaseIE): class BFMTVArticleIE(BFMTVBaseIE):
@@ -130,7 +116,7 @@ class BFMTVArticleIE(BFMTVBaseIE):
def _entries(self, webpage): def _entries(self, webpage):
for video_block_el in re.findall(self._VIDEO_BLOCK_REGEX, 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: if video:
yield video yield video