bfmtv.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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\.|rmc\.)?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. 'duration': 44.757,
  29. 'tags': ['bfmactu', 'politique'],
  30. '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',
  31. },
  32. }]
  33. def _real_extract(self, url):
  34. bfmtv_id = self._match_id(url)
  35. webpage = self._download_webpage(url, bfmtv_id)
  36. video_block = extract_attributes(self._search_regex(
  37. self._VIDEO_BLOCK_REGEX, webpage, 'video block'))
  38. return self._brightcove_url_result(video_block['videoid'], video_block)
  39. class BFMTVLiveIE(BFMTVIE): # XXX: Do not subclass from concrete IE
  40. IE_NAME = 'bfmtv:live'
  41. _VALID_URL = BFMTVBaseIE._VALID_URL_BASE + '(?P<id>(?:[^/]+/)?en-direct)'
  42. _TESTS = [{
  43. 'url': 'https://www.bfmtv.com/en-direct/',
  44. 'info_dict': {
  45. 'id': '5615950982001',
  46. 'ext': 'mp4',
  47. 'title': r're:^le direct BFMTV WEB \d{4}-\d{2}-\d{2} \d{2}:\d{2}$',
  48. 'uploader_id': '876450610001',
  49. 'upload_date': '20220926',
  50. 'timestamp': 1664207191,
  51. 'live_status': 'is_live',
  52. 'thumbnail': r're:https://.+/image\.jpg',
  53. 'tags': [],
  54. },
  55. 'params': {
  56. 'skip_download': True,
  57. },
  58. }, {
  59. 'url': 'https://www.bfmtv.com/economie/en-direct/',
  60. 'only_matching': True,
  61. }]
  62. class BFMTVArticleIE(BFMTVBaseIE):
  63. IE_NAME = 'bfmtv:article'
  64. _VALID_URL = BFMTVBaseIE._VALID_URL_TMPL % 'A'
  65. _TESTS = [{
  66. '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',
  67. 'info_dict': {
  68. 'id': '202101060198',
  69. 'title': 'Covid-19: un responsable de l\'Institut Pasteur se demande "quand la France va se reconfiner"',
  70. 'description': 'md5:947974089c303d3ac6196670ae262843',
  71. },
  72. 'playlist_count': 2,
  73. }, {
  74. 'url': 'https://www.bfmtv.com/international/pour-bolsonaro-le-bresil-est-en-faillite-mais-il-ne-peut-rien-faire_AD-202101060232.html',
  75. 'only_matching': True,
  76. }, {
  77. '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',
  78. 'only_matching': True,
  79. }, {
  80. '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',
  81. 'info_dict': {
  82. 'id': '6318445464112',
  83. 'ext': 'mp4',
  84. 'title': 'Le plein de bioéthanol fait de plus en plus mal à la pompe',
  85. 'uploader_id': '876630703001',
  86. 'upload_date': '20230110',
  87. 'timestamp': 1673341692,
  88. 'duration': 109.269,
  89. 'tags': ['rmc', 'show', 'apolline de malherbe', 'info', 'talk', 'matinale', 'radio'],
  90. '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',
  91. },
  92. }]
  93. def _real_extract(self, url):
  94. bfmtv_id = self._match_id(url)
  95. webpage = self._download_webpage(url, bfmtv_id)
  96. entries = []
  97. for video_block_el in re.findall(self._VIDEO_BLOCK_REGEX, webpage):
  98. video_block = extract_attributes(video_block_el)
  99. video_id = video_block.get('videoid')
  100. if not video_id:
  101. continue
  102. entries.append(self._brightcove_url_result(video_id, video_block))
  103. return self.playlist_result(
  104. entries, bfmtv_id, self._og_search_title(webpage, fatal=False),
  105. self._html_search_meta(['og:description', 'description'], webpage))