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