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.

147 lines
5.1 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. unescapeHTML
  7. )
  8. class NTVIE(InfoExtractor):
  9. _VALID_URL = r'http://(?:www\.)?ntv\.ru/(?P<id>.+)'
  10. _TESTS = [
  11. {
  12. 'url': 'http://www.ntv.ru/novosti/863142/',
  13. 'info_dict': {
  14. 'id': '746000',
  15. 'ext': 'flv',
  16. 'title': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины',
  17. 'description': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины',
  18. 'duration': 136,
  19. },
  20. 'params': {
  21. # rtmp download
  22. 'skip_download': True,
  23. },
  24. },
  25. {
  26. 'url': 'http://www.ntv.ru/video/novosti/750370/',
  27. 'info_dict': {
  28. 'id': '750370',
  29. 'ext': 'flv',
  30. 'title': 'Родные пассажиров пропавшего Boeing не верят в трагический исход',
  31. 'description': 'Родные пассажиров пропавшего Boeing не верят в трагический исход',
  32. 'duration': 172,
  33. },
  34. 'params': {
  35. # rtmp download
  36. 'skip_download': True,
  37. },
  38. },
  39. {
  40. 'url': 'http://www.ntv.ru/peredacha/segodnya/m23700/o232416',
  41. 'info_dict': {
  42. 'id': '747480',
  43. 'ext': 'flv',
  44. 'title': '«Сегодня». 21 марта 2014 года. 16:00 ',
  45. 'description': '«Сегодня». 21 марта 2014 года. 16:00 ',
  46. 'duration': 1496,
  47. },
  48. 'params': {
  49. # rtmp download
  50. 'skip_download': True,
  51. },
  52. },
  53. {
  54. 'url': 'http://www.ntv.ru/kino/Koma_film',
  55. 'info_dict': {
  56. 'id': '758100',
  57. 'ext': 'flv',
  58. 'title': 'Остросюжетный фильм «Кома»',
  59. 'description': 'Остросюжетный фильм «Кома»',
  60. 'duration': 5592,
  61. },
  62. 'params': {
  63. # rtmp download
  64. 'skip_download': True,
  65. },
  66. },
  67. {
  68. 'url': 'http://www.ntv.ru/serial/Delo_vrachey/m31760/o233916/',
  69. 'info_dict': {
  70. 'id': '751482',
  71. 'ext': 'flv',
  72. 'title': '«Дело врачей»: «Деревце жизни»',
  73. 'description': '«Дело врачей»: «Деревце жизни»',
  74. 'duration': 2590,
  75. },
  76. 'params': {
  77. # rtmp download
  78. 'skip_download': True,
  79. },
  80. },
  81. ]
  82. _VIDEO_ID_REGEXES = [
  83. r'<meta property="og:url" content="http://www\.ntv\.ru/video/(\d+)',
  84. r'<video embed=[^>]+><id>(\d+)</id>',
  85. r'<video restriction[^>]+><key>(\d+)</key>',
  86. ]
  87. def _real_extract(self, url):
  88. mobj = re.match(self._VALID_URL, url)
  89. video_id = mobj.group('id')
  90. page = self._download_webpage(url, video_id)
  91. video_id = self._html_search_regex(self._VIDEO_ID_REGEXES, page, 'video id')
  92. player = self._download_xml('http://www.ntv.ru/vi%s/' % video_id, video_id, 'Downloading video XML')
  93. title = unescapeHTML(player.find('./data/title').text)
  94. description = unescapeHTML(player.find('./data/description').text)
  95. video = player.find('./data/video')
  96. video_id = video.find('./id').text
  97. thumbnail = video.find('./splash').text
  98. duration = int(video.find('./totaltime').text)
  99. view_count = int(video.find('./views').text)
  100. puid22 = video.find('./puid22').text
  101. apps = {
  102. '4': 'video1',
  103. '7': 'video2',
  104. }
  105. app = apps.get(puid22, apps['4'])
  106. formats = []
  107. for format_id in ['', 'hi', 'webm']:
  108. file = video.find('./%sfile' % format_id)
  109. if file is None:
  110. continue
  111. size = video.find('./%ssize' % format_id)
  112. formats.append({
  113. 'url': 'rtmp://media.ntv.ru/%s' % app,
  114. 'app': app,
  115. 'play_path': file.text,
  116. 'rtmp_conn': 'B:1',
  117. 'player_url': 'http://www.ntv.ru/swf/vps1.swf?update=20131128',
  118. 'page_url': 'http://www.ntv.ru',
  119. 'flash_ver': 'LNX 11,2,202,341',
  120. 'rtmp_live': True,
  121. 'ext': 'flv',
  122. 'filesize': int(size.text),
  123. })
  124. self._sort_formats(formats)
  125. return {
  126. 'id': video_id,
  127. 'title': title,
  128. 'description': description,
  129. 'thumbnail': thumbnail,
  130. 'duration': duration,
  131. 'view_count': view_count,
  132. 'formats': formats,
  133. }