]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/drtv.py
c44adb1099bf6f0a2d08ccad7cebebef3939ddf9
[youtubedl] / youtube_dl / extractor / drtv.py
1 from __future__ import unicode_literals
2
3 from .subtitles import SubtitlesInfoExtractor
4 from .common import ExtractorError
5 from ..utils import parse_iso8601
6
7
8 class DRTVIE(SubtitlesInfoExtractor):
9 _VALID_URL = r'https?://(?:www\.)?dr\.dk/tv/se/(?:[^/]+/)+(?P<id>[\da-z-]+)(?:[/#?]|$)'
10
11 _TEST = {
12 'url': 'http://www.dr.dk/tv/se/partiets-mand/partiets-mand-7-8',
13 'md5': '4a7e1dd65cdb2643500a3f753c942f25',
14 'info_dict': {
15 'id': 'partiets-mand-7-8',
16 'ext': 'mp4',
17 'title': 'Partiets mand (7:8)',
18 'description': 'md5:a684b90a8f9336cd4aab94b7647d7862',
19 'timestamp': 1403047940,
20 'upload_date': '20140617',
21 'duration': 1299.040,
22 },
23 }
24
25 def _real_extract(self, url):
26 video_id = self._match_id(url)
27
28 programcard = self._download_json(
29 'http://www.dr.dk/mu/programcard/expanded/%s' % video_id, video_id, 'Downloading video JSON')
30
31 data = programcard['Data'][0]
32
33 title = data['Title']
34 description = data['Description']
35 timestamp = parse_iso8601(data['CreatedTime'])
36
37 thumbnail = None
38 duration = None
39
40 restricted_to_denmark = False
41
42 formats = []
43 subtitles = {}
44
45 for asset in data['Assets']:
46 if asset['Kind'] == 'Image':
47 thumbnail = asset['Uri']
48 elif asset['Kind'] == 'VideoResource':
49 duration = asset['DurationInMilliseconds'] / 1000.0
50 restricted_to_denmark = asset['RestrictedToDenmark']
51 for link in asset['Links']:
52 target = link['Target']
53 uri = link['Uri']
54 formats.append({
55 'url': uri + '?hdcore=3.3.0&plugin=aasp-3.3.0.99.43' if target == 'HDS' else uri,
56 'format_id': target,
57 'ext': link['FileFormat'],
58 'preference': -1 if target == 'HDS' else -2,
59 })
60 subtitles_list = asset.get('SubtitlesList')
61 if isinstance(subtitles_list, list):
62 LANGS = {
63 'Danish': 'dk',
64 }
65 for subs in subtitles_list:
66 lang = subs['Language']
67 subtitles[LANGS.get(lang, lang)] = subs['Uri']
68
69 if not formats and restricted_to_denmark:
70 raise ExtractorError(
71 'Unfortunately, DR is not allowed to show this program outside Denmark.', expected=True)
72
73 self._sort_formats(formats)
74
75 if self._downloader.params.get('listsubtitles', False):
76 self._list_available_subtitles(video_id, subtitles)
77 return
78
79 return {
80 'id': video_id,
81 'title': title,
82 'description': description,
83 'thumbnail': thumbnail,
84 'timestamp': timestamp,
85 'duration': duration,
86 'formats': formats,
87 'subtitles': self.extract_subtitles(video_id, subtitles),
88 }