2014-02-14 00:22:23 +08:00
|
|
|
# encoding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
|
|
|
ExtractorError,
|
|
|
|
int_or_none
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2014-03-17 02:59:40 +08:00
|
|
|
class RUTVIE(InfoExtractor):
|
|
|
|
IE_DESC = 'RUTV.RU'
|
2014-05-10 03:23:24 +08:00
|
|
|
_VALID_URL = r'''(?x)
|
|
|
|
https?://player\.(?:rutv\.ru|vgtrk\.com)/
|
|
|
|
(?P<path>flash2v/container\.swf\?id=
|
|
|
|
|iframe/(?P<type>swf|video|live)/id/
|
|
|
|
|index/iframe/cast_id/)
|
|
|
|
(?P<id>\d+)'''
|
2014-02-14 00:22:23 +08:00
|
|
|
|
|
|
|
_TESTS = [
|
|
|
|
{
|
2014-03-17 02:59:40 +08:00
|
|
|
'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',
|
2014-02-14 00:22:23 +08:00
|
|
|
'info_dict': {
|
2014-03-17 02:59:40 +08:00
|
|
|
'id': '774471',
|
2014-03-07 03:27:39 +08:00
|
|
|
'ext': 'mp4',
|
2014-03-17 02:59:40 +08:00
|
|
|
'title': 'Монологи на все времена',
|
|
|
|
'description': 'md5:18d8b5e6a41fb1faa53819471852d5d5',
|
|
|
|
'duration': 2906,
|
2014-03-07 03:27:39 +08:00
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
# m3u8 download
|
|
|
|
'skip_download': True,
|
|
|
|
},
|
|
|
|
},
|
2014-02-14 00:22:23 +08:00
|
|
|
{
|
2014-03-17 02:59:40 +08:00
|
|
|
'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',
|
2014-02-14 00:22:23 +08:00
|
|
|
'info_dict': {
|
2014-03-17 02:59:40 +08:00
|
|
|
'id': '774016',
|
2014-02-14 00:22:23 +08:00
|
|
|
'ext': 'mp4',
|
2014-03-17 02:59:40 +08:00
|
|
|
'title': 'Чужой в семье Сталина',
|
|
|
|
'description': '',
|
|
|
|
'duration': 2539,
|
2014-02-14 00:22:23 +08:00
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
# m3u8 download
|
|
|
|
'skip_download': True,
|
|
|
|
},
|
|
|
|
},
|
2014-03-07 03:27:39 +08:00
|
|
|
{
|
2014-03-17 02:59:40 +08:00
|
|
|
'url': 'http://player.rutv.ru/iframe/swf/id/766888/sid/hitech/?acc_video_id=4000',
|
2014-03-07 03:27:39 +08:00
|
|
|
'info_dict': {
|
|
|
|
'id': '766888',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': 'Вести.net: интернет-гиганты начали перетягивание программных "одеял"',
|
|
|
|
'description': 'md5:65ddd47f9830c4f42ed6475f8730c995',
|
|
|
|
'duration': 279,
|
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
# m3u8 download
|
|
|
|
'skip_download': True,
|
|
|
|
},
|
|
|
|
},
|
2014-03-10 19:52:00 +08:00
|
|
|
{
|
2014-03-17 02:59:40 +08:00
|
|
|
'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',
|
2014-03-10 19:52:00 +08:00
|
|
|
'info_dict': {
|
2014-03-17 02:59:40 +08:00
|
|
|
'id': '771852',
|
2014-03-10 19:52:00 +08:00
|
|
|
'ext': 'mp4',
|
2014-03-17 02:59:40 +08:00
|
|
|
'title': 'Прямой эфир. Жертвы загадочной болезни: смерть от старости в 17 лет',
|
|
|
|
'description': 'md5:b81c8c55247a4bd996b43ce17395b2d8',
|
|
|
|
'duration': 3096,
|
2014-03-10 19:52:00 +08:00
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
# m3u8 download
|
|
|
|
'skip_download': True,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2014-03-17 02:59:40 +08:00
|
|
|
'url': 'http://player.rutv.ru/iframe/live/id/51499/showZoomBtn/false/isPlay/true/sid/sochi2014',
|
2014-03-10 19:52:00 +08:00
|
|
|
'info_dict': {
|
|
|
|
'id': '51499',
|
|
|
|
'ext': 'flv',
|
|
|
|
'title': 'Сочи-2014. Биатлон. Индивидуальная гонка. Мужчины ',
|
|
|
|
'description': 'md5:9e0ed5c9d2fa1efbfdfed90c9a6d179c',
|
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
# rtmp download
|
|
|
|
'skip_download': True,
|
|
|
|
},
|
2014-03-17 02:59:40 +08:00
|
|
|
'skip': 'Translation has finished',
|
2014-03-10 19:52:00 +08:00
|
|
|
},
|
2014-02-14 00:22:23 +08:00
|
|
|
]
|
|
|
|
|
2014-03-17 02:59:40 +08:00
|
|
|
@classmethod
|
|
|
|
def _extract_url(cls, webpage):
|
2014-03-07 03:27:39 +08:00
|
|
|
mobj = re.search(
|
2014-05-10 03:23:24 +08:00
|
|
|
r'<iframe[^>]+?src=(["\'])(?P<url>https?://player\.rutv\.ru/(?:iframe/(?:swf|video|live)/id|index/iframe/cast_id)/.+?)\1', webpage)
|
2014-03-07 03:27:39 +08:00
|
|
|
if mobj:
|
2014-03-17 02:59:40 +08:00
|
|
|
return mobj.group('url')
|
2014-03-07 03:27:39 +08:00
|
|
|
|
|
|
|
mobj = re.search(
|
2014-09-10 02:09:04 +08:00
|
|
|
r'<meta[^>]+?property=(["\'])og:video\1[^>]+?content=(["\'])(?P<url>https?://player\.(?:rutv\.ru|vgtrk\.com)/flash2v/container\.swf\?id=.+?\2)',
|
2014-03-17 02:59:40 +08:00
|
|
|
webpage)
|
2014-02-14 00:22:23 +08:00
|
|
|
if mobj:
|
2014-03-17 02:59:40 +08:00
|
|
|
return mobj.group('url')
|
2014-02-14 00:22:23 +08:00
|
|
|
|
2014-03-17 02:59:40 +08:00
|
|
|
def _real_extract(self, url):
|
|
|
|
mobj = re.match(self._VALID_URL, url)
|
|
|
|
video_id = mobj.group('id')
|
2014-05-10 03:23:24 +08:00
|
|
|
video_path = mobj.group('path')
|
2014-02-14 00:22:23 +08:00
|
|
|
|
2014-05-10 03:23:24 +08:00
|
|
|
if video_path.startswith('flash2v'):
|
2014-03-17 02:59:40 +08:00
|
|
|
video_type = 'video'
|
2014-05-10 03:23:24 +08:00
|
|
|
elif video_path.startswith('iframe'):
|
|
|
|
video_type = mobj.group('type')
|
|
|
|
if video_type == 'swf':
|
|
|
|
video_type = 'video'
|
|
|
|
elif video_path.startswith('index/iframe/cast_id'):
|
|
|
|
video_type = 'live'
|
2014-02-14 00:22:23 +08:00
|
|
|
|
|
|
|
json_data = self._download_json(
|
|
|
|
'http://player.rutv.ru/iframe/%splay/id/%s' % ('live-' if video_type == 'live' else '', video_id),
|
|
|
|
video_id, 'Downloading JSON')
|
|
|
|
|
|
|
|
if json_data['errors']:
|
2014-03-17 02:59:40 +08:00
|
|
|
raise ExtractorError('%s said: %s' % (self.IE_NAME, json_data['errors']), expected=True)
|
2014-02-14 00:22:23 +08:00
|
|
|
|
|
|
|
playlist = json_data['data']['playlist']
|
|
|
|
medialist = playlist['medialist']
|
|
|
|
media = medialist[0]
|
|
|
|
|
|
|
|
if media['errors']:
|
2014-03-17 02:59:40 +08:00
|
|
|
raise ExtractorError('%s said: %s' % (self.IE_NAME, media['errors']), expected=True)
|
2014-02-14 00:22:23 +08:00
|
|
|
|
|
|
|
view_count = playlist.get('count_views')
|
|
|
|
priority_transport = playlist['priority_transport']
|
|
|
|
|
|
|
|
thumbnail = media['picture']
|
2014-03-04 22:40:35 +08:00
|
|
|
width = int_or_none(media['width'])
|
|
|
|
height = int_or_none(media['height'])
|
2014-02-14 00:22:23 +08:00
|
|
|
description = media['anons']
|
|
|
|
title = media['title']
|
|
|
|
duration = int_or_none(media.get('duration'))
|
|
|
|
|
|
|
|
formats = []
|
|
|
|
|
|
|
|
for transport, links in media['sources'].items():
|
|
|
|
for quality, url in links.items():
|
|
|
|
if transport == 'rtmp':
|
|
|
|
mobj = re.search(r'^(?P<url>rtmp://[^/]+/(?P<app>.+))/(?P<playpath>.+)$', url)
|
|
|
|
if not mobj:
|
|
|
|
continue
|
|
|
|
fmt = {
|
|
|
|
'url': mobj.group('url'),
|
|
|
|
'play_path': mobj.group('playpath'),
|
|
|
|
'app': mobj.group('app'),
|
|
|
|
'page_url': 'http://player.rutv.ru',
|
|
|
|
'player_url': 'http://player.rutv.ru/flash2v/osmf.swf?i=22',
|
|
|
|
'rtmp_live': True,
|
|
|
|
'ext': 'flv',
|
|
|
|
'vbr': int(quality),
|
|
|
|
}
|
|
|
|
elif transport == 'm3u8':
|
|
|
|
fmt = {
|
|
|
|
'url': url,
|
|
|
|
'ext': 'mp4',
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
fmt = {
|
|
|
|
'url': url
|
|
|
|
}
|
|
|
|
fmt.update({
|
|
|
|
'width': width,
|
|
|
|
'height': height,
|
|
|
|
'format_id': '%s-%s' % (transport, quality),
|
|
|
|
'preference': -1 if priority_transport == transport else -2,
|
|
|
|
})
|
|
|
|
formats.append(fmt)
|
|
|
|
|
|
|
|
if not formats:
|
|
|
|
raise ExtractorError('No media links available for %s' % video_id)
|
|
|
|
|
|
|
|
self._sort_formats(formats)
|
|
|
|
|
|
|
|
return {
|
|
|
|
'id': video_id,
|
|
|
|
'title': title,
|
|
|
|
'description': description,
|
|
|
|
'thumbnail': thumbnail,
|
|
|
|
'view_count': view_count,
|
|
|
|
'duration': duration,
|
|
|
|
'formats': formats,
|
|
|
|
}
|