ntvru.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. int_or_none,
  4. strip_or_none,
  5. unescapeHTML,
  6. xpath_text,
  7. )
  8. class NTVRuIE(InfoExtractor):
  9. IE_NAME = 'ntv.ru'
  10. _VALID_URL = r'https?://(?:www\.)?ntv\.ru/(?:[^/]+/)*(?P<id>[^/?#&]+)'
  11. _TESTS = [{
  12. 'url': 'http://www.ntv.ru/novosti/863142/',
  13. 'md5': 'ba7ea172a91cb83eb734cad18c10e723',
  14. 'info_dict': {
  15. 'id': '746000',
  16. 'ext': 'mp4',
  17. 'title': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины',
  18. 'description': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины',
  19. 'thumbnail': r're:^http://.*\.jpg',
  20. 'duration': 136,
  21. 'view_count': int,
  22. },
  23. }, {
  24. 'url': 'http://www.ntv.ru/video/novosti/750370/',
  25. 'md5': 'adecff79691b4d71e25220a191477124',
  26. 'info_dict': {
  27. 'id': '750370',
  28. 'ext': 'mp4',
  29. 'title': 'Родные пассажиров пропавшего Boeing не верят в трагический исход',
  30. 'description': 'Родные пассажиров пропавшего Boeing не верят в трагический исход',
  31. 'thumbnail': r're:^http://.*\.jpg',
  32. 'duration': 172,
  33. 'view_count': int,
  34. },
  35. 'skip': '404 Not Found',
  36. }, {
  37. 'url': 'http://www.ntv.ru/peredacha/segodnya/m23700/o232416',
  38. 'md5': '82dbd49b38e3af1d00df16acbeab260c',
  39. 'info_dict': {
  40. 'id': '747480',
  41. 'ext': 'mp4',
  42. 'title': '«Сегодня». 21 марта 2014 года. 16:00',
  43. 'description': '«Сегодня». 21 марта 2014 года. 16:00',
  44. 'thumbnail': r're:^http://.*\.jpg',
  45. 'duration': 1496,
  46. 'view_count': int,
  47. },
  48. }, {
  49. 'url': 'https://www.ntv.ru/kino/Koma_film/m70281/o336036/video/',
  50. 'md5': 'e9c7cde24d9d3eaed545911a04e6d4f4',
  51. 'info_dict': {
  52. 'id': '1126480',
  53. 'ext': 'mp4',
  54. 'title': 'Остросюжетный фильм «Кома»',
  55. 'description': 'Остросюжетный фильм «Кома»',
  56. 'thumbnail': r're:^http://.*\.jpg',
  57. 'duration': 5592,
  58. 'view_count': int,
  59. },
  60. }, {
  61. 'url': 'http://www.ntv.ru/serial/Delo_vrachey/m31760/o233916/',
  62. 'md5': '9320cd0e23f3ea59c330dc744e06ff3b',
  63. 'info_dict': {
  64. 'id': '751482',
  65. 'ext': 'mp4',
  66. 'title': '«Дело врачей»: «Деревце жизни»',
  67. 'description': '«Дело врачей»: «Деревце жизни»',
  68. 'thumbnail': r're:^http://.*\.jpg',
  69. 'duration': 2590,
  70. 'view_count': int,
  71. },
  72. }, {
  73. # Schemeless file URL
  74. 'url': 'https://www.ntv.ru/video/1797442',
  75. 'only_matching': True,
  76. }]
  77. _VIDEO_ID_REGEXES = [
  78. r'<meta property="og:url" content="https?://www\.ntv\.ru/video/(\d+)',
  79. r'<meta property="og:video:(?:url|iframe)" content="https?://www\.ntv\.ru/embed/(\d+)',
  80. r'<video embed=[^>]+><id>(\d+)</id>',
  81. r'<video restriction[^>]+><key>(\d+)</key>',
  82. ]
  83. def _real_extract(self, url):
  84. video_id = self._match_id(url)
  85. webpage = self._download_webpage(url, video_id)
  86. video_url = self._og_search_property(
  87. ('video', 'video:iframe'), webpage, default=None)
  88. if video_url:
  89. video_id = self._search_regex(
  90. r'https?://(?:www\.)?ntv\.ru/video/(?:embed/)?(\d+)',
  91. video_url, 'video id', default=None)
  92. if not video_id:
  93. video_id = self._html_search_regex(
  94. self._VIDEO_ID_REGEXES, webpage, 'video id')
  95. player = self._download_xml(
  96. f'http://www.ntv.ru/vi{video_id}/',
  97. video_id, 'Downloading video XML')
  98. title = strip_or_none(unescapeHTML(xpath_text(player, './data/title', 'title', fatal=True)))
  99. video = player.find('./data/video')
  100. formats = []
  101. for format_id in ['', 'hi', 'webm']:
  102. file_ = xpath_text(video, f'./{format_id}file')
  103. if not file_:
  104. continue
  105. if file_.startswith('//'):
  106. file_ = self._proto_relative_url(file_)
  107. elif not file_.startswith('http'):
  108. file_ = 'http://media.ntv.ru/vod/' + file_
  109. formats.append({
  110. 'url': file_,
  111. 'filesize': int_or_none(xpath_text(video, f'./{format_id}size')),
  112. })
  113. hls_manifest = xpath_text(video, './playback/hls')
  114. if hls_manifest:
  115. formats.extend(self._extract_m3u8_formats(
  116. hls_manifest, video_id, m3u8_id='hls', fatal=False))
  117. dash_manifest = xpath_text(video, './playback/dash')
  118. if dash_manifest:
  119. formats.extend(self._extract_mpd_formats(
  120. dash_manifest, video_id, mpd_id='dash', fatal=False))
  121. return {
  122. 'id': xpath_text(video, './id'),
  123. 'title': title,
  124. 'description': strip_or_none(unescapeHTML(xpath_text(player, './data/description'))),
  125. 'thumbnail': xpath_text(video, './splash'),
  126. 'duration': int_or_none(xpath_text(video, './totaltime')),
  127. 'view_count': int_or_none(xpath_text(video, './views')),
  128. 'formats': formats,
  129. }