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.

71 lines
2.7 KiB

  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. )
  9. class CanalplusIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.canalplus\.fr/.*?/(?P<path>.*)|player\.canalplus\.fr/#/(?P<id>[0-9]+))'
  11. _VIDEO_INFO_TEMPLATE = 'http://service.canal-plus.com/video/rest/getVideosLiees/cplus/%s'
  12. IE_NAME = 'canalplus.fr'
  13. _TEST = {
  14. 'url': 'http://www.canalplus.fr/c-infos-documentaires/pid1830-c-zapping.html?vid=922470',
  15. 'md5': '3db39fb48b9685438ecf33a1078023e4',
  16. 'info_dict': {
  17. 'id': '922470',
  18. 'ext': 'flv',
  19. 'title': 'Zapping - 26/08/13',
  20. 'description': 'Le meilleur de toutes les chaînes, tous les jours.\nEmission du 26 août 2013',
  21. 'upload_date': '20130826',
  22. },
  23. }
  24. def _real_extract(self, url):
  25. mobj = re.match(self._VALID_URL, url)
  26. video_id = mobj.groupdict().get('id')
  27. # Beware, some subclasses do not define an id group
  28. display_id = url_basename(mobj.group('path'))
  29. if video_id is None:
  30. webpage = self._download_webpage(url, display_id)
  31. video_id = self._search_regex(r'<canal:player videoId="(\d+)"', webpage, 'video id')
  32. info_url = self._VIDEO_INFO_TEMPLATE % video_id
  33. doc = self._download_xml(info_url, video_id, 'Downloading video XML')
  34. video_info = [video for video in doc if video.find('ID').text == video_id][0]
  35. media = video_info.find('MEDIA')
  36. infos = video_info.find('INFOS')
  37. preferences = ['MOBILE', 'BAS_DEBIT', 'HAUT_DEBIT', 'HD', 'HLS', 'HDS']
  38. formats = [
  39. {
  40. 'url': fmt.text + '?hdcore=2.11.3' if fmt.tag == 'HDS' else fmt.text,
  41. 'format_id': fmt.tag,
  42. 'ext': 'mp4' if fmt.tag == 'HLS' else 'flv',
  43. 'preference': preferences.index(fmt.tag) if fmt.tag in preferences else -1,
  44. } for fmt in media.find('VIDEOS') if fmt.text
  45. ]
  46. self._sort_formats(formats)
  47. return {
  48. 'id': video_id,
  49. 'display_id': display_id,
  50. 'title': '%s - %s' % (infos.find('TITRAGE/TITRE').text,
  51. infos.find('TITRAGE/SOUS_TITRE').text),
  52. 'upload_date': unified_strdate(infos.find('PUBLICATION/DATE').text),
  53. 'thumbnail': media.find('IMAGES/GRAND').text,
  54. 'description': infos.find('DESCRIPTION').text,
  55. 'view_count': int(infos.find('NB_VUES').text),
  56. 'like_count': int(infos.find('NB_LIKES').text),
  57. 'comment_count': int(infos.find('NB_COMMENTS').text),
  58. 'formats': formats,
  59. }