]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/ntvru.py
[ie/matchtv] Fix extractor (#10190)
[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 'skip': '404 Not Found',
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',
47 'thumbnail': r're:^http://.*\.jpg',
48 'duration': 1496,
49 'view_count': int,
50 },
51 }, {
52 'url': 'https://www.ntv.ru/kino/Koma_film/m70281/o336036/video/',
53 'md5': 'e9c7cde24d9d3eaed545911a04e6d4f4',
54 'info_dict': {
55 'id': '1126480',
56 'ext': 'mp4',
57 'title': 'Остросюжетный фильм «Кома»',
58 'description': 'Остросюжетный фильм «Кома»',
59 'thumbnail': r're:^http://.*\.jpg',
60 'duration': 5592,
61 'view_count': int,
62 },
63 }, {
64 'url': 'http://www.ntv.ru/serial/Delo_vrachey/m31760/o233916/',
65 'md5': '9320cd0e23f3ea59c330dc744e06ff3b',
66 'info_dict': {
67 'id': '751482',
68 'ext': 'mp4',
69 'title': '«Дело врачей»: «Деревце жизни»',
70 'description': '«Дело врачей»: «Деревце жизни»',
71 'thumbnail': r're:^http://.*\.jpg',
72 'duration': 2590,
73 'view_count': int,
74 },
75 }, {
76 # Schemeless file URL
77 'url': 'https://www.ntv.ru/video/1797442',
78 'only_matching': True,
79 }]
80
81 _VIDEO_ID_REGEXES = [
82 r'<meta property="og:url" content="https?://www\.ntv\.ru/video/(\d+)',
83 r'<meta property="og:video:(?:url|iframe)" content="https?://www\.ntv\.ru/embed/(\d+)',
84 r'<video embed=[^>]+><id>(\d+)</id>',
85 r'<video restriction[^>]+><key>(\d+)</key>',
86 ]
87
88 def _real_extract(self, url):
89 video_id = self._match_id(url)
90
91 webpage = self._download_webpage(url, video_id)
92
93 video_url = self._og_search_property(
94 ('video', 'video:iframe'), webpage, default=None)
95 if video_url:
96 video_id = self._search_regex(
97 r'https?://(?:www\.)?ntv\.ru/video/(?:embed/)?(\d+)',
98 video_url, 'video id', default=None)
99
100 if not video_id:
101 video_id = self._html_search_regex(
102 self._VIDEO_ID_REGEXES, webpage, 'video id')
103
104 player = self._download_xml(
105 f'http://www.ntv.ru/vi{video_id}/',
106 video_id, 'Downloading video XML')
107
108 title = strip_or_none(unescapeHTML(xpath_text(player, './data/title', 'title', fatal=True)))
109
110 video = player.find('./data/video')
111
112 formats = []
113 for format_id in ['', 'hi', 'webm']:
114 file_ = xpath_text(video, f'./{format_id}file')
115 if not file_:
116 continue
117 if file_.startswith('//'):
118 file_ = self._proto_relative_url(file_)
119 elif not file_.startswith('http'):
120 file_ = 'http://media.ntv.ru/vod/' + file_
121 formats.append({
122 'url': file_,
123 'filesize': int_or_none(xpath_text(video, f'./{format_id}size')),
124 })
125 hls_manifest = xpath_text(video, './playback/hls')
126 if hls_manifest:
127 formats.extend(self._extract_m3u8_formats(
128 hls_manifest, video_id, m3u8_id='hls', fatal=False))
129 dash_manifest = xpath_text(video, './playback/dash')
130 if dash_manifest:
131 formats.extend(self._extract_mpd_formats(
132 dash_manifest, video_id, mpd_id='dash', fatal=False))
133
134 return {
135 'id': xpath_text(video, './id'),
136 'title': title,
137 'description': strip_or_none(unescapeHTML(xpath_text(player, './data/description'))),
138 'thumbnail': xpath_text(video, './splash'),
139 'duration': int_or_none(xpath_text(video, './totaltime')),
140 'view_count': int_or_none(xpath_text(video, './views')),
141 'formats': formats,
142 }