ina.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. strip_or_none,
  7. xpath_attr,
  8. xpath_text,
  9. )
  10. class InaIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?ina\.fr/video/(?P<id>[A-Z0-9_]+)'
  12. _TESTS = [{
  13. 'url': 'http://www.ina.fr/video/I12055569/francois-hollande-je-crois-que-c-est-clair-video.html',
  14. 'md5': 'a667021bf2b41f8dc6049479d9bb38a3',
  15. 'info_dict': {
  16. 'id': 'I12055569',
  17. 'ext': 'mp4',
  18. 'title': 'François Hollande "Je crois que c\'est clair"',
  19. 'description': 'md5:3f09eb072a06cb286b8f7e4f77109663',
  20. }
  21. }, {
  22. 'url': 'https://www.ina.fr/video/S806544_001/don-d-organes-des-avancees-mais-d-importants-besoins-video.html',
  23. 'only_matching': True,
  24. }]
  25. def _real_extract(self, url):
  26. video_id = self._match_id(url)
  27. info_doc = self._download_xml(
  28. 'http://player.ina.fr/notices/%s.mrss' % video_id, video_id)
  29. item = info_doc.find('channel/item')
  30. title = xpath_text(item, 'title', fatal=True)
  31. media_ns_xpath = lambda x: self._xpath_ns(x, 'http://search.yahoo.com/mrss/')
  32. content = item.find(media_ns_xpath('content'))
  33. get_furl = lambda x: xpath_attr(content, media_ns_xpath(x), 'url')
  34. formats = []
  35. for q, w, h in (('bq', 400, 300), ('mq', 512, 384), ('hq', 768, 576)):
  36. q_url = get_furl(q)
  37. if not q_url:
  38. continue
  39. formats.append({
  40. 'format_id': q,
  41. 'url': q_url,
  42. 'width': w,
  43. 'height': h,
  44. })
  45. if not formats:
  46. formats = [{
  47. 'url': get_furl('player') or content.attrib['url'],
  48. }]
  49. thumbnails = []
  50. for thumbnail in content.findall(media_ns_xpath('thumbnail')):
  51. thumbnail_url = thumbnail.get('url')
  52. if not thumbnail_url:
  53. continue
  54. thumbnails.append({
  55. 'url': thumbnail_url,
  56. 'height': int_or_none(thumbnail.get('height')),
  57. 'width': int_or_none(thumbnail.get('width')),
  58. })
  59. return {
  60. 'id': video_id,
  61. 'formats': formats,
  62. 'title': title,
  63. 'description': strip_or_none(xpath_text(item, 'description')),
  64. 'thumbnails': thumbnails,
  65. }