bfmtv.py 4.1 KB

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