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.

64 lines
2.5 KiB

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