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.

101 lines
3.7 KiB

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