logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

ina.py (2948B)


  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|m)\.)?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. 'url': 'http://m.ina.fr/video/I12055569',
  33. 'only_matching': True,
  34. }]
  35. def _real_extract(self, url):
  36. video_id = self._match_id(url)
  37. info_doc = self._download_xml(
  38. 'http://player.ina.fr/notices/%s.mrss' % video_id, video_id)
  39. item = info_doc.find('channel/item')
  40. title = xpath_text(item, 'title', fatal=True)
  41. media_ns_xpath = lambda x: self._xpath_ns(x, 'http://search.yahoo.com/mrss/')
  42. content = item.find(media_ns_xpath('content'))
  43. get_furl = lambda x: xpath_attr(content, media_ns_xpath(x), 'url')
  44. formats = []
  45. for q, w, h in (('bq', 400, 300), ('mq', 512, 384), ('hq', 768, 576)):
  46. q_url = get_furl(q)
  47. if not q_url:
  48. continue
  49. formats.append({
  50. 'format_id': q,
  51. 'url': q_url,
  52. 'width': w,
  53. 'height': h,
  54. })
  55. if not formats:
  56. furl = get_furl('player') or content.attrib['url']
  57. ext = determine_ext(furl)
  58. formats = [{
  59. 'url': furl,
  60. 'vcodec': 'none' if ext == 'mp3' else None,
  61. 'ext': ext,
  62. }]
  63. thumbnails = []
  64. for thumbnail in content.findall(media_ns_xpath('thumbnail')):
  65. thumbnail_url = thumbnail.get('url')
  66. if not thumbnail_url:
  67. continue
  68. thumbnails.append({
  69. 'url': thumbnail_url,
  70. 'height': int_or_none(thumbnail.get('height')),
  71. 'width': int_or_none(thumbnail.get('width')),
  72. })
  73. return {
  74. 'id': video_id,
  75. 'formats': formats,
  76. 'title': title,
  77. 'description': strip_or_none(xpath_text(item, 'description')),
  78. 'thumbnails': thumbnails,
  79. }