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