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.

135 lines
5.1 KiB

10 years ago
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. HEADRequest,
  8. unified_strdate,
  9. url_basename,
  10. qualities,
  11. )
  12. class CanalplusIE(InfoExtractor):
  13. IE_DESC = 'canalplus.fr, piwiplus.fr and d8.tv'
  14. _VALID_URL = r'https?://(?:www\.(?P<site>canalplus\.fr|piwiplus\.fr|d8\.tv|itele\.fr)/.*?/(?P<path>.*)|player\.canalplus\.fr/#/(?P<id>[0-9]+))'
  15. _VIDEO_INFO_TEMPLATE = 'http://service.canal-plus.com/video/rest/getVideosLiees/%s/%s'
  16. _SITE_ID_MAP = {
  17. 'canalplus.fr': 'cplus',
  18. 'piwiplus.fr': 'teletoon',
  19. 'd8.tv': 'd8',
  20. 'itele.fr': 'itele',
  21. }
  22. _TESTS = [{
  23. 'url': 'http://www.canalplus.fr/c-emissions/pid1830-c-zapping.html?vid=1263092',
  24. 'md5': 'b3481d7ca972f61e37420798d0a9d934',
  25. 'info_dict': {
  26. 'id': '1263092',
  27. 'ext': 'flv',
  28. 'title': 'Le Zapping - 13/05/15',
  29. 'description': 'md5:09738c0d06be4b5d06a0940edb0da73f',
  30. 'upload_date': '20150513',
  31. },
  32. }, {
  33. 'url': 'http://www.piwiplus.fr/videos-piwi/pid1405-le-labyrinthe-boing-super-ranger.html?vid=1108190',
  34. 'info_dict': {
  35. 'id': '1108190',
  36. 'ext': 'flv',
  37. 'title': 'Le labyrinthe - Boing super ranger',
  38. 'description': 'md5:4cea7a37153be42c1ba2c1d3064376ff',
  39. 'upload_date': '20140724',
  40. },
  41. 'skip': 'Only works from France',
  42. }, {
  43. 'url': 'http://www.d8.tv/d8-docs-mags/pid6589-d8-campagne-intime.html',
  44. 'info_dict': {
  45. 'id': '966289',
  46. 'ext': 'flv',
  47. 'title': 'Campagne intime - Documentaire exceptionnel',
  48. 'description': 'md5:d2643b799fb190846ae09c61e59a859f',
  49. 'upload_date': '20131108',
  50. },
  51. 'skip': 'videos get deleted after a while',
  52. }, {
  53. 'url': 'http://www.itele.fr/france/video/aubervilliers-un-lycee-en-colere-111559',
  54. 'md5': 'f3a46edcdf28006598ffaf5b30e6a2d4',
  55. 'info_dict': {
  56. 'id': '1213714',
  57. 'ext': 'flv',
  58. 'title': 'Aubervilliers : un lycée en colère - Le 11/02/2015 à 06h45',
  59. 'description': 'md5:8216206ec53426ea6321321f3b3c16db',
  60. 'upload_date': '20150211',
  61. },
  62. }]
  63. def _real_extract(self, url):
  64. mobj = re.match(self._VALID_URL, url)
  65. video_id = mobj.groupdict().get('id')
  66. site_id = self._SITE_ID_MAP[mobj.group('site') or 'canal']
  67. # Beware, some subclasses do not define an id group
  68. display_id = url_basename(mobj.group('path'))
  69. if video_id is None:
  70. webpage = self._download_webpage(url, display_id)
  71. video_id = self._search_regex(
  72. [r'<canal:player[^>]+?videoId=(["\'])(?P<id>\d+)', r'id=["\']canal_video_player(?P<id>\d+)'],
  73. webpage, 'video id', group='id')
  74. info_url = self._VIDEO_INFO_TEMPLATE % (site_id, video_id)
  75. doc = self._download_xml(info_url, video_id, 'Downloading video XML')
  76. video_info = [video for video in doc if video.find('ID').text == video_id][0]
  77. media = video_info.find('MEDIA')
  78. infos = video_info.find('INFOS')
  79. preference = qualities(['MOBILE', 'BAS_DEBIT', 'HAUT_DEBIT', 'HD', 'HLS', 'HDS'])
  80. fmt_url = next(iter(media.find('VIDEOS'))).text
  81. if '/geo' in fmt_url.lower():
  82. response = self._request_webpage(
  83. HEADRequest(fmt_url), video_id,
  84. 'Checking if the video is georestricted')
  85. if '/blocage' in response.geturl():
  86. raise ExtractorError(
  87. 'The video is not available in your country',
  88. expected=True)
  89. formats = []
  90. for fmt in media.find('VIDEOS'):
  91. format_url = fmt.text
  92. if not format_url:
  93. continue
  94. format_id = fmt.tag
  95. if format_id == 'HLS':
  96. formats.extend(self._extract_m3u8_formats(
  97. format_url, video_id, 'mp4', preference=preference(format_id)))
  98. elif format_id == 'HDS':
  99. formats.extend(self._extract_f4m_formats(
  100. format_url + '?hdcore=2.11.3', video_id, preference=preference(format_id)))
  101. else:
  102. formats.append({
  103. 'url': format_url,
  104. 'format_id': format_id,
  105. 'preference': preference(format_id),
  106. })
  107. self._sort_formats(formats)
  108. return {
  109. 'id': video_id,
  110. 'display_id': display_id,
  111. 'title': '%s - %s' % (infos.find('TITRAGE/TITRE').text,
  112. infos.find('TITRAGE/SOUS_TITRE').text),
  113. 'upload_date': unified_strdate(infos.find('PUBLICATION/DATE').text),
  114. 'thumbnail': media.find('IMAGES/GRAND').text,
  115. 'description': infos.find('DESCRIPTION').text,
  116. 'view_count': int(infos.find('NB_VUES').text),
  117. 'like_count': int(infos.find('NB_LIKES').text),
  118. 'comment_count': int(infos.find('NB_COMMENTS').text),
  119. 'formats': formats,
  120. }