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.

156 lines
5.5 KiB

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