]>
Commit | Line | Data |
---|---|---|
7d254639 | 1 | # coding: utf-8 |
f2b8db57 S |
2 | from __future__ import unicode_literals |
3 | ||
1335c3ac S |
4 | from .common import InfoExtractor |
5 | from ..utils import ( | |
6 | ExtractorError, | |
7 | parse_iso8601, | |
8 | ) | |
f2b8db57 S |
9 | |
10 | ||
18c1c424 | 11 | class DRTVIE(InfoExtractor): |
ef1269fb | 12 | _VALID_URL = r'https?://(?:www\.)?dr\.dk/tv/se/(?:[^/]+/)*(?P<id>[\da-z-]+)(?:[/#?]|$)' |
f2b8db57 S |
13 | |
14 | _TEST = { | |
7d254639 S |
15 | 'url': 'https://www.dr.dk/tv/se/boern/ultra/panisk-paske/panisk-paske-5', |
16 | 'md5': 'dc515a9ab50577fa14cc4e4b0265168f', | |
f2b8db57 | 17 | 'info_dict': { |
7d254639 | 18 | 'id': 'panisk-paske-5', |
f2b8db57 | 19 | 'ext': 'mp4', |
7d254639 S |
20 | 'title': 'Panisk Påske (5)', |
21 | 'description': 'md5:ca14173c5ab24cd26b0fcc074dff391c', | |
22 | 'timestamp': 1426984612, | |
23 | 'upload_date': '20150322', | |
24 | 'duration': 1455, | |
f2b8db57 S |
25 | }, |
26 | } | |
27 | ||
28 | def _real_extract(self, url): | |
6ad4013d | 29 | video_id = self._match_id(url) |
f2b8db57 | 30 | |
78271e33 S |
31 | webpage = self._download_webpage(url, video_id) |
32 | ||
aff84bec S |
33 | if '>Programmet er ikke længere tilgængeligt' in webpage: |
34 | raise ExtractorError( | |
35 | 'Video %s is not available' % video_id, expected=True) | |
36 | ||
78271e33 S |
37 | video_id = self._search_regex( |
38 | r'data-(?:material-identifier|episode-slug)="([^"]+)"', | |
39 | webpage, 'video id') | |
f2b8db57 | 40 | |
78271e33 S |
41 | programcard = self._download_json( |
42 | 'http://www.dr.dk/mu/programcard/expanded/%s' % video_id, | |
43 | video_id, 'Downloading video JSON') | |
f2b8db57 S |
44 | data = programcard['Data'][0] |
45 | ||
46 | title = data['Title'] | |
47 | description = data['Description'] | |
6ad4013d | 48 | timestamp = parse_iso8601(data['CreatedTime']) |
f2b8db57 S |
49 | |
50 | thumbnail = None | |
51 | duration = None | |
52 | ||
53 | restricted_to_denmark = False | |
54 | ||
55 | formats = [] | |
56 | subtitles = {} | |
57 | ||
58 | for asset in data['Assets']: | |
59 | if asset['Kind'] == 'Image': | |
60 | thumbnail = asset['Uri'] | |
61 | elif asset['Kind'] == 'VideoResource': | |
62 | duration = asset['DurationInMilliseconds'] / 1000.0 | |
63 | restricted_to_denmark = asset['RestrictedToDenmark'] | |
6d2749aa | 64 | spoken_subtitles = asset['Target'] == 'SpokenSubtitles' |
f2b8db57 | 65 | for link in asset['Links']: |
f2b8db57 | 66 | uri = link['Uri'] |
1335c3ac | 67 | target = link['Target'] |
6d2749aa | 68 | format_id = target |
1335c3ac | 69 | preference = None |
6d2749aa | 70 | if spoken_subtitles: |
1335c3ac | 71 | preference = -1 |
6d2749aa | 72 | format_id += '-spoken-subtitles' |
1335c3ac S |
73 | if target == 'HDS': |
74 | formats.extend(self._extract_f4m_formats( | |
75 | uri + '?hdcore=3.3.0&plugin=aasp-3.3.0.99.43', | |
76 | video_id, preference, f4m_id=format_id)) | |
77 | elif target == 'HLS': | |
78 | formats.extend(self._extract_m3u8_formats( | |
79 | uri, video_id, 'mp4', preference=preference, | |
80 | m3u8_id=format_id)) | |
81 | else: | |
82 | bitrate = link.get('Bitrate') | |
83 | if bitrate: | |
84 | format_id += '-%s' % bitrate | |
85 | formats.append({ | |
86 | 'url': uri, | |
87 | 'format_id': format_id, | |
88 | 'tbr': bitrate, | |
89 | 'ext': link.get('FileFormat'), | |
90 | }) | |
f2b8db57 S |
91 | subtitles_list = asset.get('SubtitlesList') |
92 | if isinstance(subtitles_list, list): | |
93 | LANGS = { | |
6fa73386 | 94 | 'Danish': 'da', |
f2b8db57 S |
95 | } |
96 | for subs in subtitles_list: | |
97 | lang = subs['Language'] | |
18c1c424 | 98 | subtitles[LANGS.get(lang, lang)] = [{'url': subs['Uri'], 'ext': 'vtt'}] |
f2b8db57 S |
99 | |
100 | if not formats and restricted_to_denmark: | |
101 | raise ExtractorError( | |
102 | 'Unfortunately, DR is not allowed to show this program outside Denmark.', expected=True) | |
103 | ||
104 | self._sort_formats(formats) | |
105 | ||
f2b8db57 S |
106 | return { |
107 | 'id': video_id, | |
108 | 'title': title, | |
109 | 'description': description, | |
110 | 'thumbnail': thumbnail, | |
111 | 'timestamp': timestamp, | |
112 | 'duration': duration, | |
113 | 'formats': formats, | |
18c1c424 | 114 | 'subtitles': subtitles, |
f2b8db57 | 115 | } |