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.

182 lines
6.7 KiB

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