]>
Commit | Line | Data |
---|---|---|
1 | # coding: utf-8 | |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..compat import compat_str | |
8 | from ..utils import ( | |
9 | float_or_none, | |
10 | int_or_none, | |
11 | clean_html, | |
12 | ) | |
13 | ||
14 | ||
15 | class DBTVIE(InfoExtractor): | |
16 | _VALID_URL = r'http://dbtv\.no/(?P<id>[0-9]+)#(?P<display_id>.+)' | |
17 | _TEST = { | |
18 | 'url': 'http://dbtv.no/3649835190001#Skulle_teste_ut_fornøyelsespark,_men_kollegaen_var_bare_opptatt_av_bikinikroppen', | |
19 | 'md5': 'b89953ed25dacb6edb3ef6c6f430f8bc', | |
20 | 'info_dict': { | |
21 | 'id': '33100', | |
22 | 'display_id': 'Skulle_teste_ut_fornøyelsespark,_men_kollegaen_var_bare_opptatt_av_bikinikroppen', | |
23 | 'ext': 'mp4', | |
24 | 'title': 'Skulle teste ut fornøyelsespark, men kollegaen var bare opptatt av bikinikroppen', | |
25 | 'description': 'md5:1504a54606c4dde3e4e61fc97aa857e0', | |
26 | 'thumbnail': 're:https?://.*\.jpg$', | |
27 | 'timestamp': 1404039863.438, | |
28 | 'upload_date': '20140629', | |
29 | 'duration': 69.544, | |
30 | 'view_count': int, | |
31 | 'categories': list, | |
32 | } | |
33 | } | |
34 | ||
35 | def _real_extract(self, url): | |
36 | mobj = re.match(self._VALID_URL, url) | |
37 | video_id = mobj.group('id') | |
38 | display_id = mobj.group('display_id') | |
39 | ||
40 | data = self._download_json( | |
41 | 'http://api.dbtv.no/discovery/%s' % video_id, display_id) | |
42 | ||
43 | video = data['playlist'][0] | |
44 | ||
45 | formats = [{ | |
46 | 'url': f['URL'], | |
47 | 'vcodec': f.get('container'), | |
48 | 'width': int_or_none(f.get('width')), | |
49 | 'height': int_or_none(f.get('height')), | |
50 | 'vbr': float_or_none(f.get('rate'), 1000), | |
51 | 'filesize': int_or_none(f.get('size')), | |
52 | } for f in video['renditions'] if 'URL' in f] | |
53 | ||
54 | if not formats: | |
55 | for url_key, format_id in [('URL', 'mp4'), ('HLSURL', 'hls')]: | |
56 | if url_key in video: | |
57 | formats.append({ | |
58 | 'url': video[url_key], | |
59 | 'format_id': format_id, | |
60 | }) | |
61 | ||
62 | self._sort_formats(formats) | |
63 | ||
64 | return { | |
65 | 'id': compat_str(video['id']), | |
66 | 'display_id': display_id, | |
67 | 'title': video['title'], | |
68 | 'description': clean_html(video['desc']), | |
69 | 'thumbnail': video.get('splash') or video.get('thumb'), | |
70 | 'timestamp': float_or_none(video.get('publishedAt'), 1000), | |
71 | 'duration': float_or_none(video.get('length'), 1000), | |
72 | 'view_count': int_or_none(video.get('views')), | |
73 | 'categories': video.get('tags'), | |
74 | 'formats': formats, | |
75 | } |