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.

169 lines
5.8 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 VestiIE(InfoExtractor):
  10. IE_NAME = 'vesti'
  11. IE_DESC = 'Вести.Ru'
  12. _VALID_URL = r'http://(?:.+?\.)?vesti\.ru/(?P<id>.+)'
  13. _TESTS = [
  14. {
  15. 'url': 'http://www.vesti.ru/videos?vid=575582&cid=1',
  16. 'info_dict': {
  17. 'id': '765035',
  18. 'ext': 'mp4',
  19. 'title': 'Вести.net: биткоины в России не являются законными',
  20. 'description': 'md5:d4bb3859dc1177b28a94c5014c35a36b',
  21. 'duration': 302,
  22. },
  23. 'params': {
  24. # m3u8 download
  25. 'skip_download': True,
  26. },
  27. },
  28. {
  29. 'url': 'http://www.vesti.ru/only_video.html?vid=576180',
  30. 'info_dict': {
  31. 'id': '766048',
  32. 'ext': 'mp4',
  33. 'title': 'США заморозило, Британию затопило',
  34. 'description': 'md5:f0ed0695ec05aed27c56a70a58dc4cc1',
  35. 'duration': 87,
  36. },
  37. 'params': {
  38. # m3u8 download
  39. 'skip_download': True,
  40. },
  41. },
  42. {
  43. 'url': 'http://sochi2014.vesti.ru/video/index/video_id/766403',
  44. 'info_dict': {
  45. 'id': '766403',
  46. 'ext': 'mp4',
  47. 'title': 'XXII зимние Олимпийские игры. Российские хоккеисты стартовали на Олимпиаде с победы',
  48. 'description': 'md5:55805dfd35763a890ff50fa9e35e31b3',
  49. 'duration': 271,
  50. },
  51. 'params': {
  52. # m3u8 download
  53. 'skip_download': True,
  54. },
  55. 'skip': 'Blocked outside Russia'
  56. },
  57. {
  58. 'url': 'http://sochi2014.vesti.ru/live/play/live_id/301',
  59. 'info_dict': {
  60. 'id': '51499',
  61. 'ext': 'flv',
  62. 'title': 'Сочи-2014. Биатлон. Индивидуальная гонка. Мужчины ',
  63. 'description': 'md5:9e0ed5c9d2fa1efbfdfed90c9a6d179c',
  64. },
  65. 'params': {
  66. # rtmp download
  67. 'skip_download': True,
  68. },
  69. 'skip': 'Translation has finished'
  70. }
  71. ]
  72. def _real_extract(self, url):
  73. mobj = re.match(self._VALID_URL, url)
  74. video_id = mobj.group('id')
  75. page = self._download_webpage(url, video_id, 'Downloading page')
  76. mobj = re.search(r'<meta property="og:video" content=".+?\.swf\?v?id=(?P<id>\d+).*?" />', page)
  77. if mobj:
  78. video_type = 'video'
  79. video_id = mobj.group('id')
  80. else:
  81. mobj = re.search(
  82. r'<iframe.+?src="http://player\.rutv\.ru/iframe/(?P<type>[^/]+)/id/(?P<id>\d+)[^"]*".*?></iframe>', page)
  83. if not mobj:
  84. raise ExtractorError('No media found')
  85. video_type = mobj.group('type')
  86. video_id = mobj.group('id')
  87. json_data = self._download_json(
  88. 'http://player.rutv.ru/iframe/%splay/id/%s' % ('live-' if video_type == 'live' else '', video_id),
  89. video_id, 'Downloading JSON')
  90. if json_data['errors']:
  91. raise ExtractorError('vesti returned error: %s' % json_data['errors'], expected=True)
  92. playlist = json_data['data']['playlist']
  93. medialist = playlist['medialist']
  94. media = medialist[0]
  95. if media['errors']:
  96. raise ExtractorError('vesti returned error: %s' % media['errors'], expected=True)
  97. view_count = playlist.get('count_views')
  98. priority_transport = playlist['priority_transport']
  99. thumbnail = media['picture']
  100. width = int_or_none(media['width'])
  101. height = int_or_none(media['height'])
  102. description = media['anons']
  103. title = media['title']
  104. duration = int_or_none(media.get('duration'))
  105. formats = []
  106. for transport, links in media['sources'].items():
  107. for quality, url in links.items():
  108. if transport == 'rtmp':
  109. mobj = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>.+))/(?P<playpath>.+)$', url)
  110. if not mobj:
  111. continue
  112. fmt = {
  113. 'url': mobj.group('url'),
  114. 'play_path': mobj.group('playpath'),
  115. 'app': mobj.group('app'),
  116. 'page_url': 'http://player.rutv.ru',
  117. 'player_url': 'http://player.rutv.ru/flash2v/osmf.swf?i=22',
  118. 'rtmp_live': True,
  119. 'ext': 'flv',
  120. 'vbr': int(quality),
  121. }
  122. elif transport == 'm3u8':
  123. fmt = {
  124. 'url': url,
  125. 'ext': 'mp4',
  126. }
  127. else:
  128. fmt = {
  129. 'url': url
  130. }
  131. fmt.update({
  132. 'width': width,
  133. 'height': height,
  134. 'format_id': '%s-%s' % (transport, quality),
  135. 'preference': -1 if priority_transport == transport else -2,
  136. })
  137. formats.append(fmt)
  138. if not formats:
  139. raise ExtractorError('No media links available for %s' % video_id)
  140. self._sort_formats(formats)
  141. return {
  142. 'id': video_id,
  143. 'title': title,
  144. 'description': description,
  145. 'thumbnail': thumbnail,
  146. 'view_count': view_count,
  147. 'duration': duration,
  148. 'formats': formats,
  149. }