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.

132 lines
5.0 KiB

11 years ago
11 years ago
10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. clean_html,
  6. xpath_text,
  7. int_or_none,
  8. )
  9. class NTVRuIE(InfoExtractor):
  10. IE_NAME = 'ntv.ru'
  11. _VALID_URL = r'https?://(?:www\.)?ntv\.ru/(?:[^/]+/)*(?P<id>[^/?#&]+)'
  12. _TESTS = [{
  13. 'url': 'http://www.ntv.ru/novosti/863142/',
  14. 'md5': 'ba7ea172a91cb83eb734cad18c10e723',
  15. 'info_dict': {
  16. 'id': '746000',
  17. 'ext': 'mp4',
  18. 'title': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины',
  19. 'description': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины',
  20. 'thumbnail': r're:^http://.*\.jpg',
  21. 'duration': 136,
  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. },
  34. }, {
  35. 'url': 'http://www.ntv.ru/peredacha/segodnya/m23700/o232416',
  36. 'md5': '82dbd49b38e3af1d00df16acbeab260c',
  37. 'info_dict': {
  38. 'id': '747480',
  39. 'ext': 'mp4',
  40. 'title': '«Сегодня». 21 марта 2014 года. 16:00',
  41. 'description': '«Сегодня». 21 марта 2014 года. 16:00',
  42. 'thumbnail': r're:^http://.*\.jpg',
  43. 'duration': 1496,
  44. },
  45. }, {
  46. 'url': 'http://www.ntv.ru/kino/Koma_film',
  47. 'md5': 'f825770930937aa7e5aca0dc0d29319a',
  48. 'info_dict': {
  49. 'id': '1007609',
  50. 'ext': 'mp4',
  51. 'title': 'Остросюжетный фильм «Кома»',
  52. 'description': 'Остросюжетный фильм «Кома»',
  53. 'thumbnail': r're:^http://.*\.jpg',
  54. 'duration': 5592,
  55. },
  56. }, {
  57. 'url': 'http://www.ntv.ru/serial/Delo_vrachey/m31760/o233916/',
  58. 'md5': '9320cd0e23f3ea59c330dc744e06ff3b',
  59. 'info_dict': {
  60. 'id': '751482',
  61. 'ext': 'mp4',
  62. 'title': '«Дело врачей»: «Деревце жизни»',
  63. 'description': '«Дело врачей»: «Деревце жизни»',
  64. 'thumbnail': r're:^http://.*\.jpg',
  65. 'duration': 2590,
  66. },
  67. }]
  68. _VIDEO_ID_REGEXES = [
  69. r'<meta property="og:url" content="http://www\.ntv\.ru/video/(\d+)',
  70. r'<video embed=[^>]+><id>(\d+)</id>',
  71. r'<video restriction[^>]+><key>(\d+)</key>',
  72. ]
  73. def _real_extract(self, url):
  74. video_id = self._match_id(url)
  75. webpage = self._download_webpage(url, video_id)
  76. video_url = self._og_search_property(
  77. ('video', 'video:iframe'), webpage, default=None)
  78. if video_url:
  79. video_id = self._search_regex(
  80. r'https?://(?:www\.)?ntv\.ru/video/(?:embed/)?(\d+)',
  81. video_url, 'video id', default=None)
  82. if not video_id:
  83. video_id = self._html_search_regex(
  84. self._VIDEO_ID_REGEXES, webpage, 'video id')
  85. player = self._download_xml(
  86. 'http://www.ntv.ru/vi%s/' % video_id,
  87. video_id, 'Downloading video XML')
  88. title = clean_html(xpath_text(player, './data/title', 'title', fatal=True))
  89. description = clean_html(xpath_text(player, './data/description', 'description'))
  90. video = player.find('./data/video')
  91. video_id = xpath_text(video, './id', 'video id')
  92. thumbnail = xpath_text(video, './splash', 'thumbnail')
  93. duration = int_or_none(xpath_text(video, './totaltime', 'duration'))
  94. view_count = int_or_none(xpath_text(video, './views', 'view count'))
  95. token = self._download_webpage(
  96. 'http://stat.ntv.ru/services/access/token',
  97. video_id, 'Downloading access token')
  98. formats = []
  99. for format_id in ['', 'hi', 'webm']:
  100. file_ = video.find('./%sfile' % format_id)
  101. if file_ is None:
  102. continue
  103. size = video.find('./%ssize' % format_id)
  104. formats.append({
  105. 'url': 'http://media2.ntv.ru/vod/%s&tok=%s' % (file_.text, token),
  106. 'filesize': int_or_none(size.text if size is not None else None),
  107. })
  108. self._sort_formats(formats)
  109. return {
  110. 'id': video_id,
  111. 'title': title,
  112. 'description': description,
  113. 'thumbnail': thumbnail,
  114. 'duration': duration,
  115. 'view_count': view_count,
  116. 'formats': formats,
  117. }