2 from __future__ import unicode_literals
6 from .common import InfoExtractor
13 class NewstubeIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?newstube\.ru/media/(?P<id>.+)'
16 'url': 'http://www.newstube.ru/media/telekanal-cnn-peremestil-gorod-slavyansk-v-krym',
17 'md5': '801eef0c2a9f4089fa04e4fe3533abdc',
19 'id': '728e0ef2-e187-4012-bac0-5a081fdcb1f6',
21 'title': 'Телеканал CNN переместил город Славянск в Крым',
22 'description': 'md5:419a8c9f03442bc0b0a794d689360335',
27 def _real_extract(self, url):
28 mobj = re.match(self._VALID_URL, url)
29 video_id = mobj.group('id')
31 page = self._download_webpage(url, video_id, 'Downloading page')
33 video_guid = self._html_search_regex(
34 r'<meta property="og:video:url" content="https?://(?:www\.)?newstube\.ru/freshplayer\.swf\?guid=(?P<guid>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})',
37 player = self._download_xml(
38 'http://p.newstube.ru/v2/player.asmx/GetAutoPlayInfo6?state=&url=%s&sessionId=&id=%s&placement=profile&location=n2' % (url, video_guid),
39 video_guid, 'Downloading player XML')
42 return s.replace('/', '/%(ns)s') % {'ns': '{http://app1.newstube.ru/N2SiteWS/player.asmx}'}
44 error_message = player.find(ns('./ErrorMessage'))
45 if error_message is not None:
46 raise ExtractorError('%s returned error: %s' % (self.IE_NAME, error_message.text), expected=True)
48 session_id = player.find(ns('./SessionId')).text
49 media_info = player.find(ns('./Medias/MediaInfo'))
50 title = media_info.find(ns('./Name')).text
51 description = self._og_search_description(page)
52 thumbnail = media_info.find(ns('./KeyFrame')).text
53 duration = int(media_info.find(ns('./Duration')).text) / 1000.0
57 for stream_info in media_info.findall(ns('./Streams/StreamInfo')):
58 media_location = stream_info.find(ns('./MediaLocation'))
59 if media_location is None:
62 server = media_location.find(ns('./Server')).text
63 app = media_location.find(ns('./App')).text
64 media_id = stream_info.find(ns('./Id')).text
65 name = stream_info.find(ns('./Name')).text
66 width = int(stream_info.find(ns('./Width')).text)
67 height = int(stream_info.find(ns('./Height')).text)
70 'url': 'rtmp://%s/%s' % (server, app),
72 'play_path': '01/%s' % video_guid.upper(),
73 'rtmp_conn': ['S:%s' % session_id, 'S:%s' % media_id, 'S:n2'],
76 'format_id': 'rtmp' + ('-%s' % name if name else ''),
81 sources_data = self._download_json(
82 'http://www.newstube.ru/player2/getsources?guid=%s' % video_guid,
83 video_guid, fatal=False)
85 for source in sources_data.get('Sources', []):
86 source_url = source.get('Src')
89 height = int_or_none(source.get('Height'))
91 'format_id': 'http' + ('-%dp' % height if height else ''),
93 'width': int_or_none(source.get('Width')),
96 source_type = source.get('Type')
98 mobj = re.search(r'codecs="([^,]+),\s*([^"]+)"', source_type)
100 vcodec, acodec = mobj.groups()
107 self._check_formats(formats, video_guid)
108 self._sort_formats(formats)
113 'description': description,
114 'thumbnail': thumbnail,
115 'duration': duration,