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.

54 lines
2.3 KiB

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