]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/ntvru.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / ntvru.py
CommitLineData
263f4b51
S
1from .common import InfoExtractor
2from ..utils import (
054fe3cc 3 int_or_none,
f9c4a452
RA
4 strip_or_none,
5 unescapeHTML,
6 xpath_text,
263f4b51
S
7)
8
9
3fd45e03 10class 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,
263f4b51 24 },
9cb0e65d
S
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 не верят в трагический исход',
ec85ded8 33 'thumbnail': r're:^http://.*\.jpg',
9cb0e65d 34 'duration': 172,
263f4b51 35 },
9cb0e65d
S
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',
ec85ded8 44 'thumbnail': r're:^http://.*\.jpg',
9cb0e65d 45 'duration': 1496,
263f4b51 46 },
9cb0e65d 47 }, {
f9c4a452
RA
48 'url': 'https://www.ntv.ru/kino/Koma_film/m70281/o336036/video/',
49 'md5': 'e9c7cde24d9d3eaed545911a04e6d4f4',
9cb0e65d 50 'info_dict': {
f9c4a452 51 'id': '1126480',
9cb0e65d
S
52 'ext': 'mp4',
53 'title': 'Остросюжетный фильм «Кома»',
54 'description': 'Остросюжетный фильм «Кома»',
ec85ded8 55 'thumbnail': r're:^http://.*\.jpg',
9cb0e65d 56 'duration': 5592,
263f4b51 57 },
9cb0e65d
S
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': '«Дело врачей»: «Деревце жизни»',
ec85ded8 66 'thumbnail': r're:^http://.*\.jpg',
9cb0e65d 67 'duration': 2590,
263f4b51 68 },
f9c4a452
RA
69 }, {
70 # Schemeless file URL
71 'url': 'https://www.ntv.ru/video/1797442',
72 'only_matching': True,
9cb0e65d 73 }]
263f4b51
S
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>',
50fc5996 78 r'<video restriction[^>]+><key>(\d+)</key>',
263f4b51
S
79 ]
80
81 def _real_extract(self, url):
3fd45e03 82 video_id = self._match_id(url)
056b5668 83
054fe3cc 84 webpage = self._download_webpage(url, video_id)
263f4b51 85
9cb0e65d
S
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')
263f4b51 96
054fe3cc
S
97 player = self._download_xml(
98 'http://www.ntv.ru/vi%s/' % video_id,
99 video_id, 'Downloading video XML')
9cb0e65d 100
f9c4a452 101 title = strip_or_none(unescapeHTML(xpath_text(player, './data/title', 'title', fatal=True)))
263f4b51 102
054fe3cc 103 video = player.find('./data/video')
8f656244 104
263f4b51
S
105 formats = []
106 for format_id in ['', 'hi', 'webm']:
f9c4a452
RA
107 file_ = xpath_text(video, './%sfile' % format_id)
108 if not file_:
263f4b51 109 continue
f9c4a452
RA
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_
263f4b51 114 formats.append({
f9c4a452
RA
115 'url': file_,
116 'filesize': int_or_none(xpath_text(video, './%ssize' % format_id)),
263f4b51 117 })
263f4b51
S
118
119 return {
f9c4a452 120 'id': xpath_text(video, './id'),
263f4b51 121 'title': title,
f9c4a452
RA
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')),
263f4b51 126 'formats': formats,
5f6a1245 127 }