]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vgtv.py
14e945d494cd2f6e5f3b3e6a03ff6ebb076826dd
[youtubedl] / youtube_dl / extractor / vgtv.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from .xstream import XstreamIE
8 from ..utils import (
9 ExtractorError,
10 float_or_none,
11 )
12
13
14 class VGTVIE(XstreamIE):
15 IE_DESC = 'VGTV, BTTV, FTV, Aftenposten and Aftonbladet'
16
17 _HOST_TO_APPNAME = {
18 'vgtv.no': 'vgtv',
19 'bt.no/tv': 'bttv',
20 'aftenbladet.no/tv': 'satv',
21 'fvn.no/fvntv': 'fvntv',
22 'aftenposten.no/webtv': 'aptv',
23 }
24
25 _APP_NAME_TO_VENDOR = {
26 'vgtv': 'vgtv',
27 'bttv': 'bt',
28 'satv': 'sa',
29 'fvntv': 'fvn',
30 'aptv': 'ap',
31 }
32
33 _VALID_URL = r'''(?x)
34 (?:https?://(?:www\.)?
35 (?P<host>
36 %s
37 )
38 /
39 (?:
40 \#!/(?:video|live)/|
41 embed?.*id=
42 )|
43 (?P<appname>
44 %s
45 ):)
46 (?P<id>\d+)
47 ''' % ('|'.join(_HOST_TO_APPNAME.keys()), '|'.join(_APP_NAME_TO_VENDOR.keys()))
48
49 _TESTS = [
50 {
51 # streamType: vod
52 'url': 'http://www.vgtv.no/#!/video/84196/hevnen-er-soet-episode-10-abu',
53 'md5': 'b8be7a234cebb840c0d512c78013e02f',
54 'info_dict': {
55 'id': '84196',
56 'ext': 'mp4',
57 'title': 'Hevnen er søt: Episode 10 - Abu',
58 'description': 'md5:e25e4badb5f544b04341e14abdc72234',
59 'thumbnail': 're:^https?://.*\.jpg',
60 'duration': 648.000,
61 'timestamp': 1404626400,
62 'upload_date': '20140706',
63 'view_count': int,
64 },
65 },
66 {
67 # streamType: wasLive
68 'url': 'http://www.vgtv.no/#!/live/100764/opptak-vgtv-foelger-em-kvalifiseringen',
69 'info_dict': {
70 'id': '100764',
71 'ext': 'flv',
72 'title': 'OPPTAK: VGTV følger EM-kvalifiseringen',
73 'description': 'md5:3772d9c0dc2dff92a886b60039a7d4d3',
74 'thumbnail': 're:^https?://.*\.jpg',
75 'duration': 9103.0,
76 'timestamp': 1410113864,
77 'upload_date': '20140907',
78 'view_count': int,
79 },
80 'params': {
81 # m3u8 download
82 'skip_download': True,
83 },
84 'skip': 'Video is no longer available',
85 },
86 {
87 # streamType: wasLive
88 'url': 'http://www.vgtv.no/#!/live/113063/direkte-v75-fra-solvalla',
89 'info_dict': {
90 'id': '113063',
91 'ext': 'mp4',
92 'title': 'V75 fra Solvalla 30.05.15',
93 'description': 'md5:b3743425765355855f88e096acc93231',
94 'thumbnail': 're:^https?://.*\.jpg',
95 'duration': 25966,
96 'timestamp': 1432975582,
97 'upload_date': '20150530',
98 'view_count': int,
99 },
100 'params': {
101 # m3u8 download
102 'skip_download': True,
103 },
104 },
105 {
106 'url': 'http://www.aftenposten.no/webtv/#!/video/21039/trailer-sweatshop-i-can-t-take-any-more',
107 'md5': 'fd828cd29774a729bf4d4425fe192972',
108 'info_dict': {
109 'id': '21039',
110 'ext': 'mov',
111 'title': 'TRAILER: «SWEATSHOP» - I can´t take any more',
112 'description': 'md5:21891f2b0dd7ec2f78d84a50e54f8238',
113 'duration': 66,
114 'timestamp': 1417002452,
115 'upload_date': '20141126',
116 'view_count': int,
117 }
118 },
119 {
120 'url': 'http://www.bt.no/tv/#!/video/100250/norling-dette-er-forskjellen-paa-1-divisjon-og-eliteserien',
121 'only_matching': True,
122 },
123 ]
124
125 def _real_extract(self, url):
126 mobj = re.match(self._VALID_URL, url)
127 video_id = mobj.group('id')
128 host = mobj.group('host')
129 appname = self._HOST_TO_APPNAME[host] if host else mobj.group('appname')
130 vendor = self._APP_NAME_TO_VENDOR[appname]
131
132 data = self._download_json(
133 'http://svp.vg.no/svp/api/v1/%s/assets/%s?appName=%s-website'
134 % (vendor, video_id, appname),
135 video_id, 'Downloading media JSON')
136
137 if data.get('status') == 'inactive':
138 raise ExtractorError(
139 'Video %s is no longer available' % video_id, expected=True)
140
141 info = {
142 'formats': [],
143 }
144 if len(video_id) == 5:
145 if appname == 'bttv':
146 info = self._extract_video_info('btno', video_id)
147 elif appname == 'aptv':
148 info = self._extract_video_info('ap', video_id)
149
150 streams = data['streamUrls']
151 stream_type = data.get('streamType')
152
153 formats = []
154
155 hls_url = streams.get('hls')
156 if hls_url:
157 formats.extend(self._extract_m3u8_formats(
158 hls_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
159
160 hds_url = streams.get('hds')
161 if hds_url:
162 hdcore_sign = 'hdcore=3.7.0'
163 f4m_formats = self._extract_f4m_formats(
164 hds_url + '?%s' % hdcore_sign, video_id, f4m_id='hds', fatal=False)
165 if f4m_formats:
166 for entry in f4m_formats:
167 # URLs without the extra param induce an 404 error
168 entry.update({'extra_param_to_segment_url': hdcore_sign})
169 formats.append(entry)
170
171 mp4_urls = streams.get('pseudostreaming') or []
172 mp4_url = streams.get('mp4')
173 if mp4_url:
174 mp4_urls.append(mp4_url)
175 for mp4_url in mp4_urls:
176 format_info = {
177 'url': mp4_url,
178 }
179 mobj = re.search('(\d+)_(\d+)_(\d+)', mp4_url)
180 if mobj:
181 tbr = int(mobj.group(3))
182 format_info.update({
183 'width': int(mobj.group(1)),
184 'height': int(mobj.group(2)),
185 'tbr': tbr,
186 'format_id': 'mp4-%s' % tbr,
187 })
188 formats.append(format_info)
189
190 info['formats'].extend(formats)
191
192 self._sort_formats(info['formats'])
193
194 info.update({
195 'id': video_id,
196 'title': self._live_title(data['title']) if stream_type == 'live' else data['title'],
197 'description': data['description'],
198 'thumbnail': data['images']['main'] + '?t[]=900x506q80',
199 'timestamp': data['published'],
200 'duration': float_or_none(data['duration'], 1000),
201 'view_count': data['displays'],
202 'is_live': True if stream_type == 'live' else False,
203 })
204 return info
205
206
207 class BTArticleIE(InfoExtractor):
208 IE_NAME = 'bt:article'
209 IE_DESC = 'Bergens Tidende Articles'
210 _VALID_URL = 'http://(?:www\.)?bt\.no/(?:[^/]+/)+(?P<id>[^/]+)-\d+\.html'
211 _TEST = {
212 'url': 'http://www.bt.no/nyheter/lokalt/Kjemper-for-internatet-1788214.html',
213 'md5': '2acbe8ad129b3469d5ae51b1158878df',
214 'info_dict': {
215 'id': '23199',
216 'ext': 'mp4',
217 'title': 'Alrekstad internat',
218 'description': 'md5:dc81a9056c874fedb62fc48a300dac58',
219 'thumbnail': 're:^https?://.*\.jpg',
220 'duration': 191,
221 'timestamp': 1289991323,
222 'upload_date': '20101117',
223 'view_count': int,
224 },
225 }
226
227 def _real_extract(self, url):
228 webpage = self._download_webpage(url, self._match_id(url))
229 video_id = self._search_regex(
230 r'<video[^>]+data-id="(\d+)"', webpage, 'video id')
231 return self.url_result('bttv:%s' % video_id, 'VGTV')
232
233
234 class BTVestlendingenIE(InfoExtractor):
235 IE_NAME = 'bt:vestlendingen'
236 IE_DESC = 'Bergens Tidende - Vestlendingen'
237 _VALID_URL = 'http://(?:www\.)?bt\.no/spesial/vestlendingen/#!/(?P<id>\d+)'
238 _TESTS = [{
239 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86588',
240 'md5': 'd7d17e3337dc80de6d3a540aefbe441b',
241 'info_dict': {
242 'id': '86588',
243 'ext': 'mov',
244 'title': 'Otto Wollertsen',
245 'description': 'Vestlendingen Otto Fredrik Wollertsen',
246 'timestamp': 1430473209,
247 'upload_date': '20150501',
248 },
249 'skip': '404 Error',
250 }, {
251 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86255',
252 'md5': 'a2893f8632e96389f4bdf36aa9463ceb',
253 'info_dict': {
254 'id': '86255',
255 'ext': 'mov',
256 'title': 'Du må tåle å fryse og være sulten',
257 'description': 'md5:b8046f4d022d5830ddab04865791d063',
258 'upload_date': '20150321',
259 'timestamp': 1426942023,
260 },
261 }]
262
263 def _real_extract(self, url):
264 return self.url_result('bttv:%s' % self._match_id(url), 'VGTV')