]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/drtv.py
debian/control: Add recommends on aria2 | wget | curl to use external downloaders.
[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 webpage = self._download_webpage(url, video_id)
29
30 video_id = self._search_regex(
31 r'data-(?:material-identifier|episode-slug)="([^"]+)"',
32 webpage, 'video id')
33
34 programcard = self._download_json(
35 'http://www.dr.dk/mu/programcard/expanded/%s' % video_id,
36 video_id, 'Downloading video JSON')
37 data = programcard['Data'][0]
38
39 title = data['Title']
40 description = data['Description']
41 timestamp = parse_iso8601(data['CreatedTime'])
42
43 thumbnail = None
44 duration = None
45
46 restricted_to_denmark = False
47
48 formats = []
49 subtitles = {}
50
51 for asset in data['Assets']:
52 if asset['Kind'] == 'Image':
53 thumbnail = asset['Uri']
54 elif asset['Kind'] == 'VideoResource':
55 duration = asset['DurationInMilliseconds'] / 1000.0
56 restricted_to_denmark = asset['RestrictedToDenmark']
57 spoken_subtitles = asset['Target'] == 'SpokenSubtitles'
58 for link in asset['Links']:
59 target = link['Target']
60 uri = link['Uri']
61 format_id = target
62 preference = -1 if target == 'HDS' else -2
63 if spoken_subtitles:
64 preference -= 2
65 format_id += '-spoken-subtitles'
66 formats.append({
67 'url': uri + '?hdcore=3.3.0&plugin=aasp-3.3.0.99.43' if target == 'HDS' else uri,
68 'format_id': format_id,
69 'ext': link['FileFormat'],
70 'preference': preference,
71 })
72 subtitles_list = asset.get('SubtitlesList')
73 if isinstance(subtitles_list, list):
74 LANGS = {
75 'Danish': 'dk',
76 }
77 for subs in subtitles_list:
78 lang = subs['Language']
79 subtitles[LANGS.get(lang, lang)] = subs['Uri']
80
81 if not formats and restricted_to_denmark:
82 raise ExtractorError(
83 'Unfortunately, DR is not allowed to show this program outside Denmark.', expected=True)
84
85 self._sort_formats(formats)
86
87 if self._downloader.params.get('listsubtitles', False):
88 self._list_available_subtitles(video_id, subtitles)
89 return
90
91 return {
92 'id': video_id,
93 'title': title,
94 'description': description,
95 'thumbnail': thumbnail,
96 'timestamp': timestamp,
97 'duration': duration,
98 'formats': formats,
99 'subtitles': self.extract_subtitles(video_id, subtitles),
100 }