]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/dplay.py
32028bc3b79b61d249ad4bccaebadf745f9f942a
2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
9 from ..compat
import compat_urlparse
17 class DPlayIE(InfoExtractor
):
18 _VALID_URL
= r
'https?://(?P<domain>it\.dplay\.com|www\.dplay\.(?:dk|se|no))/[^/]+/(?P<id>[^/?#]+)'
21 # geo restricted, via direct unsigned hls URL
22 'url': 'http://it.dplay.com/take-me-out/stagione-1-episodio-25/',
25 'display_id': 'stagione-1-episodio-25',
27 'title': 'Episodio 25',
28 'description': 'md5:cae5f40ad988811b197d2d27a53227eb',
30 'timestamp': 1454701800,
31 'upload_date': '20160205',
33 'series': 'Take me out',
38 'expected_warnings': ['Unable to download f4m manifest'],
40 # non geo restricted, via secure api, unsigned download hls URL
41 'url': 'http://www.dplay.se/nugammalt-77-handelser-som-format-sverige/season-1-svensken-lar-sig-njuta-av-livet/',
44 'display_id': 'season-1-svensken-lar-sig-njuta-av-livet',
46 'title': 'Svensken lär sig njuta av livet',
47 'description': 'md5:d3819c9bccffd0fe458ca42451dd50d8',
49 'timestamp': 1365454320,
50 'upload_date': '20130408',
51 'creator': 'Kanal 5 (Home)',
52 'series': 'Nugammalt - 77 händelser som format Sverige',
58 # geo restricted, via secure api, unsigned download hls URL
59 'url': 'http://www.dplay.dk/mig-og-min-mor/season-6-episode-12/',
62 'display_id': 'season-6-episode-12',
64 'title': 'Episode 12',
65 'description': 'md5:9c86e51a93f8a4401fc9641ef9894c90',
67 'timestamp': 1429696800,
68 'upload_date': '20150422',
69 'creator': 'Kanal 4 (Home)',
70 'series': 'Mig og min mor',
76 # geo restricted, via direct unsigned hls URL
77 'url': 'http://www.dplay.no/pga-tour/season-1-hoydepunkter-18-21-februar/',
78 'only_matching': True,
81 def _real_extract(self
, url
):
82 mobj
= re
.match(self
._VALID
_URL
, url
)
83 display_id
= mobj
.group('id')
84 domain
= mobj
.group('domain')
86 webpage
= self
._download
_webpage
(url
, display_id
)
88 video_id
= self
._search
_regex
(
89 r
'data-video-id=["\'](\d
+)', webpage, 'video
id')
91 info = self._download_json(
92 'http
://%s/api
/v2
/ajax
/videos?video_id
=%s' % (domain, video_id),
97 PROTOCOLS = ('hls
', 'hds
')
100 def extract_formats(protocol, manifest_url):
101 if protocol == 'hls
':
102 m3u8_formats = self._extract_m3u8_formats(
103 manifest_url, video_id, ext='mp4
',
104 entry_protocol='m3u8_native
', m3u8_id=protocol, fatal=False)
105 # Sometimes final URLs inside m3u8 are unsigned, let's fix this
106 # ourselves. Also fragments' URLs are only served signed for
108 query
= compat_urlparse
.parse_qs(compat_urlparse
.urlparse(manifest_url
).query
)
109 for m3u8_format
in m3u8_formats
:
111 'url': update_url_query(m3u8_format
['url'], query
),
113 'User-Agent': USER_AGENTS
['Safari'],
116 formats
.extend(m3u8_formats
)
117 elif protocol
== 'hds':
118 formats
.extend(self
._extract
_f
4m
_formats
(
119 manifest_url
+ '&hdcore=3.8.0&plugin=flowplayer-3.8.0.0',
120 video_id
, f4m_id
=protocol
, fatal
=False))
122 domain_tld
= domain
.split('.')[-1]
123 if domain_tld
in ('se', 'dk', 'no'):
124 for protocol
in PROTOCOLS
:
125 # Providing dsc-geo allows to bypass geo restriction in some cases
127 'secure.dplay.%s' % domain_tld
, 'dsc-geo',
129 'countryCode': domain_tld
.upper(),
130 'expiry': (time
.time() + 20 * 60) * 1000,
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
])
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/).
143 for protocol
in PROTOCOLS
:
144 if info
.get(protocol
):
145 extract_formats(protocol
, info
[protocol
])
147 self
._sort
_formats
(formats
)
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
))
154 subtitles
.setdefault(lang
, []).append({'url': subtitle_url
})
158 'display_id': display_id
,
160 'description': info
.get('video_metadata_longDescription'),
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'),
165 'season_number': int_or_none(info
.get('season')),
166 'episode_number': int_or_none(info
.get('episode')),
167 'age_limit': int_or_none(info
.get('minimum_age')),
169 'subtitles': subtitles
,