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