2 from __future__ import unicode_literals
6 from .common import InfoExtractor
12 class VGTVIE(InfoExtractor):
13 # Because of the #! in the URL structure we need to add ' before and after given URL.
14 # Or else it will cry: -bash: !/video/100495/lars-og-lars-sesong-6-episode-6-lakselus: event not found
15 _VALID_URL = r'http://(?:www\.)?vgtv\.no/#!/(?:.*)/(?P<id>[0-9]+)/(?P<title>[^?#]*)'
17 'url': 'http://www.vgtv.no/#!/video/84196/hevnen-er-soet-episode-10-abu',
18 'md5': 'b8be7a234cebb840c0d512c78013e02f',
22 'title': 'Hevnen er søt episode 10: Abu',
23 'description': 'md5:e25e4badb5f544b04341e14abdc72234',
24 'timestamp': 1404626400,
25 'upload_date': '20140706'
29 def _real_extract(self, url):
30 mobj = re.match(self._VALID_URL, url)
31 video_id = mobj.group('id')
33 # Download JSON file containing video info.
34 data = self._download_json('http://svp.vg.no/svp/api/v1/vgtv/assets/%s?appName=vgtv-website' % video_id, video_id, 'Downloading media JSON')
36 # Known streamType: vod, live, wasLive
37 # Will it even be possible to add support for live streams?
38 if data['streamType'] != 'vod':
39 raise ExtractorError('Stream type \'%s\' is not yet supported.' % data['streamType'], expected=True)
41 # Add access token to image or it will fail.
42 thumbnail = data['images']['main'] + '?t[]=900x506q80'
46 # Most videos are in MP4, but some are either HLS or HDS.
47 # Don't want to support HDS.
48 if data['streamUrls']['mp4'] is not None:
50 'url': data['streamUrls']['mp4'],
54 elif data['streamUrls']['hls'] is not None:
55 self.to_screen(u'No MP4 URL found, using m3u8. This may take some extra time.')
57 'url': data['streamUrls']['hls'],
62 raise ExtractorError('No download URL found for video: %s.' % video_id, expected=True)
66 'title': data['title'],
67 'description': data['description'],
68 'thumbnail': thumbnail,
69 'timestamp': data['published'],
70 'duration': data['duration'],
71 'view_count': data['displays'],