]>
Commit | Line | Data |
---|---|---|
263f4b51 S |
1 | # encoding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
263f4b51 S |
8 | unescapeHTML |
9 | ) | |
10 | ||
11 | ||
12 | class NTVIE(InfoExtractor): | |
13 | _VALID_URL = r'http://(?:www\.)?ntv\.ru/(?P<id>.+)' | |
14 | ||
15 | _TESTS = [ | |
16 | { | |
17 | 'url': 'http://www.ntv.ru/novosti/863142/', | |
18 | 'info_dict': { | |
19 | 'id': '746000', | |
20 | 'ext': 'flv', | |
21 | 'title': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины', | |
22 | 'description': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины', | |
23 | 'duration': 136, | |
24 | }, | |
25 | 'params': { | |
50fc5996 S |
26 | # rtmp download |
27 | 'skip_download': True, | |
28 | }, | |
263f4b51 S |
29 | }, |
30 | { | |
31 | 'url': 'http://www.ntv.ru/video/novosti/750370/', | |
32 | 'info_dict': { | |
33 | 'id': '750370', | |
34 | 'ext': 'flv', | |
35 | 'title': 'Родные пассажиров пропавшего Boeing не верят в трагический исход', | |
36 | 'description': 'Родные пассажиров пропавшего Boeing не верят в трагический исход', | |
37 | 'duration': 172, | |
38 | }, | |
39 | 'params': { | |
50fc5996 S |
40 | # rtmp download |
41 | 'skip_download': True, | |
42 | }, | |
263f4b51 S |
43 | }, |
44 | { | |
45 | 'url': 'http://www.ntv.ru/peredacha/segodnya/m23700/o232416', | |
46 | 'info_dict': { | |
47 | 'id': '747480', | |
48 | 'ext': 'flv', | |
49 | 'title': '«Сегодня». 21 марта 2014 года. 16:00 ', | |
50 | 'description': '«Сегодня». 21 марта 2014 года. 16:00 ', | |
51 | 'duration': 1496, | |
52 | }, | |
53 | 'params': { | |
50fc5996 S |
54 | # rtmp download |
55 | 'skip_download': True, | |
56 | }, | |
263f4b51 S |
57 | }, |
58 | { | |
59 | 'url': 'http://www.ntv.ru/kino/Koma_film', | |
60 | 'info_dict': { | |
c47d21da | 61 | 'id': '758100', |
263f4b51 | 62 | 'ext': 'flv', |
c47d21da S |
63 | 'title': 'Остросюжетный фильм «Кома»', |
64 | 'description': 'Остросюжетный фильм «Кома»', | |
65 | 'duration': 5592, | |
263f4b51 S |
66 | }, |
67 | 'params': { | |
50fc5996 S |
68 | # rtmp download |
69 | 'skip_download': True, | |
70 | }, | |
263f4b51 S |
71 | }, |
72 | { | |
73 | 'url': 'http://www.ntv.ru/serial/Delo_vrachey/m31760/o233916/', | |
74 | 'info_dict': { | |
75 | 'id': '751482', | |
76 | 'ext': 'flv', | |
77 | 'title': '«Дело врачей»: «Деревце жизни»', | |
78 | 'description': '«Дело врачей»: «Деревце жизни»', | |
79 | 'duration': 2590, | |
80 | }, | |
81 | 'params': { | |
50fc5996 S |
82 | # rtmp download |
83 | 'skip_download': True, | |
84 | }, | |
263f4b51 S |
85 | }, |
86 | ] | |
87 | ||
88 | _VIDEO_ID_REGEXES = [ | |
89 | r'<meta property="og:url" content="http://www\.ntv\.ru/video/(\d+)', | |
90 | r'<video embed=[^>]+><id>(\d+)</id>', | |
50fc5996 | 91 | r'<video restriction[^>]+><key>(\d+)</key>', |
263f4b51 S |
92 | ] |
93 | ||
94 | def _real_extract(self, url): | |
95 | mobj = re.match(self._VALID_URL, url) | |
96 | video_id = mobj.group('id') | |
97 | ||
50fc5996 | 98 | page = self._download_webpage(url, video_id) |
056b5668 | 99 | |
50fc5996 | 100 | video_id = self._html_search_regex(self._VIDEO_ID_REGEXES, page, 'video id') |
263f4b51 S |
101 | |
102 | player = self._download_xml('http://www.ntv.ru/vi%s/' % video_id, video_id, 'Downloading video XML') | |
103 | title = unescapeHTML(player.find('./data/title').text) | |
104 | description = unescapeHTML(player.find('./data/description').text) | |
105 | ||
106 | video = player.find('./data/video') | |
107 | video_id = video.find('./id').text | |
108 | thumbnail = video.find('./splash').text | |
109 | duration = int(video.find('./totaltime').text) | |
110 | view_count = int(video.find('./views').text) | |
111 | puid22 = video.find('./puid22').text | |
112 | ||
113 | apps = { | |
114 | '4': 'video1', | |
115 | '7': 'video2', | |
116 | } | |
117 | ||
50fc5996 | 118 | app = apps.get(puid22, apps['4']) |
8f656244 | 119 | |
263f4b51 S |
120 | formats = [] |
121 | for format_id in ['', 'hi', 'webm']: | |
122 | file = video.find('./%sfile' % format_id) | |
123 | if file is None: | |
124 | continue | |
125 | size = video.find('./%ssize' % format_id) | |
263f4b51 S |
126 | formats.append({ |
127 | 'url': 'rtmp://media.ntv.ru/%s' % app, | |
128 | 'app': app, | |
129 | 'play_path': file.text, | |
130 | 'rtmp_conn': 'B:1', | |
131 | 'player_url': 'http://www.ntv.ru/swf/vps1.swf?update=20131128', | |
132 | 'page_url': 'http://www.ntv.ru', | |
133 | 'flash_ver': 'LNX 11,2,202,341', | |
134 | 'rtmp_live': True, | |
135 | 'ext': 'flv', | |
136 | 'filesize': int(size.text), | |
137 | }) | |
138 | self._sort_formats(formats) | |
139 | ||
140 | return { | |
141 | 'id': video_id, | |
142 | 'title': title, | |
143 | 'description': description, | |
144 | 'thumbnail': thumbnail, | |
145 | 'duration': duration, | |
146 | 'view_count': view_count, | |
147 | 'formats': formats, | |
148 | } |