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.

203 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>flash\d+v/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://player.rutv.ru/iframe/live/id/21/showZoomBtn/false/isPlay/true/',
  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|vgtrk\.com)/(?: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)/flash\d+v/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 re.match(r'flash\d+v', video_path):
  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. is_live = video_type == 'live'
  122. json_data = self._download_json(
  123. 'http://player.rutv.ru/iframe/data%s/id/%s' % ('live' if is_live else 'video', video_id),
  124. video_id, 'Downloading JSON')
  125. if json_data['errors']:
  126. raise ExtractorError('%s said: %s' % (self.IE_NAME, json_data['errors']), expected=True)
  127. playlist = json_data['data']['playlist']
  128. medialist = playlist['medialist']
  129. media = medialist[0]
  130. if media['errors']:
  131. raise ExtractorError('%s said: %s' % (self.IE_NAME, media['errors']), expected=True)
  132. view_count = playlist.get('count_views')
  133. priority_transport = playlist['priority_transport']
  134. thumbnail = media['picture']
  135. width = int_or_none(media['width'])
  136. height = int_or_none(media['height'])
  137. description = media['anons']
  138. title = media['title']
  139. duration = int_or_none(media.get('duration'))
  140. formats = []
  141. for transport, links in media['sources'].items():
  142. for quality, url in links.items():
  143. preference = -1 if priority_transport == transport else -2
  144. if transport == 'rtmp':
  145. mobj = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>.+))/(?P<playpath>.+)$', url)
  146. if not mobj:
  147. continue
  148. fmt = {
  149. 'url': mobj.group('url'),
  150. 'play_path': mobj.group('playpath'),
  151. 'app': mobj.group('app'),
  152. 'page_url': 'http://player.rutv.ru',
  153. 'player_url': 'http://player.rutv.ru/flash3v/osmf.swf?i=22',
  154. 'rtmp_live': True,
  155. 'ext': 'flv',
  156. 'vbr': int(quality),
  157. 'preference': preference,
  158. }
  159. elif transport == 'm3u8':
  160. formats.extend(self._extract_m3u8_formats(
  161. url, video_id, 'mp4', preference=preference, m3u8_id='hls'))
  162. continue
  163. else:
  164. fmt = {
  165. 'url': url
  166. }
  167. fmt.update({
  168. 'width': width,
  169. 'height': height,
  170. 'format_id': '%s-%s' % (transport, quality),
  171. })
  172. formats.append(fmt)
  173. self._sort_formats(formats)
  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. }