]>
Commit | Line | Data |
---|---|---|
940b606a | 1 | # coding: utf-8 |
4cd759f7 JMF |
2 | from __future__ import unicode_literals |
3 | ||
940b606a S |
4 | import json |
5 | import re | |
4cd759f7 JMF |
6 | import time |
7 | ||
8 | from .common import InfoExtractor | |
5448b781 S |
9 | from ..compat import compat_urlparse |
10 | from ..utils import ( | |
11 | int_or_none, | |
12 | update_url_query, | |
13 | ) | |
940b606a | 14 | |
4cd759f7 JMF |
15 | |
16 | class DPlayIE(InfoExtractor): | |
5886b38d | 17 | _VALID_URL = r'https?://(?P<domain>it\.dplay\.com|www\.dplay\.(?:dk|se|no))/[^/]+/(?P<id>[^/?#]+)' |
95050537 | 18 | |
940b606a | 19 | _TESTS = [{ |
fd0ff8ba | 20 | # geo restricted, via direct unsigned hls URL |
940b606a S |
21 | 'url': 'http://it.dplay.com/take-me-out/stagione-1-episodio-25/', |
22 | 'info_dict': { | |
23 | 'id': '1255600', | |
24 | 'display_id': 'stagione-1-episodio-25', | |
25 | 'ext': 'mp4', | |
26 | 'title': 'Episodio 25', | |
27 | 'description': 'md5:cae5f40ad988811b197d2d27a53227eb', | |
28 | 'duration': 2761, | |
29 | 'timestamp': 1454701800, | |
30 | 'upload_date': '20160205', | |
31 | 'creator': 'RTIT', | |
32 | 'series': 'Take me out', | |
33 | 'season_number': 1, | |
34 | 'episode_number': 25, | |
35 | 'age_limit': 0, | |
4cd759f7 | 36 | }, |
940b606a S |
37 | 'expected_warnings': ['Unable to download f4m manifest'], |
38 | }, { | |
5448b781 | 39 | # non geo restricted, via secure api, unsigned download hls URL |
940b606a S |
40 | 'url': 'http://www.dplay.se/nugammalt-77-handelser-som-format-sverige/season-1-svensken-lar-sig-njuta-av-livet/', |
41 | 'info_dict': { | |
42 | 'id': '3172', | |
43 | 'display_id': 'season-1-svensken-lar-sig-njuta-av-livet', | |
5448b781 | 44 | 'ext': 'mp4', |
940b606a S |
45 | 'title': 'Svensken lär sig njuta av livet', |
46 | 'description': 'md5:d3819c9bccffd0fe458ca42451dd50d8', | |
47 | 'duration': 2650, | |
48 | 'timestamp': 1365454320, | |
49 | 'upload_date': '20130408', | |
50 | 'creator': 'Kanal 5 (Home)', | |
51 | 'series': 'Nugammalt - 77 händelser som format Sverige', | |
52 | 'season_number': 1, | |
53 | 'episode_number': 1, | |
54 | 'age_limit': 0, | |
95050537 | 55 | }, |
940b606a | 56 | }, { |
5448b781 | 57 | # geo restricted, via secure api, unsigned download hls URL |
940b606a S |
58 | 'url': 'http://www.dplay.dk/mig-og-min-mor/season-6-episode-12/', |
59 | 'info_dict': { | |
60 | 'id': '70816', | |
61 | 'display_id': 'season-6-episode-12', | |
5448b781 | 62 | 'ext': 'mp4', |
940b606a S |
63 | 'title': 'Episode 12', |
64 | 'description': 'md5:9c86e51a93f8a4401fc9641ef9894c90', | |
65 | 'duration': 2563, | |
66 | 'timestamp': 1429696800, | |
67 | 'upload_date': '20150422', | |
5448b781 | 68 | 'creator': 'Kanal 4 (Home)', |
940b606a S |
69 | 'series': 'Mig og min mor', |
70 | 'season_number': 6, | |
71 | 'episode_number': 12, | |
72 | 'age_limit': 0, | |
73 | }, | |
5add979d | 74 | }, { |
fd0ff8ba | 75 | # geo restricted, via direct unsigned hls URL |
5add979d S |
76 | 'url': 'http://www.dplay.no/pga-tour/season-1-hoydepunkter-18-21-februar/', |
77 | 'only_matching': True, | |
940b606a | 78 | }] |
4cd759f7 JMF |
79 | |
80 | def _real_extract(self, url): | |
940b606a S |
81 | mobj = re.match(self._VALID_URL, url) |
82 | display_id = mobj.group('id') | |
83 | domain = mobj.group('domain') | |
84 | ||
4cd759f7 | 85 | webpage = self._download_webpage(url, display_id) |
4cd759f7 | 86 | |
940b606a S |
87 | video_id = self._search_regex( |
88 | r'data-video-id=["\'](\d+)', webpage, 'video id') | |
95050537 | 89 | |
940b606a S |
90 | info = self._download_json( |
91 | 'http://%s/api/v2/ajax/videos?video_id=%s' % (domain, video_id), | |
4cd759f7 JMF |
92 | video_id)['data'][0] |
93 | ||
940b606a | 94 | title = info['title'] |
95050537 | 95 | |
940b606a S |
96 | PROTOCOLS = ('hls', 'hds') |
97 | formats = [] | |
95050537 | 98 | |
940b606a S |
99 | def extract_formats(protocol, manifest_url): |
100 | if protocol == 'hls': | |
5448b781 | 101 | m3u8_formats = self._extract_m3u8_formats( |
940b606a | 102 | manifest_url, video_id, ext='mp4', |
5448b781 S |
103 | entry_protocol='m3u8_native', m3u8_id=protocol, fatal=False) |
104 | # Sometimes final URLs inside m3u8 are unsigned, let's fix this | |
105 | # ourselves | |
106 | query = compat_urlparse.parse_qs(compat_urlparse.urlparse(manifest_url).query) | |
107 | for m3u8_format in m3u8_formats: | |
108 | m3u8_format['url'] = update_url_query(m3u8_format['url'], query) | |
109 | formats.extend(m3u8_formats) | |
940b606a S |
110 | elif protocol == 'hds': |
111 | formats.extend(self._extract_f4m_formats( | |
112 | manifest_url + '&hdcore=3.8.0&plugin=flowplayer-3.8.0.0', | |
113 | video_id, f4m_id=protocol, fatal=False)) | |
114 | ||
115 | domain_tld = domain.split('.')[-1] | |
397ec446 | 116 | if domain_tld in ('se', 'dk', 'no'): |
940b606a | 117 | for protocol in PROTOCOLS: |
fd0ff8ba | 118 | # Providing dsc-geo allows to bypass geo restriction in some cases |
940b606a S |
119 | self._set_cookie( |
120 | 'secure.dplay.%s' % domain_tld, 'dsc-geo', | |
121 | json.dumps({ | |
122 | 'countryCode': domain_tld.upper(), | |
123 | 'expiry': (time.time() + 20 * 60) * 1000, | |
124 | })) | |
125 | stream = self._download_json( | |
126 | 'https://secure.dplay.%s/secure/api/v2/user/authorization/stream/%s?stream_type=%s' | |
127 | % (domain_tld, video_id, protocol), video_id, | |
128 | 'Downloading %s stream JSON' % protocol, fatal=False) | |
129 | if stream and stream.get(protocol): | |
130 | extract_formats(protocol, stream[protocol]) | |
fd0ff8ba S |
131 | |
132 | # The last resort is to try direct unsigned hls/hds URLs from info dictionary. | |
133 | # Sometimes this does work even when secure API with dsc-geo has failed (e.g. | |
134 | # http://www.dplay.no/pga-tour/season-1-hoydepunkter-18-21-februar/). | |
135 | if not formats: | |
940b606a S |
136 | for protocol in PROTOCOLS: |
137 | if info.get(protocol): | |
138 | extract_formats(protocol, info[protocol]) | |
4cd759f7 | 139 | |
19dbaeec S |
140 | self._sort_formats(formats) |
141 | ||
e239413f S |
142 | subtitles = {} |
143 | for lang in ('se', 'sv', 'da', 'nl', 'no'): | |
144 | for format_id in ('web_vtt', 'vtt', 'srt'): | |
145 | subtitle_url = info.get('subtitles_%s_%s' % (lang, format_id)) | |
146 | if subtitle_url: | |
147 | subtitles.setdefault(lang, []).append({'url': subtitle_url}) | |
148 | ||
4cd759f7 JMF |
149 | return { |
150 | 'id': video_id, | |
151 | 'display_id': display_id, | |
940b606a | 152 | 'title': title, |
95050537 | 153 | 'description': info.get('video_metadata_longDescription'), |
940b606a S |
154 | 'duration': int_or_none(info.get('video_metadata_length'), scale=1000), |
155 | 'timestamp': int_or_none(info.get('video_publish_date')), | |
156 | 'creator': info.get('video_metadata_homeChannel'), | |
157 | 'series': info.get('video_metadata_show'), | |
95050537 AR |
158 | 'season_number': int_or_none(info.get('season')), |
159 | 'episode_number': int_or_none(info.get('episode')), | |
940b606a S |
160 | 'age_limit': int_or_none(info.get('minimum_age')), |
161 | 'formats': formats, | |
e239413f | 162 | 'subtitles': subtitles, |
4cd759f7 | 163 | } |