]> 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
8
9 class NewstubeIE(InfoExtractor):
10 _VALID_URL = r'https?://(?:www\.)?newstube\.ru/media/(?P<id>.+)'
11 _TEST = {
12 'url': 'http://newstube.ru/media/na-korable-progress-prodolzhaetsya-testirovanie-sistemy-kurs',
13 'info_dict': {
14 'id': 'd156a237-a6e9-4111-a682-039995f721f1',
15 'ext': 'flv',
16 'title': 'На корабле «Прогресс» продолжается тестирование системы «Курс»',
17 'description': 'md5:d0cbe7b4a6f600552617e48548d5dc77',
18 'duration': 20.04,
19 },
20 'params': {
21 # rtmp download
22 'skip_download': True,
23 },
24 }
25
26 def _real_extract(self, url):
27 mobj = re.match(self._VALID_URL, url)
28 video_id = mobj.group('id')
29
30 page = self._download_webpage(url, video_id, 'Downloading page')
31
32 video_guid = self._html_search_regex(
33 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})',
34 page, 'video GUID')
35
36 player = self._download_xml(
37 'http://p.newstube.ru/v2/player.asmx/GetAutoPlayInfo6?state=&url=%s&sessionId=&id=%s&placement=profile&location=n2' % (url, video_guid),
38 video_guid, 'Downloading player XML')
39
40 def ns(s):
41 return s.replace('/', '/%(ns)s') % {'ns': '{http://app1.newstube.ru/N2SiteWS/player.asmx}'}
42
43 session_id = player.find(ns('./SessionId')).text
44 media_info = player.find(ns('./Medias/MediaInfo'))
45 title = media_info.find(ns('./Name')).text
46 description = self._og_search_description(page)
47 thumbnail = media_info.find(ns('./KeyFrame')).text
48 duration = int(media_info.find(ns('./Duration')).text) / 1000.0
49
50 formats = []
51
52 for stream_info in media_info.findall(ns('./Streams/StreamInfo')):
53 media_location = stream_info.find(ns('./MediaLocation'))
54 if media_location is None:
55 continue
56
57 server = media_location.find(ns('./Server')).text
58 app = media_location.find(ns('./App')).text
59 media_id = stream_info.find(ns('./Id')).text
60 quality_id = stream_info.find(ns('./QualityId')).text
61 name = stream_info.find(ns('./Name')).text
62 width = int(stream_info.find(ns('./Width')).text)
63 height = int(stream_info.find(ns('./Height')).text)
64
65 formats.append({
66 'url': 'rtmp://%s/%s' % (server, app),
67 'app': app,
68 'play_path': '01/%s' % video_guid.upper(),
69 'rtmp_conn': ['S:%s' % session_id, 'S:%s' % media_id, 'S:n2'],
70 'page_url': url,
71 'ext': 'flv',
72 'format_id': quality_id,
73 'format_note': name,
74 'width': width,
75 'height': height,
76 })
77
78 self._sort_formats(formats)
79
80 return {
81 'id': video_guid,
82 'title': title,
83 'description': description,
84 'thumbnail': thumbnail,
85 'duration': duration,
86 'formats': formats,
87 }