logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

rutv.py (8087B)


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