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