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