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