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