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.

83 lines
2.8 KiB

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