logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

bfmtv.py (4216B)


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