logo

youtube-dl

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

tv5mondeplus.py (4498B)


  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. determine_ext,
  6. extract_attributes,
  7. int_or_none,
  8. parse_duration,
  9. )
  10. class TV5MondePlusIE(InfoExtractor):
  11. IE_DESC = 'TV5MONDE+'
  12. _VALID_URL = r'https?://(?:www\.)?(?:tv5mondeplus|revoir\.tv5monde)\.com/toutes-les-videos/[^/]+/(?P<id>[^/?#]+)'
  13. _TESTS = [{
  14. # movie
  15. 'url': 'https://revoir.tv5monde.com/toutes-les-videos/cinema/rendez-vous-a-atlit',
  16. 'md5': '8cbde5ea7b296cf635073e27895e227f',
  17. 'info_dict': {
  18. 'id': '822a4756-0712-7329-1859-a13ac7fd1407',
  19. 'display_id': 'rendez-vous-a-atlit',
  20. 'ext': 'mp4',
  21. 'title': 'Rendez-vous à Atlit',
  22. 'description': 'md5:2893a4c5e1dbac3eedff2d87956e4efb',
  23. 'upload_date': '20200130',
  24. },
  25. }, {
  26. # series episode
  27. 'url': 'https://revoir.tv5monde.com/toutes-les-videos/series-fictions/c-est-la-vie-ennemie-juree',
  28. 'info_dict': {
  29. 'id': '0df7007c-4900-3936-c601-87a13a93a068',
  30. 'display_id': 'c-est-la-vie-ennemie-juree',
  31. 'ext': 'mp4',
  32. 'title': "C'est la vie - Ennemie jurée",
  33. 'description': 'md5:dfb5c63087b6f35fe0cc0af4fe44287e',
  34. 'upload_date': '20200130',
  35. 'series': "C'est la vie",
  36. 'episode': 'Ennemie jurée',
  37. },
  38. 'params': {
  39. 'skip_download': True,
  40. },
  41. }, {
  42. 'url': 'https://revoir.tv5monde.com/toutes-les-videos/series-fictions/neuf-jours-en-hiver-neuf-jours-en-hiver',
  43. 'only_matching': True,
  44. }, {
  45. 'url': 'https://revoir.tv5monde.com/toutes-les-videos/info-societe/le-journal-de-la-rts-edition-du-30-01-20-19h30',
  46. 'only_matching': True,
  47. }]
  48. _GEO_BYPASS = False
  49. def _real_extract(self, url):
  50. display_id = self._match_id(url)
  51. webpage = self._download_webpage(url, display_id)
  52. if ">Ce programme n'est malheureusement pas disponible pour votre zone géographique.<" in webpage:
  53. self.raise_geo_restricted(countries=['FR'])
  54. title = episode = self._html_search_regex(r'<h1>([^<]+)', webpage, 'title')
  55. vpl_data = extract_attributes(self._search_regex(
  56. r'(<[^>]+class="video_player_loader"[^>]+>)',
  57. webpage, 'video player loader'))
  58. video_files = self._parse_json(
  59. vpl_data['data-broadcast'], display_id).get('files', [])
  60. formats = []
  61. for video_file in video_files:
  62. v_url = video_file.get('url')
  63. if not v_url:
  64. continue
  65. video_format = video_file.get('format') or determine_ext(v_url)
  66. if video_format == 'm3u8':
  67. formats.extend(self._extract_m3u8_formats(
  68. v_url, display_id, 'mp4', 'm3u8_native',
  69. m3u8_id='hls', fatal=False))
  70. else:
  71. formats.append({
  72. 'url': v_url,
  73. 'format_id': video_format,
  74. })
  75. self._sort_formats(formats)
  76. description = self._html_search_regex(
  77. r'(?s)<div[^>]+class=["\']episode-texte[^>]+>(.+?)</div>', webpage,
  78. 'description', fatal=False)
  79. series = self._html_search_regex(
  80. r'<p[^>]+class=["\']episode-emission[^>]+>([^<]+)', webpage,
  81. 'series', default=None)
  82. if series and series != title:
  83. title = '%s - %s' % (series, title)
  84. upload_date = self._search_regex(
  85. r'(?:date_publication|publish_date)["\']\s*:\s*["\'](\d{4}_\d{2}_\d{2})',
  86. webpage, 'upload date', default=None)
  87. if upload_date:
  88. upload_date = upload_date.replace('_', '')
  89. video_id = self._search_regex(
  90. (r'data-guid=["\']([\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})',
  91. r'id_contenu["\']\s:\s*(\d+)'), webpage, 'video id',
  92. default=display_id)
  93. return {
  94. 'id': video_id,
  95. 'display_id': display_id,
  96. 'title': title,
  97. 'description': description,
  98. 'thumbnail': vpl_data.get('data-image'),
  99. 'duration': int_or_none(vpl_data.get('data-duration')) or parse_duration(self._html_search_meta('duration', webpage)),
  100. 'upload_date': upload_date,
  101. 'formats': formats,
  102. 'series': series,
  103. 'episode': episode,
  104. }