2 from __future__ import unicode_literals
8 from .common import InfoExtractor
9 from ..compat import compat_urlparse
16 class DPlayIE(InfoExtractor):
17 _VALID_URL = r'https?://(?P<domain>it\.dplay\.com|www\.dplay\.(?:dk|se|no))/[^/]+/(?P<id>[^/?#]+)'
20 # geo restricted, via direct unsigned hls URL
21 'url': 'http://it.dplay.com/take-me-out/stagione-1-episodio-25/',
24 'display_id': 'stagione-1-episodio-25',
26 'title': 'Episodio 25',
27 'description': 'md5:cae5f40ad988811b197d2d27a53227eb',
29 'timestamp': 1454701800,
30 'upload_date': '20160205',
32 'series': 'Take me out',
37 'expected_warnings': ['Unable to download f4m manifest'],
39 # non geo restricted, via secure api, unsigned download hls URL
40 'url': 'http://www.dplay.se/nugammalt-77-handelser-som-format-sverige/season-1-svensken-lar-sig-njuta-av-livet/',
43 'display_id': 'season-1-svensken-lar-sig-njuta-av-livet',
45 'title': 'Svensken lär sig njuta av livet',
46 'description': 'md5:d3819c9bccffd0fe458ca42451dd50d8',
48 'timestamp': 1365454320,
49 'upload_date': '20130408',
50 'creator': 'Kanal 5 (Home)',
51 'series': 'Nugammalt - 77 händelser som format Sverige',
57 # geo restricted, via secure api, unsigned download hls URL
58 'url': 'http://www.dplay.dk/mig-og-min-mor/season-6-episode-12/',
61 'display_id': 'season-6-episode-12',
63 'title': 'Episode 12',
64 'description': 'md5:9c86e51a93f8a4401fc9641ef9894c90',
66 'timestamp': 1429696800,
67 'upload_date': '20150422',
68 'creator': 'Kanal 4 (Home)',
69 'series': 'Mig og min mor',
75 # geo restricted, via direct unsigned hls URL
76 'url': 'http://www.dplay.no/pga-tour/season-1-hoydepunkter-18-21-februar/',
77 'only_matching': True,
80 def _real_extract(self, url):
81 mobj = re.match(self._VALID_URL, url)
82 display_id = mobj.group('id')
83 domain = mobj.group('domain')
85 webpage = self._download_webpage(url, display_id)
87 video_id = self._search_regex(
88 r'data-video-id=["\'](\d+)', webpage, 'video id')
90 info = self._download_json(
91 'http://%s/api/v2/ajax/videos?video_id=%s' % (domain, video_id),
96 PROTOCOLS = ('hls', 'hds')
99 def extract_formats(protocol, manifest_url):
100 if protocol == 'hls':
101 m3u8_formats = self._extract_m3u8_formats(
102 manifest_url, video_id, ext='mp4',
103 entry_protocol='m3u8_native', m3u8_id=protocol, fatal=False)
104 # Sometimes final URLs inside m3u8 are unsigned, let's fix this
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)
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))
115 domain_tld = domain.split('.')[-1]
116 if domain_tld in ('se', 'dk', 'no'):
117 for protocol in PROTOCOLS:
118 # Providing dsc-geo allows to bypass geo restriction in some cases
120 'secure.dplay.%s' % domain_tld, 'dsc-geo',
122 'countryCode': domain_tld.upper(),
123 'expiry': (time.time() + 20 * 60) * 1000,
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])
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/).
136 for protocol in PROTOCOLS:
137 if info.get(protocol):
138 extract_formats(protocol, info[protocol])
140 self._sort_formats(formats)
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))
147 subtitles.setdefault(lang, []).append({'url': subtitle_url})
151 'display_id': display_id,
153 'description': info.get('video_metadata_longDescription'),
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'),
158 'season_number': int_or_none(info.get('season')),
159 'episode_number': int_or_none(info.get('episode')),
160 'age_limit': int_or_none(info.get('minimum_age')),
162 'subtitles': subtitles,