]>
Commit | Line | Data |
---|---|---|
dcdb292f | 1 | # coding: utf-8 |
263f4b51 S |
2 | from __future__ import unicode_literals |
3 | ||
263f4b51 S |
4 | from .common import InfoExtractor |
5 | from ..utils import ( | |
054fe3cc S |
6 | clean_html, |
7 | xpath_text, | |
8 | int_or_none, | |
263f4b51 S |
9 | ) |
10 | ||
11 | ||
3fd45e03 | 12 | class NTVRuIE(InfoExtractor): |
8f4b58d7 | 13 | IE_NAME = 'ntv.ru' |
9cb0e65d | 14 | _VALID_URL = r'https?://(?:www\.)?ntv\.ru/(?:[^/]+/)*(?P<id>[^/?#&]+)' |
263f4b51 | 15 | |
9cb0e65d S |
16 | _TESTS = [{ |
17 | 'url': 'http://www.ntv.ru/novosti/863142/', | |
18 | 'md5': 'ba7ea172a91cb83eb734cad18c10e723', | |
19 | 'info_dict': { | |
20 | 'id': '746000', | |
21 | 'ext': 'mp4', | |
22 | 'title': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины', | |
23 | 'description': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины', | |
24 | 'thumbnail': 're:^http://.*\.jpg', | |
25 | 'duration': 136, | |
263f4b51 | 26 | }, |
9cb0e65d S |
27 | }, { |
28 | 'url': 'http://www.ntv.ru/video/novosti/750370/', | |
29 | 'md5': 'adecff79691b4d71e25220a191477124', | |
30 | 'info_dict': { | |
31 | 'id': '750370', | |
32 | 'ext': 'mp4', | |
33 | 'title': 'Родные пассажиров пропавшего Boeing не верят в трагический исход', | |
34 | 'description': 'Родные пассажиров пропавшего Boeing не верят в трагический исход', | |
35 | 'thumbnail': 're:^http://.*\.jpg', | |
36 | 'duration': 172, | |
263f4b51 | 37 | }, |
9cb0e65d S |
38 | }, { |
39 | 'url': 'http://www.ntv.ru/peredacha/segodnya/m23700/o232416', | |
40 | 'md5': '82dbd49b38e3af1d00df16acbeab260c', | |
41 | 'info_dict': { | |
42 | 'id': '747480', | |
43 | 'ext': 'mp4', | |
44 | 'title': '«Сегодня». 21 марта 2014 года. 16:00', | |
45 | 'description': '«Сегодня». 21 марта 2014 года. 16:00', | |
46 | 'thumbnail': 're:^http://.*\.jpg', | |
47 | 'duration': 1496, | |
263f4b51 | 48 | }, |
9cb0e65d S |
49 | }, { |
50 | 'url': 'http://www.ntv.ru/kino/Koma_film', | |
51 | 'md5': 'f825770930937aa7e5aca0dc0d29319a', | |
52 | 'info_dict': { | |
53 | 'id': '1007609', | |
54 | 'ext': 'mp4', | |
55 | 'title': 'Остросюжетный фильм «Кома»', | |
56 | 'description': 'Остросюжетный фильм «Кома»', | |
57 | 'thumbnail': 're:^http://.*\.jpg', | |
58 | 'duration': 5592, | |
263f4b51 | 59 | }, |
9cb0e65d S |
60 | }, { |
61 | 'url': 'http://www.ntv.ru/serial/Delo_vrachey/m31760/o233916/', | |
62 | 'md5': '9320cd0e23f3ea59c330dc744e06ff3b', | |
63 | 'info_dict': { | |
64 | 'id': '751482', | |
65 | 'ext': 'mp4', | |
66 | 'title': '«Дело врачей»: «Деревце жизни»', | |
67 | 'description': '«Дело врачей»: «Деревце жизни»', | |
68 | 'thumbnail': 're:^http://.*\.jpg', | |
69 | 'duration': 2590, | |
263f4b51 | 70 | }, |
9cb0e65d | 71 | }] |
263f4b51 S |
72 | |
73 | _VIDEO_ID_REGEXES = [ | |
74 | r'<meta property="og:url" content="http://www\.ntv\.ru/video/(\d+)', | |
75 | r'<video embed=[^>]+><id>(\d+)</id>', | |
50fc5996 | 76 | r'<video restriction[^>]+><key>(\d+)</key>', |
263f4b51 S |
77 | ] |
78 | ||
79 | def _real_extract(self, url): | |
3fd45e03 | 80 | video_id = self._match_id(url) |
056b5668 | 81 | |
054fe3cc | 82 | webpage = self._download_webpage(url, video_id) |
263f4b51 | 83 | |
9cb0e65d S |
84 | video_url = self._og_search_property( |
85 | ('video', 'video:iframe'), webpage, default=None) | |
86 | if video_url: | |
87 | video_id = self._search_regex( | |
88 | r'https?://(?:www\.)?ntv\.ru/video/(?:embed/)?(\d+)', | |
89 | video_url, 'video id', default=None) | |
90 | ||
91 | if not video_id: | |
92 | video_id = self._html_search_regex( | |
93 | self._VIDEO_ID_REGEXES, webpage, 'video id') | |
263f4b51 | 94 | |
054fe3cc S |
95 | player = self._download_xml( |
96 | 'http://www.ntv.ru/vi%s/' % video_id, | |
97 | video_id, 'Downloading video XML') | |
9cb0e65d | 98 | |
054fe3cc S |
99 | title = clean_html(xpath_text(player, './data/title', 'title', fatal=True)) |
100 | description = clean_html(xpath_text(player, './data/description', 'description')) | |
263f4b51 | 101 | |
054fe3cc S |
102 | video = player.find('./data/video') |
103 | video_id = xpath_text(video, './id', 'video id') | |
104 | thumbnail = xpath_text(video, './splash', 'thumbnail') | |
105 | duration = int_or_none(xpath_text(video, './totaltime', 'duration')) | |
106 | view_count = int_or_none(xpath_text(video, './views', 'view count')) | |
263f4b51 | 107 | |
054fe3cc S |
108 | token = self._download_webpage( |
109 | 'http://stat.ntv.ru/services/access/token', | |
110 | video_id, 'Downloading access token') | |
8f656244 | 111 | |
263f4b51 S |
112 | formats = [] |
113 | for format_id in ['', 'hi', 'webm']: | |
054fe3cc S |
114 | file_ = video.find('./%sfile' % format_id) |
115 | if file_ is None: | |
263f4b51 S |
116 | continue |
117 | size = video.find('./%ssize' % format_id) | |
263f4b51 | 118 | formats.append({ |
054fe3cc S |
119 | 'url': 'http://media2.ntv.ru/vod/%s&tok=%s' % (file_.text, token), |
120 | 'filesize': int_or_none(size.text if size is not None else None), | |
263f4b51 S |
121 | }) |
122 | self._sort_formats(formats) | |
123 | ||
124 | return { | |
125 | 'id': video_id, | |
126 | 'title': title, | |
127 | 'description': description, | |
128 | 'thumbnail': thumbnail, | |
129 | 'duration': duration, | |
130 | 'view_count': view_count, | |
131 | 'formats': formats, | |
5f6a1245 | 132 | } |