]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/vgtv.py
[YoutubeDL] Make sure all formats have unique format_id
[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
4d454c5e
S
7from ..utils import (
8 ExtractorError,
9 float_or_none,
10)
78149a96 11
78149a96
MK
12
13class VGTVIE(InfoExtractor):
34e7dc81 14 IE_DESC = 'VGTV and BTTV'
0ceab847
S
15 _VALID_URL = r'''(?x)
16 (?:
17 vgtv:|
18 http://(?:www\.)?
19 )
20 (?P<host>vgtv|bt)
21 (?:
22 :|
5c0b2c16 23 \.no/(?:tv/)?\#!/(?:video|live)/
0ceab847
S
24 )
25 (?P<id>[0-9]+)
26 '''
321c1e44
S
27 _TESTS = [
28 {
29 # streamType: vod
30 'url': 'http://www.vgtv.no/#!/video/84196/hevnen-er-soet-episode-10-abu',
31 'md5': 'b8be7a234cebb840c0d512c78013e02f',
32 'info_dict': {
33 'id': '84196',
34 'ext': 'mp4',
eecd6a46 35 'title': 'Hevnen er søt: Episode 10 - Abu',
321c1e44
S
36 'description': 'md5:e25e4badb5f544b04341e14abdc72234',
37 'thumbnail': 're:^https?://.*\.jpg',
38 'duration': 648.000,
39 'timestamp': 1404626400,
3fbeb95e
S
40 'upload_date': '20140706',
41 'view_count': int,
321c1e44
S
42 },
43 },
44 {
45 # streamType: wasLive
46 'url': 'http://www.vgtv.no/#!/live/100764/opptak-vgtv-foelger-em-kvalifiseringen',
47 'info_dict': {
48 'id': '100764',
b7bb0df2 49 'ext': 'flv',
321c1e44
S
50 'title': 'OPPTAK: VGTV følger EM-kvalifiseringen',
51 'description': 'md5:3772d9c0dc2dff92a886b60039a7d4d3',
52 'thumbnail': 're:^https?://.*\.jpg',
eecd6a46 53 'duration': 9103.0,
321c1e44 54 'timestamp': 1410113864,
3fbeb95e
S
55 'upload_date': '20140907',
56 'view_count': int,
321c1e44
S
57 },
58 'params': {
59 # m3u8 download
60 'skip_download': True,
61 },
62 },
63 {
64 # streamType: live
65 'url': 'http://www.vgtv.no/#!/live/100015/direkte-her-kan-du-se-laksen-live-fra-suldalslaagen',
66 'info_dict': {
67 'id': '100015',
b7bb0df2 68 'ext': 'flv',
321c1e44
S
69 'title': 'DIREKTE: Her kan du se laksen live fra Suldalslågen!',
70 'description': 'md5:9a60cc23fa349f761628924e56eeec2d',
71 'thumbnail': 're:^https?://.*\.jpg',
72 'duration': 0,
73 'timestamp': 1407423348,
3fbeb95e
S
74 'upload_date': '20140807',
75 'view_count': int,
321c1e44
S
76 },
77 'params': {
78 # m3u8 download
79 'skip_download': True,
80 },
81 },
34e7dc81
S
82 {
83 'url': 'http://www.bt.no/tv/#!/video/100250/norling-dette-er-forskjellen-paa-1-divisjon-og-eliteserien',
84 'only_matching': True,
85 },
321c1e44 86 ]
78149a96 87
321c1e44 88 def _real_extract(self, url):
34e7dc81
S
89 mobj = re.match(self._VALID_URL, url)
90 video_id = mobj.group('id')
91 host = mobj.group('host')
92
93 HOST_WEBSITES = {
94 'vgtv': 'vgtv',
95 'bt': 'bttv',
96 }
97
321c1e44 98 data = self._download_json(
34e7dc81
S
99 'http://svp.vg.no/svp/api/v1/%s/assets/%s?appName=%s-website'
100 % (host, video_id, HOST_WEBSITES[host]),
321c1e44 101 video_id, 'Downloading media JSON')
78149a96 102
4d454c5e
S
103 if data.get('status') == 'inactive':
104 raise ExtractorError(
105 'Video %s is no longer available' % video_id, expected=True)
106
321c1e44 107 streams = data['streamUrls']
78149a96 108
321c1e44 109 formats = []
78149a96 110
321c1e44
S
111 hls_url = streams.get('hls')
112 if hls_url:
f2e00565
S
113 formats.extend(self._extract_m3u8_formats(
114 hls_url, video_id, 'mp4', m3u8_id='hls'))
78149a96 115
321c1e44 116 hds_url = streams.get('hds')
5c2191a6
S
117 # wasLive hds are always 404
118 if hds_url and data.get('streamType') != 'wasLive':
f2e00565
S
119 formats.extend(self._extract_f4m_formats(
120 hds_url + '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18',
121 video_id, f4m_id='hds'))
78149a96 122
321c1e44
S
123 mp4_url = streams.get('mp4')
124 if mp4_url:
125 _url = hls_url or hds_url
126 MP4_URL_TEMPLATE = '%s/%%s.%s' % (mp4_url.rpartition('/')[0], mp4_url.rpartition('.')[-1])
127 for mp4_format in _url.split(','):
128 m = re.search('(?P<width>\d+)_(?P<height>\d+)_(?P<vbr>\d+)', mp4_format)
129 if not m:
130 continue
131 width = int(m.group('width'))
132 height = int(m.group('height'))
133 vbr = int(m.group('vbr'))
134 formats.append({
135 'url': MP4_URL_TEMPLATE % mp4_format,
136 'format_id': 'mp4-%s' % vbr,
137 'width': width,
138 'height': height,
139 'vbr': vbr,
140 'preference': 1,
141 })
142 self._sort_formats(formats)
143
144 return {
145 'id': video_id,
146 'title': data['title'],
147 'description': data['description'],
148 'thumbnail': data['images']['main'] + '?t[]=900x506q80',
149 'timestamp': data['published'],
150 'duration': float_or_none(data['duration'], 1000),
151 'view_count': data['displays'],
152 'formats': formats,
5f6a1245 153 }
0ceab847
S
154
155
156class BTArticleIE(InfoExtractor):
fe373287
S
157 IE_NAME = 'bt:article'
158 IE_DESC = 'Bergens Tidende Articles'
0ceab847
S
159 _VALID_URL = 'http://(?:www\.)?bt\.no/(?:[^/]+/)+(?P<id>[^/]+)-\d+\.html'
160 _TEST = {
161 'url': 'http://www.bt.no/nyheter/lokalt/Kjemper-for-internatet-1788214.html',
162 'md5': 'd055e8ee918ef2844745fcfd1a4175fb',
163 'info_dict': {
164 'id': '23199',
165 'ext': 'mp4',
166 'title': 'Alrekstad internat',
167 'description': 'md5:dc81a9056c874fedb62fc48a300dac58',
168 'thumbnail': 're:^https?://.*\.jpg',
169 'duration': 191,
170 'timestamp': 1289991323,
171 'upload_date': '20101117',
172 'view_count': int,
173 },
174 }
175
176 def _real_extract(self, url):
177 webpage = self._download_webpage(url, self._match_id(url))
178 video_id = self._search_regex(
179 r'SVP\.Player\.load\(\s*(\d+)', webpage, 'video id')
180 return self.url_result('vgtv:bt:%s' % video_id, 'VGTV')
fe373287
S
181
182
183class BTVestlendingenIE(InfoExtractor):
184 IE_NAME = 'bt:vestlendingen'
185 IE_DESC = 'Bergens Tidende - Vestlendingen'
186 _VALID_URL = 'http://(?:www\.)?bt\.no/spesial/vestlendingen/#!/(?P<id>\d+)'
187 _TEST = {
188 'url': 'http://www.bt.no/spesial/vestlendingen/#!/86588',
189 'md5': 'd7d17e3337dc80de6d3a540aefbe441b',
190 'info_dict': {
191 'id': '86588',
192 'ext': 'mov',
193 'title': 'Otto Wollertsen',
194 'description': 'Vestlendingen Otto Fredrik Wollertsen',
195 'timestamp': 1430473209,
196 'upload_date': '20150501',
197 },
198 }
199
200 def _real_extract(self, url):
201 return self.url_result('xstream:btno:%s' % self._match_id(url), 'Xstream')