tv5mondeplus.py 2.9 KB

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