]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/ntvru.py
[ntvru] Rename from NTV to clarify the difference between n-tv.de and ntv.ru
[yt-dlp.git] / youtube_dl / extractor / ntvru.py
CommitLineData
263f4b51
S
1# encoding: utf-8
2from __future__ import unicode_literals
3
4import re
5
6from .common import InfoExtractor
7from ..utils import (
263f4b51
S
8 unescapeHTML
9)
10
11
3fd45e03 12class NTVRuIE(InfoExtractor):
263f4b51
S
13 _VALID_URL = r'http://(?:www\.)?ntv\.ru/(?P<id>.+)'
14
15 _TESTS = [
16 {
17 'url': 'http://www.ntv.ru/novosti/863142/',
18 'info_dict': {
19 'id': '746000',
20 'ext': 'flv',
21 'title': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины',
22 'description': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины',
23 'duration': 136,
24 },
25 'params': {
50fc5996
S
26 # rtmp download
27 'skip_download': True,
28 },
263f4b51
S
29 },
30 {
31 'url': 'http://www.ntv.ru/video/novosti/750370/',
32 'info_dict': {
33 'id': '750370',
34 'ext': 'flv',
35 'title': 'Родные пассажиров пропавшего Boeing не верят в трагический исход',
36 'description': 'Родные пассажиров пропавшего Boeing не верят в трагический исход',
37 'duration': 172,
38 },
39 'params': {
50fc5996
S
40 # rtmp download
41 'skip_download': True,
42 },
263f4b51
S
43 },
44 {
45 'url': 'http://www.ntv.ru/peredacha/segodnya/m23700/o232416',
46 'info_dict': {
47 'id': '747480',
48 'ext': 'flv',
49 'title': '«Сегодня». 21 марта 2014 года. 16:00 ',
50 'description': '«Сегодня». 21 марта 2014 года. 16:00 ',
51 'duration': 1496,
52 },
53 'params': {
50fc5996
S
54 # rtmp download
55 'skip_download': True,
56 },
263f4b51
S
57 },
58 {
59 'url': 'http://www.ntv.ru/kino/Koma_film',
60 'info_dict': {
c47d21da 61 'id': '758100',
263f4b51 62 'ext': 'flv',
c47d21da
S
63 'title': 'Остросюжетный фильм «Кома»',
64 'description': 'Остросюжетный фильм «Кома»',
65 'duration': 5592,
263f4b51
S
66 },
67 'params': {
50fc5996
S
68 # rtmp download
69 'skip_download': True,
70 },
263f4b51
S
71 },
72 {
73 'url': 'http://www.ntv.ru/serial/Delo_vrachey/m31760/o233916/',
74 'info_dict': {
75 'id': '751482',
76 'ext': 'flv',
77 'title': '«Дело врачей»: «Деревце жизни»',
78 'description': '«Дело врачей»: «Деревце жизни»',
79 'duration': 2590,
80 },
81 'params': {
50fc5996
S
82 # rtmp download
83 'skip_download': True,
84 },
263f4b51
S
85 },
86 ]
87
88 _VIDEO_ID_REGEXES = [
89 r'<meta property="og:url" content="http://www\.ntv\.ru/video/(\d+)',
90 r'<video embed=[^>]+><id>(\d+)</id>',
50fc5996 91 r'<video restriction[^>]+><key>(\d+)</key>',
263f4b51
S
92 ]
93
94 def _real_extract(self, url):
3fd45e03 95 video_id = self._match_id(url)
50fc5996 96 page = self._download_webpage(url, video_id)
056b5668 97
50fc5996 98 video_id = self._html_search_regex(self._VIDEO_ID_REGEXES, page, 'video id')
263f4b51
S
99
100 player = self._download_xml('http://www.ntv.ru/vi%s/' % video_id, video_id, 'Downloading video XML')
101 title = unescapeHTML(player.find('./data/title').text)
102 description = unescapeHTML(player.find('./data/description').text)
103
104 video = player.find('./data/video')
105 video_id = video.find('./id').text
106 thumbnail = video.find('./splash').text
107 duration = int(video.find('./totaltime').text)
108 view_count = int(video.find('./views').text)
109 puid22 = video.find('./puid22').text
110
111 apps = {
112 '4': 'video1',
113 '7': 'video2',
114 }
115
50fc5996 116 app = apps.get(puid22, apps['4'])
8f656244 117
263f4b51
S
118 formats = []
119 for format_id in ['', 'hi', 'webm']:
120 file = video.find('./%sfile' % format_id)
121 if file is None:
122 continue
123 size = video.find('./%ssize' % format_id)
263f4b51
S
124 formats.append({
125 'url': 'rtmp://media.ntv.ru/%s' % app,
126 'app': app,
127 'play_path': file.text,
128 'rtmp_conn': 'B:1',
129 'player_url': 'http://www.ntv.ru/swf/vps1.swf?update=20131128',
130 'page_url': 'http://www.ntv.ru',
3c1b81b9 131 'flash_version': 'LNX 11,2,202,341',
263f4b51
S
132 'rtmp_live': True,
133 'ext': 'flv',
134 'filesize': int(size.text),
135 })
136 self._sort_formats(formats)
137
138 return {
139 'id': video_id,
140 'title': title,
141 'description': description,
142 'thumbnail': thumbnail,
143 'duration': duration,
144 'view_count': view_count,
145 'formats': formats,
5f6a1245 146 }