Release 2024.12.03
[yt-dlp3.git] / yt_dlp / extractor / bfmtv.py
blob49d4819a3df4d71bacf6f8cdcfd7adc1f21c5d05
1 import re
3 from .common import InfoExtractor
4 from ..utils import ExtractorError, extract_attributes
7 class BFMTVBaseIE(InfoExtractor):
8 _VALID_URL_BASE = r'https?://(?:www\.|rmc\.)?bfmtv\.com/'
9 _VALID_URL_TMPL = _VALID_URL_BASE + r'(?:[^/]+/)*[^/?&#]+_%s[A-Z]-(?P<id>\d{12})\.html'
10 _VIDEO_BLOCK_REGEX = r'(<div[^>]+class="video_block[^"]*"[^>]*>.*?</div>)'
11 _VIDEO_ELEMENT_REGEX = r'(<video-js[^>]+>)'
12 BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/%s_default/index.html?videoId=%s'
14 def _extract_video(self, video_block):
15 video_element = self._search_regex(
16 self._VIDEO_ELEMENT_REGEX, video_block, 'video element', default=None)
17 if video_element:
18 video_element_attrs = extract_attributes(video_element)
19 video_id = video_element_attrs.get('data-video-id')
20 if not video_id:
21 return
22 account_id = video_element_attrs.get('data-account') or '876450610001'
23 player_id = video_element_attrs.get('adjustplayer') or '19dszYXgm'
24 else:
25 video_block_attrs = extract_attributes(video_block)
26 video_id = video_block_attrs.get('videoid')
27 if not video_id:
28 return
29 account_id = video_block_attrs.get('accountid') or '876630703001'
30 player_id = video_block_attrs.get('playerid') or 'KbPwEbuHx'
31 return self.url_result(
32 self.BRIGHTCOVE_URL_TEMPLATE % (account_id, player_id, video_id),
33 'BrightcoveNew', video_id)
36 class BFMTVIE(BFMTVBaseIE):
37 IE_NAME = 'bfmtv'
38 _VALID_URL = BFMTVBaseIE._VALID_URL_TMPL % 'V'
39 _TESTS = [{
40 'url': 'https://www.bfmtv.com/politique/emmanuel-macron-l-islam-est-une-religion-qui-vit-une-crise-aujourd-hui-partout-dans-le-monde_VN-202010020146.html',
41 'info_dict': {
42 'id': '6196747868001',
43 'ext': 'mp4',
44 'title': 'Emmanuel Macron: "L\'Islam est une religion qui vit une crise aujourd’hui, partout dans le monde"',
45 'description': 'Le Président s\'exprime sur la question du séparatisme depuis les Mureaux, dans les Yvelines.',
46 'uploader_id': '876450610001',
47 'upload_date': '20201002',
48 'timestamp': 1601629620,
49 'duration': 44.757,
50 'tags': ['bfmactu', 'politique'],
51 'thumbnail': 'https://cf-images.eu-west-1.prod.boltdns.net/v1/static/876450610001/5041f4c1-bc48-4af8-a256-1b8300ad8ef0/cf2f9114-e8e2-4494-82b4-ab794ea4bc7d/1920x1080/match/image.jpg',
55 def _real_extract(self, url):
56 bfmtv_id = self._match_id(url)
57 webpage = self._download_webpage(url, bfmtv_id)
58 video = self._extract_video(self._search_regex(
59 self._VIDEO_BLOCK_REGEX, webpage, 'video block'))
60 if not video:
61 raise ExtractorError('Failed to extract video')
62 return video
65 class BFMTVLiveIE(BFMTVBaseIE):
66 IE_NAME = 'bfmtv:live'
67 _VALID_URL = BFMTVBaseIE._VALID_URL_BASE + '(?P<id>(?:[^/]+/)?en-direct)'
68 _TESTS = [{
69 'url': 'https://www.bfmtv.com/en-direct/',
70 'info_dict': {
71 'id': '6346069778112',
72 'ext': 'mp4',
73 'title': r're:^Le Live BFM TV \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
74 'uploader_id': '876450610001',
75 'upload_date': '20240202',
76 'timestamp': 1706887572,
77 'live_status': 'is_live',
78 'thumbnail': r're:https://.+/image\.jpg',
79 'tags': [],
81 'params': {
82 'skip_download': True,
84 }, {
85 'url': 'https://www.bfmtv.com/economie/en-direct/',
86 'only_matching': True,
89 def _real_extract(self, url):
90 bfmtv_id = self._match_id(url)
91 webpage = self._download_webpage(url, bfmtv_id)
92 video = self._extract_video(self._search_regex(
93 self._VIDEO_BLOCK_REGEX, webpage, 'video block'))
94 if not video:
95 raise ExtractorError('Failed to extract video')
96 return video
99 class BFMTVArticleIE(BFMTVBaseIE):
100 IE_NAME = 'bfmtv:article'
101 _VALID_URL = BFMTVBaseIE._VALID_URL_TMPL % 'A'
102 _TESTS = [{
103 'url': 'https://www.bfmtv.com/sante/covid-19-un-responsable-de-l-institut-pasteur-se-demande-quand-la-france-va-se-reconfiner_AV-202101060198.html',
104 'info_dict': {
105 'id': '202101060198',
106 'title': 'Covid-19: un responsable de l\'Institut Pasteur se demande "quand la France va se reconfiner"',
107 'description': 'md5:947974089c303d3ac6196670ae262843',
109 'playlist_count': 2,
110 }, {
111 'url': 'https://www.bfmtv.com/international/pour-bolsonaro-le-bresil-est-en-faillite-mais-il-ne-peut-rien-faire_AD-202101060232.html',
112 'only_matching': True,
113 }, {
114 'url': 'https://www.bfmtv.com/sante/covid-19-oui-le-vaccin-de-pfizer-distribue-en-france-a-bien-ete-teste-sur-des-personnes-agees_AN-202101060275.html',
115 'only_matching': True,
116 }, {
117 'url': 'https://rmc.bfmtv.com/actualites/societe/transports/ce-n-est-plus-tout-rentable-le-bioethanol-e85-depasse-1eu-le-litre-des-automobilistes-regrettent_AV-202301100268.html',
118 'info_dict': {
119 'id': '6318445464112',
120 'ext': 'mp4',
121 'title': 'Le plein de bioéthanol fait de plus en plus mal à la pompe',
122 'uploader_id': '876630703001',
123 'upload_date': '20230110',
124 'timestamp': 1673341692,
125 'duration': 109.269,
126 'tags': ['rmc', 'show', 'apolline de malherbe', 'info', 'talk', 'matinale', 'radio'],
127 'thumbnail': 'https://cf-images.eu-west-1.prod.boltdns.net/v1/static/876630703001/5bef74b8-9d5e-4480-a21f-60c2e2480c46/96c88b74-f9db-45e1-8040-e199c5da216c/1920x1080/match/image.jpg',
131 def _entries(self, webpage):
132 for video_block_el in re.findall(self._VIDEO_BLOCK_REGEX, webpage):
133 video = self._extract_video(video_block_el)
134 if video:
135 yield video
137 def _real_extract(self, url):
138 bfmtv_id = self._match_id(url)
139 webpage = self._download_webpage(url, bfmtv_id)
141 return self.playlist_result(
142 self._entries(webpage), bfmtv_id, self._og_search_title(webpage, fatal=False),
143 self._html_search_meta(['og:description', 'description'], webpage))