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.

110 lines
4.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_parse_qs,
  7. compat_str,
  8. compat_urllib_parse_urlparse,
  9. )
  10. from ..utils import (
  11. determine_ext,
  12. int_or_none,
  13. try_get,
  14. qualities,
  15. )
  16. class SixPlayIE(InfoExtractor):
  17. IE_NAME = '6play'
  18. _VALID_URL = r'(?:6play:|https?://(?:www\.)?6play\.fr/.+?-c_)(?P<id>[0-9]+)'
  19. _TEST = {
  20. 'url': 'http://www.6play.fr/le-meilleur-patissier-p_1807/le-meilleur-patissier-special-fetes-mercredi-a-21-00-sur-m6-c_11638450',
  21. 'md5': '42310bffe4ba3982db112b9cd3467328',
  22. 'info_dict': {
  23. 'id': '11638450',
  24. 'ext': 'mp4',
  25. 'title': 'Le Meilleur Pâtissier, spécial fêtes mercredi à 21:00 sur M6',
  26. 'description': 'md5:308853f6a5f9e2d55a30fc0654de415f',
  27. 'duration': 39,
  28. 'series': 'Le meilleur pâtissier',
  29. },
  30. 'params': {
  31. 'skip_download': True,
  32. },
  33. }
  34. def _real_extract(self, url):
  35. video_id = self._match_id(url)
  36. data = self._download_json(
  37. 'https://pc.middleware.6play.fr/6play/v2/platforms/m6group_web/services/6play/videos/clip_%s' % video_id,
  38. video_id, query={
  39. 'csa': 5,
  40. 'with': 'clips',
  41. })
  42. clip_data = data['clips'][0]
  43. title = clip_data['title']
  44. urls = []
  45. quality_key = qualities(['lq', 'sd', 'hq', 'hd'])
  46. formats = []
  47. subtitles = {}
  48. for asset in clip_data['assets']:
  49. asset_url = asset.get('full_physical_path')
  50. protocol = asset.get('protocol')
  51. if not asset_url or protocol == 'primetime' or asset_url in urls:
  52. continue
  53. urls.append(asset_url)
  54. container = asset.get('video_container')
  55. ext = determine_ext(asset_url)
  56. if protocol == 'http_subtitle' or ext == 'vtt':
  57. subtitles.setdefault('fr', []).append({'url': asset_url})
  58. continue
  59. if container == 'm3u8' or ext == 'm3u8':
  60. if protocol == 'usp' and not compat_parse_qs(compat_urllib_parse_urlparse(asset_url).query).get('token', [None])[0]:
  61. asset_url = re.sub(r'/([^/]+)\.ism/[^/]*\.m3u8', r'/\1.ism/\1.m3u8', asset_url)
  62. formats.extend(self._extract_m3u8_formats(
  63. asset_url, video_id, 'mp4', 'm3u8_native',
  64. m3u8_id='hls', fatal=False))
  65. formats.extend(self._extract_f4m_formats(
  66. asset_url.replace('.m3u8', '.f4m'),
  67. video_id, f4m_id='hds', fatal=False))
  68. formats.extend(self._extract_mpd_formats(
  69. asset_url.replace('.m3u8', '.mpd'),
  70. video_id, mpd_id='dash', fatal=False))
  71. formats.extend(self._extract_ism_formats(
  72. re.sub(r'/[^/]+\.m3u8', '/Manifest', asset_url),
  73. video_id, ism_id='mss', fatal=False))
  74. else:
  75. formats.extend(self._extract_m3u8_formats(
  76. asset_url, video_id, 'mp4', 'm3u8_native',
  77. m3u8_id='hls', fatal=False))
  78. elif container == 'mp4' or ext == 'mp4':
  79. quality = asset.get('video_quality')
  80. formats.append({
  81. 'url': asset_url,
  82. 'format_id': quality,
  83. 'quality': quality_key(quality),
  84. 'ext': ext,
  85. })
  86. self._sort_formats(formats)
  87. def get(getter):
  88. for src in (data, clip_data):
  89. v = try_get(src, getter, compat_str)
  90. if v:
  91. return v
  92. return {
  93. 'id': video_id,
  94. 'title': title,
  95. 'description': get(lambda x: x['description']),
  96. 'duration': int_or_none(clip_data.get('duration')),
  97. 'series': get(lambda x: x['program']['title']),
  98. 'formats': formats,
  99. 'subtitles': subtitles,
  100. }