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