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