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