]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/ntvru.py
Add support for https for all extractors as preventive and future-proof measure
[yt-dlp.git] / youtube_dl / extractor / ntvru.py
CommitLineData
263f4b51
S
1# encoding: utf-8
2from __future__ import unicode_literals
3
263f4b51
S
4from .common import InfoExtractor
5from ..utils import (
054fe3cc
S
6 clean_html,
7 xpath_text,
8 int_or_none,
263f4b51
S
9)
10
11
3fd45e03 12class NTVRuIE(InfoExtractor):
8f4b58d7 13 IE_NAME = 'ntv.ru'
5886b38d 14 _VALID_URL = r'https?://(?:www\.)?ntv\.ru/(?P<id>.+)'
263f4b51
S
15
16 _TESTS = [
17 {
18 'url': 'http://www.ntv.ru/novosti/863142/',
054fe3cc 19 'md5': 'ba7ea172a91cb83eb734cad18c10e723',
263f4b51
S
20 'info_dict': {
21 'id': '746000',
054fe3cc 22 'ext': 'mp4',
263f4b51
S
23 'title': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины',
24 'description': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины',
054fe3cc 25 'thumbnail': 're:^http://.*\.jpg',
263f4b51
S
26 'duration': 136,
27 },
263f4b51
S
28 },
29 {
30 'url': 'http://www.ntv.ru/video/novosti/750370/',
054fe3cc 31 'md5': 'adecff79691b4d71e25220a191477124',
263f4b51
S
32 'info_dict': {
33 'id': '750370',
054fe3cc 34 'ext': 'mp4',
263f4b51
S
35 'title': 'Родные пассажиров пропавшего Boeing не верят в трагический исход',
36 'description': 'Родные пассажиров пропавшего Boeing не верят в трагический исход',
054fe3cc 37 'thumbnail': 're:^http://.*\.jpg',
263f4b51
S
38 'duration': 172,
39 },
263f4b51
S
40 },
41 {
42 'url': 'http://www.ntv.ru/peredacha/segodnya/m23700/o232416',
054fe3cc 43 'md5': '82dbd49b38e3af1d00df16acbeab260c',
263f4b51
S
44 'info_dict': {
45 'id': '747480',
054fe3cc
S
46 'ext': 'mp4',
47 'title': '«Сегодня». 21 марта 2014 года. 16:00',
48 'description': '«Сегодня». 21 марта 2014 года. 16:00',
49 'thumbnail': 're:^http://.*\.jpg',
263f4b51
S
50 'duration': 1496,
51 },
263f4b51
S
52 },
53 {
54 'url': 'http://www.ntv.ru/kino/Koma_film',
054fe3cc 55 'md5': 'f825770930937aa7e5aca0dc0d29319a',
263f4b51 56 'info_dict': {
054fe3cc
S
57 'id': '1007609',
58 'ext': 'mp4',
c47d21da
S
59 'title': 'Остросюжетный фильм «Кома»',
60 'description': 'Остросюжетный фильм «Кома»',
054fe3cc 61 'thumbnail': 're:^http://.*\.jpg',
c47d21da 62 'duration': 5592,
263f4b51 63 },
263f4b51
S
64 },
65 {
66 'url': 'http://www.ntv.ru/serial/Delo_vrachey/m31760/o233916/',
054fe3cc 67 'md5': '9320cd0e23f3ea59c330dc744e06ff3b',
263f4b51
S
68 'info_dict': {
69 'id': '751482',
054fe3cc 70 'ext': 'mp4',
263f4b51
S
71 'title': '«Дело врачей»: «Деревце жизни»',
72 'description': '«Дело врачей»: «Деревце жизни»',
054fe3cc 73 'thumbnail': 're:^http://.*\.jpg',
263f4b51
S
74 'duration': 2590,
75 },
263f4b51
S
76 },
77 ]
78
79 _VIDEO_ID_REGEXES = [
80 r'<meta property="og:url" content="http://www\.ntv\.ru/video/(\d+)',
81 r'<video embed=[^>]+><id>(\d+)</id>',
50fc5996 82 r'<video restriction[^>]+><key>(\d+)</key>',
263f4b51
S
83 ]
84
85 def _real_extract(self, url):
3fd45e03 86 video_id = self._match_id(url)
056b5668 87
054fe3cc 88 webpage = self._download_webpage(url, video_id)
263f4b51 89
054fe3cc 90 video_id = self._html_search_regex(self._VIDEO_ID_REGEXES, webpage, 'video id')
263f4b51 91
054fe3cc
S
92 player = self._download_xml(
93 'http://www.ntv.ru/vi%s/' % video_id,
94 video_id, 'Downloading video XML')
95 title = clean_html(xpath_text(player, './data/title', 'title', fatal=True))
96 description = clean_html(xpath_text(player, './data/description', 'description'))
263f4b51 97
054fe3cc
S
98 video = player.find('./data/video')
99 video_id = xpath_text(video, './id', 'video id')
100 thumbnail = xpath_text(video, './splash', 'thumbnail')
101 duration = int_or_none(xpath_text(video, './totaltime', 'duration'))
102 view_count = int_or_none(xpath_text(video, './views', 'view count'))
263f4b51 103
054fe3cc
S
104 token = self._download_webpage(
105 'http://stat.ntv.ru/services/access/token',
106 video_id, 'Downloading access token')
8f656244 107
263f4b51
S
108 formats = []
109 for format_id in ['', 'hi', 'webm']:
054fe3cc
S
110 file_ = video.find('./%sfile' % format_id)
111 if file_ is None:
263f4b51
S
112 continue
113 size = video.find('./%ssize' % format_id)
263f4b51 114 formats.append({
054fe3cc
S
115 'url': 'http://media2.ntv.ru/vod/%s&tok=%s' % (file_.text, token),
116 'filesize': int_or_none(size.text if size is not None else None),
263f4b51
S
117 })
118 self._sort_formats(formats)
119
120 return {
121 'id': video_id,
122 'title': title,
123 'description': description,
124 'thumbnail': thumbnail,
125 'duration': duration,
126 'view_count': view_count,
127 'formats': formats,
5f6a1245 128 }