You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
2.9 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. clean_html,
  6. determine_ext,
  7. extract_attributes,
  8. get_element_by_class,
  9. int_or_none,
  10. parse_duration,
  11. parse_iso8601,
  12. )
  13. class TV5MondePlusIE(InfoExtractor):
  14. IE_DESC = 'TV5MONDE+'
  15. _VALID_URL = r'https?://(?:www\.)?tv5mondeplus\.com/toutes-les-videos/[^/]+/(?P<id>[^/?#]+)'
  16. _TEST = {
  17. 'url': 'http://www.tv5mondeplus.com/toutes-les-videos/documentaire/tdah-mon-amour-tele-quebec-tdah-mon-amour-ep001-enfants',
  18. 'md5': '12130fc199f020673138a83466542ec6',
  19. 'info_dict': {
  20. 'id': 'tdah-mon-amour-tele-quebec-tdah-mon-amour-ep001-enfants',
  21. 'ext': 'mp4',
  22. 'title': 'Tdah, mon amour - Enfants',
  23. 'description': 'md5:230e3aca23115afcf8006d1bece6df74',
  24. 'upload_date': '20170401',
  25. 'timestamp': 1491022860,
  26. }
  27. }
  28. _GEO_BYPASS = False
  29. def _real_extract(self, url):
  30. display_id = self._match_id(url)
  31. webpage = self._download_webpage(url, display_id)
  32. if ">Ce programme n'est malheureusement pas disponible pour votre zone géographique.<" in webpage:
  33. self.raise_geo_restricted(countries=['FR'])
  34. series = get_element_by_class('video-detail__title', webpage)
  35. title = episode = get_element_by_class(
  36. 'video-detail__subtitle', webpage) or series
  37. if series and series != title:
  38. title = '%s - %s' % (series, title)
  39. vpl_data = extract_attributes(self._search_regex(
  40. r'(<[^>]+class="video_player_loader"[^>]+>)',
  41. webpage, 'video player loader'))
  42. video_files = self._parse_json(
  43. vpl_data['data-broadcast'], display_id).get('files', [])
  44. formats = []
  45. for video_file in video_files:
  46. v_url = video_file.get('url')
  47. if not v_url:
  48. continue
  49. video_format = video_file.get('format') or determine_ext(v_url)
  50. if video_format == 'm3u8':
  51. formats.extend(self._extract_m3u8_formats(
  52. v_url, display_id, 'mp4', 'm3u8_native',
  53. m3u8_id='hls', fatal=False))
  54. else:
  55. formats.append({
  56. 'url': v_url,
  57. 'format_id': video_format,
  58. })
  59. self._sort_formats(formats)
  60. return {
  61. 'id': display_id,
  62. 'display_id': display_id,
  63. 'title': title,
  64. 'description': clean_html(get_element_by_class('video-detail__description', webpage)),
  65. 'thumbnail': vpl_data.get('data-image'),
  66. 'duration': int_or_none(vpl_data.get('data-duration')) or parse_duration(self._html_search_meta('duration', webpage)),
  67. 'timestamp': parse_iso8601(self._html_search_meta('uploadDate', webpage)),
  68. 'formats': formats,
  69. 'episode': episode,
  70. 'series': series,
  71. }