]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/newstube.py
Prepare for release.
[youtubedl] / youtube_dl / extractor / newstube.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import ExtractorError
8
9
10 class NewstubeIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?newstube\.ru/media/(?P<id>.+)'
12 _TEST = {
13 'url': 'http://www.newstube.ru/media/telekanal-cnn-peremestil-gorod-slavyansk-v-krym',
14 'info_dict': {
15 'id': '728e0ef2-e187-4012-bac0-5a081fdcb1f6',
16 'ext': 'flv',
17 'title': 'Телеканал CNN переместил город Славянск в Крым',
18 'description': 'md5:419a8c9f03442bc0b0a794d689360335',
19 'duration': 31.05,
20 },
21 'params': {
22 # rtmp download
23 'skip_download': True,
24 },
25 }
26
27 def _real_extract(self, url):
28 mobj = re.match(self._VALID_URL, url)
29 video_id = mobj.group('id')
30
31 page = self._download_webpage(url, video_id, 'Downloading page')
32
33 video_guid = self._html_search_regex(
34 r'<meta property="og:video" 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})',
35 page, 'video GUID')
36
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')
40
41 def ns(s):
42 return s.replace('/', '/%(ns)s') % {'ns': '{http://app1.newstube.ru/N2SiteWS/player.asmx}'}
43
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)
47
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
54
55 formats = []
56
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:
60 continue
61
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 quality_id = stream_info.find(ns('./QualityId')).text
66 name = stream_info.find(ns('./Name')).text
67 width = int(stream_info.find(ns('./Width')).text)
68 height = int(stream_info.find(ns('./Height')).text)
69
70 formats.append({
71 'url': 'rtmp://%s/%s' % (server, app),
72 'app': app,
73 'play_path': '01/%s' % video_guid.upper(),
74 'rtmp_conn': ['S:%s' % session_id, 'S:%s' % media_id, 'S:n2'],
75 'page_url': url,
76 'ext': 'flv',
77 'format_id': quality_id,
78 'format_note': name,
79 'width': width,
80 'height': height,
81 })
82
83 self._sort_formats(formats)
84
85 return {
86 'id': video_guid,
87 'title': title,
88 'description': description,
89 'thumbnail': thumbnail,
90 'duration': duration,
91 'formats': formats,
92 }