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