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.

46 lines
1.9 KiB

  1. import re
  2. import xml.etree.ElementTree
  3. from .common import InfoExtractor
  4. from ..utils import unified_strdate
  5. class CanalplusIE(InfoExtractor):
  6. _VALID_URL = r'https?://www\.canalplus\.fr/.*?\?vid=(?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-divertissement/pid3351-c-le-petit-journal.html?vid=889861',
  11. u'file': u'889861.flv',
  12. u'md5': u'590a888158b5f0d6832f84001fbf3e99',
  13. u'info_dict': {
  14. u'title': u'Le Petit Journal 20/06/13 - La guerre des drone',
  15. u'upload_date': u'20130620',
  16. },
  17. u'skip': u'Requires rtmpdump'
  18. }
  19. def _real_extract(self, url):
  20. mobj = re.match(self._VALID_URL, url)
  21. video_id = mobj.group('id')
  22. info_url = self._VIDEO_INFO_TEMPLATE % video_id
  23. info_page = self._download_webpage(info_url,video_id,
  24. u'Downloading video info')
  25. self.report_extraction(video_id)
  26. doc = xml.etree.ElementTree.fromstring(info_page.encode('utf-8'))
  27. video_info = [video for video in doc if video.find('ID').text == video_id][0]
  28. infos = video_info.find('INFOS')
  29. media = video_info.find('MEDIA')
  30. formats = [media.find('VIDEOS/%s' % format)
  31. for format in ['BAS_DEBIT', 'HAUT_DEBIT', 'HD']]
  32. video_url = [format.text for format in formats if format is not None][-1]
  33. return {'id': video_id,
  34. 'title': u'%s - %s' % (infos.find('TITRAGE/TITRE').text,
  35. infos.find('TITRAGE/SOUS_TITRE').text),
  36. 'url': video_url,
  37. 'ext': 'flv',
  38. 'upload_date': unified_strdate(infos.find('PUBLICATION/DATE').text),
  39. 'thumbnail': media.find('IMAGES/GRAND').text,
  40. }