]>
Commit | Line | Data |
---|---|---|
1 | import re | |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import extract_attributes | |
5 | ||
6 | ||
7 | class BFMTVBaseIE(InfoExtractor): | |
8 | _VALID_URL_BASE = r'https?://(?:www\.)?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"[^>]*>)' | |
11 | BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/%s/%s_default/index.html?videoId=%s' | |
12 | ||
13 | def _brightcove_url_result(self, video_id, video_block): | |
14 | account_id = video_block.get('accountid') or '876450612001' | |
15 | player_id = video_block.get('playerid') or 'I2qBTln4u' | |
16 | return self.url_result( | |
17 | self.BRIGHTCOVE_URL_TEMPLATE % (account_id, player_id, video_id), | |
18 | 'BrightcoveNew', video_id) | |
19 | ||
20 | ||
21 | class BFMTVIE(BFMTVBaseIE): | |
22 | IE_NAME = 'bfmtv' | |
23 | _VALID_URL = BFMTVBaseIE._VALID_URL_TMPL % 'V' | |
24 | _TESTS = [{ | |
25 | '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', | |
26 | 'info_dict': { | |
27 | 'id': '6196747868001', | |
28 | 'ext': 'mp4', | |
29 | 'title': 'Emmanuel Macron: "L\'Islam est une religion qui vit une crise aujourd’hui, partout dans le monde"', | |
30 | 'description': 'Le Président s\'exprime sur la question du séparatisme depuis les Mureaux, dans les Yvelines.', | |
31 | 'uploader_id': '876450610001', | |
32 | 'upload_date': '20201002', | |
33 | 'timestamp': 1601629620, | |
34 | }, | |
35 | }] | |
36 | ||
37 | def _real_extract(self, url): | |
38 | bfmtv_id = self._match_id(url) | |
39 | webpage = self._download_webpage(url, bfmtv_id) | |
40 | video_block = extract_attributes(self._search_regex( | |
41 | self._VIDEO_BLOCK_REGEX, webpage, 'video block')) | |
42 | return self._brightcove_url_result(video_block['videoid'], video_block) | |
43 | ||
44 | ||
45 | class BFMTVLiveIE(BFMTVIE): | |
46 | IE_NAME = 'bfmtv:live' | |
47 | _VALID_URL = BFMTVBaseIE._VALID_URL_BASE + '(?P<id>(?:[^/]+/)?en-direct)' | |
48 | _TESTS = [{ | |
49 | 'url': 'https://www.bfmtv.com/en-direct/', | |
50 | 'info_dict': { | |
51 | 'id': '5615950982001', | |
52 | 'ext': 'mp4', | |
53 | 'title': r're:^le direct BFMTV WEB \d{4}-\d{2}-\d{2} \d{2}:\d{2}$', | |
54 | 'uploader_id': '876450610001', | |
55 | 'upload_date': '20171018', | |
56 | 'timestamp': 1508329950, | |
57 | }, | |
58 | 'params': { | |
59 | 'skip_download': True, | |
60 | }, | |
61 | }, { | |
62 | 'url': 'https://www.bfmtv.com/economie/en-direct/', | |
63 | 'only_matching': True, | |
64 | }] | |
65 | ||
66 | ||
67 | class BFMTVArticleIE(BFMTVBaseIE): | |
68 | IE_NAME = 'bfmtv:article' | |
69 | _VALID_URL = BFMTVBaseIE._VALID_URL_TMPL % 'A' | |
70 | _TESTS = [{ | |
71 | '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', | |
72 | 'info_dict': { | |
73 | 'id': '202101060198', | |
74 | 'title': 'Covid-19: un responsable de l\'Institut Pasteur se demande "quand la France va se reconfiner"', | |
75 | 'description': 'md5:947974089c303d3ac6196670ae262843', | |
76 | }, | |
77 | 'playlist_count': 2, | |
78 | }, { | |
79 | 'url': 'https://www.bfmtv.com/international/pour-bolsonaro-le-bresil-est-en-faillite-mais-il-ne-peut-rien-faire_AD-202101060232.html', | |
80 | 'only_matching': True, | |
81 | }, { | |
82 | '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', | |
83 | 'only_matching': True, | |
84 | }] | |
85 | ||
86 | def _real_extract(self, url): | |
87 | bfmtv_id = self._match_id(url) | |
88 | webpage = self._download_webpage(url, bfmtv_id) | |
89 | ||
90 | entries = [] | |
91 | for video_block_el in re.findall(self._VIDEO_BLOCK_REGEX, webpage): | |
92 | video_block = extract_attributes(video_block_el) | |
93 | video_id = video_block.get('videoid') | |
94 | if not video_id: | |
95 | continue | |
96 | entries.append(self._brightcove_url_result(video_id, video_block)) | |
97 | ||
98 | return self.playlist_result( | |
99 | entries, bfmtv_id, self._og_search_title(webpage, fatal=False), | |
100 | self._html_search_meta(['og:description', 'description'], webpage)) |