]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/ntvru.py
91b7724eb4a04241af79c40c6cbbcbd6fda684ec
[yt-dlp.git] / yt_dlp / extractor / ntvru.py
1 from .common import InfoExtractor
2 from ..utils import (
3 int_or_none,
4 strip_or_none,
5 unescapeHTML,
6 xpath_text,
7 )
8
9
10 class NTVRuIE(InfoExtractor):
11 IE_NAME = 'ntv.ru'
12 _VALID_URL = r'https?://(?:www\.)?ntv\.ru/(?:[^/]+/)*(?P<id>[^/?#&]+)'
13
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': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины',
22 'thumbnail': r're:^http://.*\.jpg',
23 'duration': 136,
24 'view_count': int,
25 },
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 не верят в трагический исход',
34 'thumbnail': r're:^http://.*\.jpg',
35 'duration': 172,
36 'view_count': int,
37 },
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': r're:^http://.*\.jpg',
47 'duration': 1496,
48 'view_count': int,
49 },
50 }, {
51 'url': 'https://www.ntv.ru/kino/Koma_film/m70281/o336036/video/',
52 'md5': 'e9c7cde24d9d3eaed545911a04e6d4f4',
53 'info_dict': {
54 'id': '1126480',
55 'ext': 'mp4',
56 'title': 'Остросюжетный фильм «Кома»',
57 'description': 'Остросюжетный фильм «Кома»',
58 'thumbnail': r're:^http://.*\.jpg',
59 'duration': 5592,
60 'view_count': int,
61 },
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': '«Дело врачей»: «Деревце жизни»',
70 'thumbnail': r're:^http://.*\.jpg',
71 'duration': 2590,
72 'view_count': int,
73 },
74 }, {
75 # Schemeless file URL
76 'url': 'https://www.ntv.ru/video/1797442',
77 'only_matching': True,
78 }]
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>',
83 r'<video restriction[^>]+><key>(\d+)</key>',
84 ]
85
86 def _real_extract(self, url):
87 video_id = self._match_id(url)
88
89 webpage = self._download_webpage(url, video_id)
90
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')
101
102 player = self._download_xml(
103 'http://www.ntv.ru/vi%s/' % video_id,
104 video_id, 'Downloading video XML')
105
106 title = strip_or_none(unescapeHTML(xpath_text(player, './data/title', 'title', fatal=True)))
107
108 video = player.find('./data/video')
109
110 formats = []
111 for format_id in ['', 'hi', 'webm']:
112 file_ = xpath_text(video, './%sfile' % format_id)
113 if not file_:
114 continue
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_
119 formats.append({
120 'url': file_,
121 'filesize': int_or_none(xpath_text(video, './%ssize' % format_id)),
122 })
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))
131
132 return {
133 'id': xpath_text(video, './id'),
134 'title': title,
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')),
139 'formats': formats,
140 }