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