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