-# coding: utf-8
-from __future__ import unicode_literals
-
import re
from .common import InfoExtractor
-from ..utils import (
- ExtractorError,
- int_or_none
-)
+from ..utils import ExtractorError, int_or_none, str_to_int
class RUTVIE(InfoExtractor):
)
(?P<id>\d+)
'''
+ _EMBED_URLS = [
+ r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:test)?player\.(?:rutv\.ru|vgtrk\.com)/(?:iframe/(?:swf|video|live)/id|index/iframe/cast_id)/.+?)\1',
+ r'<meta[^>]+?property=(["\'])og:video\1[^>]+?content=(["\'])(?P<url>https?://(?:test)?player\.(?:rutv\.ru|vgtrk\.com)/flash\d+v/container\.swf\?id=.+?\2)',
+ ]
_TESTS = [
{
},
]
- @classmethod
- def _extract_url(cls, webpage):
- mobj = re.search(
- r'<iframe[^>]+?src=(["\'])(?P<url>https?://(?:test)?player\.(?:rutv\.ru|vgtrk\.com)/(?:iframe/(?:swf|video|live)/id|index/iframe/cast_id)/.+?)\1', webpage)
- if mobj:
- return mobj.group('url')
-
- mobj = re.search(
- r'<meta[^>]+?property=(["\'])og:video\1[^>]+?content=(["\'])(?P<url>https?://(?:test)?player\.(?:rutv\.ru|vgtrk\.com)/flash\d+v/container\.swf\?id=.+?\2)',
- webpage)
- if mobj:
- return mobj.group('url')
-
def _real_extract(self, url):
- mobj = re.match(self._VALID_URL, url)
+ mobj = self._match_valid_url(url)
video_id = mobj.group('id')
video_path = mobj.group('path')
is_live = video_type == 'live'
json_data = self._download_json(
- 'http://player.vgtrk.com/iframe/data%s/id/%s' % ('live' if is_live else 'video', video_id),
+ 'http://player.vgtrk.com/iframe/data{}/id/{}'.format('live' if is_live else 'video', video_id),
video_id, 'Downloading JSON')
if json_data['errors']:
- raise ExtractorError('%s said: %s' % (self.IE_NAME, json_data['errors']), expected=True)
+ raise ExtractorError('{} said: {}'.format(self.IE_NAME, json_data['errors']), expected=True)
playlist = json_data['data']['playlist']
medialist = playlist['medialist']
media = medialist[0]
if media['errors']:
- raise ExtractorError('%s said: %s' % (self.IE_NAME, media['errors']), expected=True)
+ raise ExtractorError('{} said: {}'.format(self.IE_NAME, media['errors']), expected=True)
- view_count = playlist.get('count_views')
+ view_count = int_or_none(playlist.get('count_views'))
priority_transport = playlist['priority_transport']
thumbnail = media['picture']
duration = int_or_none(media.get('duration'))
formats = []
+ subtitles = {}
for transport, links in media['sources'].items():
for quality, url in links.items():
'player_url': 'http://player.rutv.ru/flash3v/osmf.swf?i=22',
'rtmp_live': True,
'ext': 'flv',
- 'vbr': int(quality),
- 'quality': preference,
+ 'vbr': str_to_int(quality),
}
elif transport == 'm3u8':
- formats.extend(self._extract_m3u8_formats(
- url, video_id, 'mp4', quality=preference, m3u8_id='hls'))
+ fmt, subs = self._extract_m3u8_formats_and_subtitles(
+ url, video_id, 'mp4', quality=preference, m3u8_id='hls')
+ formats.extend(fmt)
+ self._merge_subtitles(subs, target=subtitles)
continue
else:
fmt = {
- 'url': url
+ 'url': url,
}
fmt.update({
- 'width': width,
- 'height': height,
- 'format_id': '%s-%s' % (transport, quality),
+ 'width': int_or_none(quality, default=height, invscale=width, scale=height),
+ 'height': int_or_none(quality, default=height),
+ 'format_id': f'{transport}-{quality}',
+ 'source_preference': preference,
})
formats.append(fmt)
- self._sort_formats(formats)
-
return {
'id': video_id,
- 'title': self._live_title(title) if is_live else title,
+ 'title': title,
'description': description,
'thumbnail': thumbnail,
'view_count': view_count,
'duration': duration,
'formats': formats,
+ 'subtitles': subtitles,
'is_live': is_live,
+ '_format_sort_fields': ('source', ),
}