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.

204 lines
7.5 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. 'skip': 'Translation has finished',
  83. },
  84. {
  85. 'url': 'http://live.russia.tv/index/index/channel_id/3',
  86. 'info_dict': {
  87. 'id': '21',
  88. 'ext': 'mp4',
  89. 'title': 're:^Россия 24. Прямой эфир [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  90. 'is_live': True,
  91. },
  92. 'params': {
  93. # m3u8 download
  94. 'skip_download': True,
  95. },
  96. },
  97. ]
  98. @classmethod
  99. def _extract_url(cls, webpage):
  100. mobj = re.search(
  101. r'<iframe[^>]+?src=(["\'])(?P<url>https?://player\.rutv\.ru/(?:iframe/(?:swf|video|live)/id|index/iframe/cast_id)/.+?)\1', webpage)
  102. if mobj:
  103. return mobj.group('url')
  104. mobj = re.search(
  105. r'<meta[^>]+?property=(["\'])og:video\1[^>]+?content=(["\'])(?P<url>https?://player\.(?:rutv\.ru|vgtrk\.com)/flash2v/container\.swf\?id=.+?\2)',
  106. webpage)
  107. if mobj:
  108. return mobj.group('url')
  109. def _real_extract(self, url):
  110. mobj = re.match(self._VALID_URL, url)
  111. video_id = mobj.group('id')
  112. video_path = mobj.group('path')
  113. if video_path.startswith('flash2v'):
  114. video_type = 'video'
  115. elif video_path.startswith('iframe'):
  116. video_type = mobj.group('type')
  117. if video_type == 'swf':
  118. video_type = 'video'
  119. elif video_path.startswith('index/iframe/cast_id'):
  120. video_type = 'live'
  121. json_data = self._download_json(
  122. 'http://player.rutv.ru/iframe/%splay/id/%s' % ('live-' if video_type == 'live' else '', video_id),
  123. video_id, 'Downloading JSON')
  124. if json_data['errors']:
  125. raise ExtractorError('%s said: %s' % (self.IE_NAME, json_data['errors']), expected=True)
  126. playlist = json_data['data']['playlist']
  127. medialist = playlist['medialist']
  128. media = medialist[0]
  129. if media['errors']:
  130. raise ExtractorError('%s said: %s' % (self.IE_NAME, media['errors']), expected=True)
  131. view_count = playlist.get('count_views')
  132. priority_transport = playlist['priority_transport']
  133. thumbnail = media['picture']
  134. width = int_or_none(media['width'])
  135. height = int_or_none(media['height'])
  136. description = media['anons']
  137. title = media['title']
  138. duration = int_or_none(media.get('duration'))
  139. formats = []
  140. for transport, links in media['sources'].items():
  141. for quality, url in links.items():
  142. if transport == 'rtmp':
  143. mobj = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>.+))/(?P<playpath>.+)$', url)
  144. if not mobj:
  145. continue
  146. fmt = {
  147. 'url': mobj.group('url'),
  148. 'play_path': mobj.group('playpath'),
  149. 'app': mobj.group('app'),
  150. 'page_url': 'http://player.rutv.ru',
  151. 'player_url': 'http://player.rutv.ru/flash2v/osmf.swf?i=22',
  152. 'rtmp_live': True,
  153. 'ext': 'flv',
  154. 'vbr': int(quality),
  155. }
  156. elif transport == 'm3u8':
  157. formats.extend(self._extract_m3u8_formats(url, video_id, 'mp4'))
  158. continue
  159. else:
  160. fmt = {
  161. 'url': url
  162. }
  163. fmt.update({
  164. 'width': width,
  165. 'height': height,
  166. 'format_id': '%s-%s' % (transport, quality),
  167. 'preference': -1 if priority_transport == transport else -2,
  168. })
  169. formats.append(fmt)
  170. if not formats:
  171. raise ExtractorError('No media links available for %s' % video_id)
  172. self._sort_formats(formats)
  173. is_live = video_type == 'live'
  174. return {
  175. 'id': video_id,
  176. 'title': self._live_title(title) if is_live else title,
  177. 'description': description,
  178. 'thumbnail': thumbnail,
  179. 'view_count': view_count,
  180. 'duration': duration,
  181. 'formats': formats,
  182. 'is_live': is_live,
  183. }