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.

192 lines
7.1 KiB

10 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. int_or_none
  8. )
  9. class RUTVIE(InfoExtractor):
  10. IE_DESC = 'RUTV.RU'
  11. _VALID_URL = r'''(?x)
  12. https?://player\.(?:rutv\.ru|vgtrk\.com)/
  13. (?P<path>flash2v/container\.swf\?id=
  14. |iframe/(?P<type>swf|video|live)/id/
  15. |index/iframe/cast_id/)
  16. (?P<id>\d+)'''
  17. _TESTS = [
  18. {
  19. 'url': 'http://player.rutv.ru/flash2v/container.swf?id=774471&sid=kultura&fbv=true&isPlay=true&ssl=false&i=560&acc_video_id=episode_id/972347/video_id/978186/brand_id/31724',
  20. 'info_dict': {
  21. 'id': '774471',
  22. 'ext': 'mp4',
  23. 'title': 'Монологи на все времена',
  24. 'description': 'md5:18d8b5e6a41fb1faa53819471852d5d5',
  25. 'duration': 2906,
  26. },
  27. 'params': {
  28. # m3u8 download
  29. 'skip_download': True,
  30. },
  31. },
  32. {
  33. 'url': 'https://player.vgtrk.com/flash2v/container.swf?id=774016&sid=russiatv&fbv=true&isPlay=true&ssl=false&i=560&acc_video_id=episode_id/972098/video_id/977760/brand_id/57638',
  34. 'info_dict': {
  35. 'id': '774016',
  36. 'ext': 'mp4',
  37. 'title': 'Чужой в семье Сталина',
  38. 'description': '',
  39. 'duration': 2539,
  40. },
  41. 'params': {
  42. # m3u8 download
  43. 'skip_download': True,
  44. },
  45. },
  46. {
  47. 'url': 'http://player.rutv.ru/iframe/swf/id/766888/sid/hitech/?acc_video_id=4000',
  48. 'info_dict': {
  49. 'id': '766888',
  50. 'ext': 'mp4',
  51. 'title': 'Вести.net: интернет-гиганты начали перетягивание программных "одеял"',
  52. 'description': 'md5:65ddd47f9830c4f42ed6475f8730c995',
  53. 'duration': 279,
  54. },
  55. 'params': {
  56. # m3u8 download
  57. 'skip_download': True,
  58. },
  59. },
  60. {
  61. 'url': 'http://player.rutv.ru/iframe/video/id/771852/start_zoom/true/showZoomBtn/false/sid/russiatv/?acc_video_id=episode_id/970443/video_id/975648/brand_id/5169',
  62. 'info_dict': {
  63. 'id': '771852',
  64. 'ext': 'mp4',
  65. 'title': 'Прямой эфир. Жертвы загадочной болезни: смерть от старости в 17 лет',
  66. 'description': 'md5:b81c8c55247a4bd996b43ce17395b2d8',
  67. 'duration': 3096,
  68. },
  69. 'params': {
  70. # m3u8 download
  71. 'skip_download': True,
  72. },
  73. },
  74. {
  75. 'url': 'http://player.rutv.ru/iframe/live/id/51499/showZoomBtn/false/isPlay/true/sid/sochi2014',
  76. 'info_dict': {
  77. 'id': '51499',
  78. 'ext': 'flv',
  79. 'title': 'Сочи-2014. Биатлон. Индивидуальная гонка. Мужчины ',
  80. 'description': 'md5:9e0ed5c9d2fa1efbfdfed90c9a6d179c',
  81. },
  82. 'params': {
  83. # rtmp download
  84. 'skip_download': True,
  85. },
  86. 'skip': 'Translation has finished',
  87. },
  88. ]
  89. @classmethod
  90. def _extract_url(cls, webpage):
  91. mobj = re.search(
  92. r'<iframe[^>]+?src=(["\'])(?P<url>https?://player\.rutv\.ru/(?:iframe/(?:swf|video|live)/id|index/iframe/cast_id)/.+?)\1', webpage)
  93. if mobj:
  94. return mobj.group('url')
  95. mobj = re.search(
  96. r'<meta[^>]+?property=(["\'])og:video\1[^>]+?content=(["\'])(?P<url>https?://player\.(?:rutv\.ru|vgtrk\.com)/flash2v/container\.swf\?id=.+?\2)',
  97. webpage)
  98. if mobj:
  99. return mobj.group('url')
  100. def _real_extract(self, url):
  101. mobj = re.match(self._VALID_URL, url)
  102. video_id = mobj.group('id')
  103. video_path = mobj.group('path')
  104. if video_path.startswith('flash2v'):
  105. video_type = 'video'
  106. elif video_path.startswith('iframe'):
  107. video_type = mobj.group('type')
  108. if video_type == 'swf':
  109. video_type = 'video'
  110. elif video_path.startswith('index/iframe/cast_id'):
  111. video_type = 'live'
  112. json_data = self._download_json(
  113. 'http://player.rutv.ru/iframe/%splay/id/%s' % ('live-' if video_type == 'live' else '', video_id),
  114. video_id, 'Downloading JSON')
  115. if json_data['errors']:
  116. raise ExtractorError('%s said: %s' % (self.IE_NAME, json_data['errors']), expected=True)
  117. playlist = json_data['data']['playlist']
  118. medialist = playlist['medialist']
  119. media = medialist[0]
  120. if media['errors']:
  121. raise ExtractorError('%s said: %s' % (self.IE_NAME, media['errors']), expected=True)
  122. view_count = playlist.get('count_views')
  123. priority_transport = playlist['priority_transport']
  124. thumbnail = media['picture']
  125. width = int_or_none(media['width'])
  126. height = int_or_none(media['height'])
  127. description = media['anons']
  128. title = media['title']
  129. duration = int_or_none(media.get('duration'))
  130. formats = []
  131. for transport, links in media['sources'].items():
  132. for quality, url in links.items():
  133. if transport == 'rtmp':
  134. mobj = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>.+))/(?P<playpath>.+)$', url)
  135. if not mobj:
  136. continue
  137. fmt = {
  138. 'url': mobj.group('url'),
  139. 'play_path': mobj.group('playpath'),
  140. 'app': mobj.group('app'),
  141. 'page_url': 'http://player.rutv.ru',
  142. 'player_url': 'http://player.rutv.ru/flash2v/osmf.swf?i=22',
  143. 'rtmp_live': True,
  144. 'ext': 'flv',
  145. 'vbr': int(quality),
  146. }
  147. elif transport == 'm3u8':
  148. formats.extend(self._extract_m3u8_formats(url, video_id, 'mp4'))
  149. continue
  150. else:
  151. fmt = {
  152. 'url': url
  153. }
  154. fmt.update({
  155. 'width': width,
  156. 'height': height,
  157. 'format_id': '%s-%s' % (transport, quality),
  158. 'preference': -1 if priority_transport == transport else -2,
  159. })
  160. formats.append(fmt)
  161. if not formats:
  162. raise ExtractorError('No media links available for %s' % video_id)
  163. self._sort_formats(formats)
  164. return {
  165. 'id': video_id,
  166. 'title': title,
  167. 'description': description,
  168. 'thumbnail': thumbnail,
  169. 'view_count': view_count,
  170. 'duration': duration,
  171. 'formats': formats,
  172. }