2 from __future__ import unicode_literals
6 from .common import InfoExtractor
12 class DBTVIE(InfoExtractor):
13 _VALID_URL = r'http://dbtv.no/(?P<id>[0-9]+)/?(?P<slug>.*)$'
15 'url': 'http://dbtv.no/3649835190001#Skulle_teste_ut_fornøyelsespark,_men_kollegaen_var_bare_opptatt_av_bikinikroppen',
16 'md5': 'b89953ed25dacb6edb3ef6c6f430f8bc',
18 'id': '3649835190001',
20 'title': 'Skulle teste ut fornøyelsespark, men kollegaen var bare opptatt av bikinikroppen',
21 'description': 'md5:d681bf2bb7dd3503892cedb9c2d0e6f2',
22 'thumbnail': 'http://gfx.dbtv.no/thumbs/still/33100.jpg',
23 'timestamp': 1404039863,
24 'upload_date': '20140629',
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://api.dbtv.no/discovery/%s' % video_id, video_id, 'Downloading media JSON')
35 # We only want the first video in the JSON API file.
36 video = data['playlist'][0]
38 # Check for full HD video, else use the standard video URL
39 for i in range(0, len(video['renditions'])):
40 if int(video['renditions'][i]['width']) == 1280:
41 video_url = video['renditions'][i]['URL']
44 video_url = video['URL']
46 # Add access token to image or it will fail.
47 thumbnail = video['splash']
50 duration = int(video['length'])
52 # Timestamp is given in milliseconds.
53 timestamp = float(str(video['publishedAt'])[0:-3])
58 if video['URL'] is not None:
65 raise ExtractorError('No download URL found for video: %s.' % video_id, expected=True)
69 'title': video['title'],
70 'description': video['desc'],
71 'thumbnail': thumbnail,
72 'timestamp': timestamp,
74 'view_count': video['views'],