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.

53 lines
2.2 KiB

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