canalplus.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. 'info_dict': {
  13. 'id': '922470',
  14. 'ext': 'flv',
  15. 'title': 'Zapping - 26/08/13',
  16. 'description': 'Le meilleur de toutes les chaînes, tous les jours.\nEmission du 26 août 2013',
  17. 'upload_date': '20130826',
  18. },
  19. 'params': {
  20. 'skip_download': True,
  21. },
  22. }
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group('id')
  26. if video_id is None:
  27. webpage = self._download_webpage(url, mobj.group('path'))
  28. video_id = self._search_regex(r'<canal:player videoId="(\d+)"', webpage, 'video id')
  29. info_url = self._VIDEO_INFO_TEMPLATE % video_id
  30. doc = self._download_xml(info_url, video_id, 'Downloading video XML')
  31. video_info = [video for video in doc if video.find('ID').text == video_id][0]
  32. media = video_info.find('MEDIA')
  33. infos = video_info.find('INFOS')
  34. preferences = ['MOBILE', 'BAS_DEBIT', 'HAUT_DEBIT', 'HD', 'HLS', 'HDS']
  35. formats = [
  36. {
  37. 'url': fmt.text + '?hdcore=2.11.3' if fmt.tag == 'HDS' else fmt.text,
  38. 'format_id': fmt.tag,
  39. 'ext': 'mp4' if fmt.tag == 'HLS' else 'flv',
  40. 'preference': preferences.index(fmt.tag) if fmt.tag in preferences else -1,
  41. } for fmt in media.find('VIDEOS') if fmt.text
  42. ]
  43. self._sort_formats(formats)
  44. return {
  45. 'id': video_id,
  46. 'title': '%s - %s' % (infos.find('TITRAGE/TITRE').text,
  47. infos.find('TITRAGE/SOUS_TITRE').text),
  48. 'upload_date': unified_strdate(infos.find('PUBLICATION/DATE').text),
  49. 'thumbnail': media.find('IMAGES/GRAND').text,
  50. 'description': infos.find('DESCRIPTION').text,
  51. 'view_count': int(infos.find('NB_VUES').text),
  52. 'like_count': int(infos.find('NB_LIKES').text),
  53. 'comment_count': int(infos.find('NB_COMMENTS').text),
  54. 'formats': formats,
  55. }