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.

115 lines
4.3 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. unified_strdate,
  7. url_basename,
  8. qualities,
  9. )
  10. class CanalplusIE(InfoExtractor):
  11. IE_DESC = 'canalplus.fr, piwiplus.fr and d8.tv'
  12. _VALID_URL = r'https?://(?:www\.(?P<site>canalplus\.fr|piwiplus\.fr|d8\.tv)/.*?/(?P<path>.*)|player\.canalplus\.fr/#/(?P<id>[0-9]+))'
  13. _VIDEO_INFO_TEMPLATE = 'http://service.canal-plus.com/video/rest/getVideosLiees/%s/%s'
  14. _SITE_ID_MAP = {
  15. 'canalplus.fr': 'cplus',
  16. 'piwiplus.fr': 'teletoon',
  17. 'd8.tv': 'd8',
  18. }
  19. _TESTS = [{
  20. 'url': 'http://www.canalplus.fr/c-infos-documentaires/pid1830-c-zapping.html?vid=922470',
  21. 'md5': '3db39fb48b9685438ecf33a1078023e4',
  22. 'info_dict': {
  23. 'id': '922470',
  24. 'ext': 'flv',
  25. 'title': 'Zapping - 26/08/13',
  26. 'description': 'Le meilleur de toutes les chaînes, tous les jours.\nEmission du 26 août 2013',
  27. 'upload_date': '20130826',
  28. },
  29. }, {
  30. 'url': 'http://www.piwiplus.fr/videos-piwi/pid1405-le-labyrinthe-boing-super-ranger.html?vid=1108190',
  31. 'info_dict': {
  32. 'id': '1108190',
  33. 'ext': 'flv',
  34. 'title': 'Le labyrinthe - Boing super ranger',
  35. 'description': 'md5:4cea7a37153be42c1ba2c1d3064376ff',
  36. 'upload_date': '20140724',
  37. },
  38. 'skip': 'Only works from France',
  39. }, {
  40. 'url': 'http://www.d8.tv/d8-docs-mags/pid6589-d8-campagne-intime.html',
  41. 'info_dict': {
  42. 'id': '966289',
  43. 'ext': 'flv',
  44. 'title': 'Campagne intime - Documentaire exceptionnel',
  45. 'description': 'md5:d2643b799fb190846ae09c61e59a859f',
  46. 'upload_date': '20131108',
  47. },
  48. 'skip': 'videos get deleted after a while',
  49. }]
  50. def _real_extract(self, url):
  51. mobj = re.match(self._VALID_URL, url)
  52. video_id = mobj.groupdict().get('id')
  53. site_id = self._SITE_ID_MAP[mobj.group('site') or 'canal']
  54. # Beware, some subclasses do not define an id group
  55. display_id = url_basename(mobj.group('path'))
  56. if video_id is None:
  57. webpage = self._download_webpage(url, display_id)
  58. video_id = self._search_regex(
  59. r'<canal:player[^>]+?videoId="(\d+)"', webpage, 'video id')
  60. info_url = self._VIDEO_INFO_TEMPLATE % (site_id, video_id)
  61. doc = self._download_xml(info_url, video_id, 'Downloading video XML')
  62. video_info = [video for video in doc if video.find('ID').text == video_id][0]
  63. media = video_info.find('MEDIA')
  64. infos = video_info.find('INFOS')
  65. preference = qualities(['MOBILE', 'BAS_DEBIT', 'HAUT_DEBIT', 'HD', 'HLS', 'HDS'])
  66. formats = []
  67. for fmt in media.find('VIDEOS'):
  68. format_url = fmt.text
  69. if not format_url:
  70. continue
  71. format_id = fmt.tag
  72. if format_id == 'HLS':
  73. hls_formats = self._extract_m3u8_formats(format_url, video_id, 'flv')
  74. for fmt in hls_formats:
  75. fmt['preference'] = preference(format_id)
  76. formats.extend(hls_formats)
  77. elif format_id == 'HDS':
  78. hds_formats = self._extract_f4m_formats(format_url + '?hdcore=2.11.3', video_id)
  79. for fmt in hds_formats:
  80. fmt['preference'] = preference(format_id)
  81. formats.extend(hds_formats)
  82. else:
  83. formats.append({
  84. 'url': format_url,
  85. 'format_id': format_id,
  86. 'preference': preference(format_id),
  87. })
  88. self._sort_formats(formats)
  89. return {
  90. 'id': video_id,
  91. 'display_id': display_id,
  92. 'title': '%s - %s' % (infos.find('TITRAGE/TITRE').text,
  93. infos.find('TITRAGE/SOUS_TITRE').text),
  94. 'upload_date': unified_strdate(infos.find('PUBLICATION/DATE').text),
  95. 'thumbnail': media.find('IMAGES/GRAND').text,
  96. 'description': infos.find('DESCRIPTION').text,
  97. 'view_count': int(infos.find('NB_VUES').text),
  98. 'like_count': int(infos.find('NB_LIKES').text),
  99. 'comment_count': int(infos.find('NB_COMMENTS').text),
  100. 'formats': formats,
  101. }