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.

211 lines
7.9 KiB

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