]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/dplay.py
Add support for https for all extractors as preventive and future-proof measure
[yt-dlp.git] / youtube_dl / extractor / dplay.py
CommitLineData
940b606a 1# coding: utf-8
4cd759f7
JMF
2from __future__ import unicode_literals
3
940b606a
S
4import json
5import re
4cd759f7
JMF
6import time
7
8from .common import InfoExtractor
9from ..utils import int_or_none
940b606a 10
4cd759f7
JMF
11
12class DPlayIE(InfoExtractor):
5886b38d 13 _VALID_URL = r'https?://(?P<domain>it\.dplay\.com|www\.dplay\.(?:dk|se|no))/[^/]+/(?P<id>[^/?#]+)'
95050537 14
940b606a
S
15 _TESTS = [{
16 'url': 'http://it.dplay.com/take-me-out/stagione-1-episodio-25/',
17 'info_dict': {
18 'id': '1255600',
19 'display_id': 'stagione-1-episodio-25',
20 'ext': 'mp4',
21 'title': 'Episodio 25',
22 'description': 'md5:cae5f40ad988811b197d2d27a53227eb',
23 'duration': 2761,
24 'timestamp': 1454701800,
25 'upload_date': '20160205',
26 'creator': 'RTIT',
27 'series': 'Take me out',
28 'season_number': 1,
29 'episode_number': 25,
30 'age_limit': 0,
4cd759f7 31 },
940b606a
S
32 'expected_warnings': ['Unable to download f4m manifest'],
33 }, {
34 'url': 'http://www.dplay.se/nugammalt-77-handelser-som-format-sverige/season-1-svensken-lar-sig-njuta-av-livet/',
35 'info_dict': {
36 'id': '3172',
37 'display_id': 'season-1-svensken-lar-sig-njuta-av-livet',
38 'ext': 'flv',
39 'title': 'Svensken lär sig njuta av livet',
40 'description': 'md5:d3819c9bccffd0fe458ca42451dd50d8',
41 'duration': 2650,
42 'timestamp': 1365454320,
43 'upload_date': '20130408',
44 'creator': 'Kanal 5 (Home)',
45 'series': 'Nugammalt - 77 händelser som format Sverige',
46 'season_number': 1,
47 'episode_number': 1,
48 'age_limit': 0,
95050537 49 },
940b606a
S
50 }, {
51 'url': 'http://www.dplay.dk/mig-og-min-mor/season-6-episode-12/',
52 'info_dict': {
53 'id': '70816',
54 'display_id': 'season-6-episode-12',
55 'ext': 'flv',
56 'title': 'Episode 12',
57 'description': 'md5:9c86e51a93f8a4401fc9641ef9894c90',
58 'duration': 2563,
59 'timestamp': 1429696800,
60 'upload_date': '20150422',
61 'creator': 'Kanal 4',
62 'series': 'Mig og min mor',
63 'season_number': 6,
64 'episode_number': 12,
65 'age_limit': 0,
66 },
5add979d
S
67 }, {
68 'url': 'http://www.dplay.no/pga-tour/season-1-hoydepunkter-18-21-februar/',
69 'only_matching': True,
940b606a 70 }]
4cd759f7
JMF
71
72 def _real_extract(self, url):
940b606a
S
73 mobj = re.match(self._VALID_URL, url)
74 display_id = mobj.group('id')
75 domain = mobj.group('domain')
76
4cd759f7 77 webpage = self._download_webpage(url, display_id)
4cd759f7 78
940b606a
S
79 video_id = self._search_regex(
80 r'data-video-id=["\'](\d+)', webpage, 'video id')
95050537 81
940b606a
S
82 info = self._download_json(
83 'http://%s/api/v2/ajax/videos?video_id=%s' % (domain, video_id),
4cd759f7
JMF
84 video_id)['data'][0]
85
940b606a 86 title = info['title']
95050537 87
940b606a
S
88 PROTOCOLS = ('hls', 'hds')
89 formats = []
95050537 90
940b606a
S
91 def extract_formats(protocol, manifest_url):
92 if protocol == 'hls':
93 formats.extend(self._extract_m3u8_formats(
94 manifest_url, video_id, ext='mp4',
95 entry_protocol='m3u8_native', m3u8_id=protocol, fatal=False))
96 elif protocol == 'hds':
97 formats.extend(self._extract_f4m_formats(
98 manifest_url + '&hdcore=3.8.0&plugin=flowplayer-3.8.0.0',
99 video_id, f4m_id=protocol, fatal=False))
100
101 domain_tld = domain.split('.')[-1]
102 if domain_tld in ('se', 'dk'):
103 for protocol in PROTOCOLS:
104 self._set_cookie(
105 'secure.dplay.%s' % domain_tld, 'dsc-geo',
106 json.dumps({
107 'countryCode': domain_tld.upper(),
108 'expiry': (time.time() + 20 * 60) * 1000,
109 }))
110 stream = self._download_json(
111 'https://secure.dplay.%s/secure/api/v2/user/authorization/stream/%s?stream_type=%s'
112 % (domain_tld, video_id, protocol), video_id,
113 'Downloading %s stream JSON' % protocol, fatal=False)
114 if stream and stream.get(protocol):
115 extract_formats(protocol, stream[protocol])
116 else:
117 for protocol in PROTOCOLS:
118 if info.get(protocol):
119 extract_formats(protocol, info[protocol])
4cd759f7
JMF
120
121 return {
122 'id': video_id,
123 'display_id': display_id,
940b606a 124 'title': title,
95050537 125 'description': info.get('video_metadata_longDescription'),
940b606a
S
126 'duration': int_or_none(info.get('video_metadata_length'), scale=1000),
127 'timestamp': int_or_none(info.get('video_publish_date')),
128 'creator': info.get('video_metadata_homeChannel'),
129 'series': info.get('video_metadata_show'),
95050537
AR
130 'season_number': int_or_none(info.get('season')),
131 'episode_number': int_or_none(info.get('episode')),
940b606a
S
132 'age_limit': int_or_none(info.get('minimum_age')),
133 'formats': formats,
4cd759f7 134 }