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.

138 lines
5.2 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="(\d+)"', webpage, 'video id')
  73. info_url = self._VIDEO_INFO_TEMPLATE % (site_id, video_id)
  74. doc = self._download_xml(info_url, video_id, 'Downloading video XML')
  75. video_info = [video for video in doc if video.find('ID').text == video_id][0]
  76. media = video_info.find('MEDIA')
  77. infos = video_info.find('INFOS')
  78. preference = qualities(['MOBILE', 'BAS_DEBIT', 'HAUT_DEBIT', 'HD', 'HLS', 'HDS'])
  79. fmt_url = next(iter(media.find('VIDEOS'))).text
  80. if '/geo' in fmt_url.lower():
  81. response = self._request_webpage(
  82. HEADRequest(fmt_url), video_id,
  83. 'Checking if the video is georestricted')
  84. if '/blocage' in response.geturl():
  85. raise ExtractorError(
  86. 'The video is not available in your country',
  87. expected=True)
  88. formats = []
  89. for fmt in media.find('VIDEOS'):
  90. format_url = fmt.text
  91. if not format_url:
  92. continue
  93. format_id = fmt.tag
  94. if format_id == 'HLS':
  95. hls_formats = self._extract_m3u8_formats(format_url, video_id, 'flv')
  96. for fmt in hls_formats:
  97. fmt['preference'] = preference(format_id)
  98. formats.extend(hls_formats)
  99. elif format_id == 'HDS':
  100. hds_formats = self._extract_f4m_formats(format_url + '?hdcore=2.11.3', video_id)
  101. for fmt in hds_formats:
  102. fmt['preference'] = preference(format_id)
  103. formats.extend(hds_formats)
  104. else:
  105. formats.append({
  106. 'url': format_url,
  107. 'format_id': format_id,
  108. 'preference': preference(format_id),
  109. })
  110. self._sort_formats(formats)
  111. return {
  112. 'id': video_id,
  113. 'display_id': display_id,
  114. 'title': '%s - %s' % (infos.find('TITRAGE/TITRE').text,
  115. infos.find('TITRAGE/SOUS_TITRE').text),
  116. 'upload_date': unified_strdate(infos.find('PUBLICATION/DATE').text),
  117. 'thumbnail': media.find('IMAGES/GRAND').text,
  118. 'description': infos.find('DESCRIPTION').text,
  119. 'view_count': int(infos.find('NB_VUES').text),
  120. 'like_count': int(infos.find('NB_LIKES').text),
  121. 'comment_count': int(infos.find('NB_COMMENTS').text),
  122. 'formats': formats,
  123. }