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.

171 lines
6.8 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import compat_urllib_parse_urlparse
  6. from ..utils import (
  7. dict_get,
  8. ExtractorError,
  9. HEADRequest,
  10. int_or_none,
  11. qualities,
  12. remove_end,
  13. unified_strdate,
  14. )
  15. class CanalplusIE(InfoExtractor):
  16. IE_DESC = 'canalplus.fr, piwiplus.fr and d8.tv'
  17. _VALID_URL = r'''(?x)
  18. https?://
  19. (?:
  20. (?:
  21. (?:(?:www|m)\.)?canalplus\.fr|
  22. (?:www\.)?piwiplus\.fr|
  23. (?:www\.)?d8\.tv|
  24. (?:www\.)?c8\.fr|
  25. (?:www\.)?d17\.tv|
  26. (?:www\.)?itele\.fr
  27. )/(?:(?:[^/]+/)*(?P<display_id>[^/?#&]+))?(?:\?.*\bvid=(?P<vid>\d+))?|
  28. player\.canalplus\.fr/#/(?P<id>\d+)
  29. )
  30. '''
  31. _VIDEO_INFO_TEMPLATE = 'http://service.canal-plus.com/video/rest/getVideosLiees/%s/%s?format=json'
  32. _SITE_ID_MAP = {
  33. 'canalplus': 'cplus',
  34. 'piwiplus': 'teletoon',
  35. 'd8': 'd8',
  36. 'c8': 'd8',
  37. 'd17': 'd17',
  38. 'itele': 'itele',
  39. }
  40. _TESTS = [{
  41. 'url': 'http://www.canalplus.fr/c-emissions/pid1830-c-zapping.html?vid=1192814',
  42. 'info_dict': {
  43. 'id': '1405510',
  44. 'display_id': 'pid1830-c-zapping',
  45. 'ext': 'mp4',
  46. 'title': 'Zapping - 02/07/2016',
  47. 'description': 'Le meilleur de toutes les chaînes, tous les jours',
  48. 'upload_date': '20160702',
  49. },
  50. }, {
  51. 'url': 'http://www.piwiplus.fr/videos-piwi/pid1405-le-labyrinthe-boing-super-ranger.html?vid=1108190',
  52. 'info_dict': {
  53. 'id': '1108190',
  54. 'display_id': 'pid1405-le-labyrinthe-boing-super-ranger',
  55. 'ext': 'mp4',
  56. 'title': 'BOING SUPER RANGER - Ep : Le labyrinthe',
  57. 'description': 'md5:4cea7a37153be42c1ba2c1d3064376ff',
  58. 'upload_date': '20140724',
  59. },
  60. 'skip': 'Only works from France',
  61. }, {
  62. 'url': 'http://www.c8.fr/c8-divertissement/ms-touche-pas-a-mon-poste/pid6318-videos-integrales.html',
  63. 'md5': '4b47b12b4ee43002626b97fad8fb1de5',
  64. 'info_dict': {
  65. 'id': '1420213',
  66. 'display_id': 'pid6318-videos-integrales',
  67. 'ext': 'mp4',
  68. 'title': 'TPMP ! Même le matin - Les 35H de Baba - 14/10/2016',
  69. 'description': 'md5:f96736c1b0ffaa96fd5b9e60ad871799',
  70. 'upload_date': '20161014',
  71. },
  72. 'skip': 'Only works from France',
  73. }, {
  74. 'url': 'http://www.itele.fr/chroniques/invite-michael-darmon/rachida-dati-nicolas-sarkozy-est-le-plus-en-phase-avec-les-inquietudes-des-francais-171510',
  75. 'info_dict': {
  76. 'id': '1420176',
  77. 'display_id': 'rachida-dati-nicolas-sarkozy-est-le-plus-en-phase-avec-les-inquietudes-des-francais-171510',
  78. 'ext': 'mp4',
  79. 'title': 'L\'invité de Michaël Darmon du 14/10/2016 - ',
  80. 'description': 'Chaque matin du lundi au vendredi, Michaël Darmon reçoit un invité politique à 8h25.',
  81. 'upload_date': '20161014',
  82. },
  83. }, {
  84. 'url': 'http://m.canalplus.fr/?vid=1398231',
  85. 'only_matching': True,
  86. }, {
  87. 'url': 'http://www.d17.tv/emissions/pid8303-lolywood.html?vid=1397061',
  88. 'only_matching': True,
  89. }]
  90. def _real_extract(self, url):
  91. mobj = re.match(self._VALID_URL, url)
  92. site_id = self._SITE_ID_MAP[compat_urllib_parse_urlparse(url).netloc.rsplit('.', 2)[-2]]
  93. # Beware, some subclasses do not define an id group
  94. display_id = remove_end(dict_get(mobj.groupdict(), ('display_id', 'id', 'vid')), '.html')
  95. webpage = self._download_webpage(url, display_id)
  96. video_id = self._search_regex(
  97. [r'<canal:player[^>]+?videoId=(["\'])(?P<id>\d+)',
  98. r'id=["\']canal_video_player(?P<id>\d+)',
  99. r'data-video=["\'](?P<id>\d+)'],
  100. webpage, 'video id', default=mobj.group('vid'), group='id')
  101. info_url = self._VIDEO_INFO_TEMPLATE % (site_id, video_id)
  102. video_data = self._download_json(info_url, video_id, 'Downloading video JSON')
  103. if isinstance(video_data, list):
  104. video_data = [video for video in video_data if video.get('ID') == video_id][0]
  105. media = video_data['MEDIA']
  106. infos = video_data['INFOS']
  107. preference = qualities(['MOBILE', 'BAS_DEBIT', 'HAUT_DEBIT', 'HD'])
  108. fmt_url = next(iter(media.get('VIDEOS')))
  109. if '/geo' in fmt_url.lower():
  110. response = self._request_webpage(
  111. HEADRequest(fmt_url), video_id,
  112. 'Checking if the video is georestricted')
  113. if '/blocage' in response.geturl():
  114. raise ExtractorError(
  115. 'The video is not available in your country',
  116. expected=True)
  117. formats = []
  118. for format_id, format_url in media['VIDEOS'].items():
  119. if not format_url:
  120. continue
  121. if format_id == 'HLS':
  122. formats.extend(self._extract_m3u8_formats(
  123. format_url, video_id, 'mp4', 'm3u8_native', m3u8_id=format_id, fatal=False))
  124. elif format_id == 'HDS':
  125. formats.extend(self._extract_f4m_formats(
  126. format_url + '?hdcore=2.11.3', video_id, f4m_id=format_id, fatal=False))
  127. else:
  128. formats.append({
  129. # the secret extracted ya function in http://player.canalplus.fr/common/js/canalPlayer.js
  130. 'url': format_url + '?secret=pqzerjlsmdkjfoiuerhsdlfknaes',
  131. 'format_id': format_id,
  132. 'preference': preference(format_id),
  133. })
  134. self._sort_formats(formats)
  135. thumbnails = [{
  136. 'id': image_id,
  137. 'url': image_url,
  138. } for image_id, image_url in media.get('images', {}).items()]
  139. titrage = infos['TITRAGE']
  140. return {
  141. 'id': video_id,
  142. 'display_id': display_id,
  143. 'title': '%s - %s' % (titrage['TITRE'],
  144. titrage['SOUS_TITRE']),
  145. 'upload_date': unified_strdate(infos.get('PUBLICATION', {}).get('DATE')),
  146. 'thumbnails': thumbnails,
  147. 'description': infos.get('DESCRIPTION'),
  148. 'duration': int_or_none(infos.get('DURATION')),
  149. 'view_count': int_or_none(infos.get('NB_VUES')),
  150. 'like_count': int_or_none(infos.get('NB_LIKES')),
  151. 'comment_count': int_or_none(infos.get('NB_COMMENTS')),
  152. 'formats': formats,
  153. }