]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/uplynk.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / uplynk.py
CommitLineData
aaf44a2f
RA
1import re
2
3from .common import InfoExtractor
4from ..utils import (
5 float_or_none,
6 ExtractorError,
7)
8
9
10class UplynkIE(InfoExtractor):
24eb13b1 11 IE_NAME = 'uplynk'
aaf44a2f
RA
12 _VALID_URL = r'https?://.*?\.uplynk\.com/(?P<path>ext/[0-9a-f]{32}/(?P<external_id>[^/?&]+)|(?P<id>[0-9a-f]{32}))\.(?:m3u8|json)(?:.*?\bpbs=(?P<session_id>[^&]+))?'
13 _TEST = {
14 'url': 'http://content.uplynk.com/e89eaf2ce9054aa89d92ddb2d817a52e.m3u8',
15 'info_dict': {
16 'id': 'e89eaf2ce9054aa89d92ddb2d817a52e',
17 'ext': 'mp4',
18 'title': '030816-kgo-530pm-solar-eclipse-vid_web.mp4',
19 'uploader_id': '4413701bf5a1488db55b767f8ae9d4fa',
20 },
21 'params': {
22 # m3u8 download
23 'skip_download': True,
24 },
25 }
26
9fa57892
RA
27 def _extract_uplynk_info(self, uplynk_content_url):
28 path, external_id, video_id, session_id = re.match(UplynkIE._VALID_URL, uplynk_content_url).groups()
aaf44a2f 29 display_id = video_id or external_id
2de3b21e 30 formats, subtitles = self._extract_m3u8_formats_and_subtitles(
bfa1073e
RA
31 'http://content.uplynk.com/%s.m3u8' % path,
32 display_id, 'mp4', 'm3u8_native')
aaf44a2f
RA
33 if session_id:
34 for f in formats:
b8079a40 35 f['extra_param_to_segment_url'] = 'pbs=' + session_id
aaf44a2f
RA
36 asset = self._download_json('http://content.uplynk.com/player/assetinfo/%s.json' % path, display_id)
37 if asset.get('error') == 1:
38 raise ExtractorError('% said: %s' % (self.IE_NAME, asset['msg']), expected=True)
39
40 return {
41 'id': asset['asset'],
42 'title': asset['desc'],
43 'thumbnail': asset.get('default_poster_url'),
44 'duration': float_or_none(asset.get('duration')),
45 'uploader_id': asset.get('owner'),
46 'formats': formats,
2de3b21e 47 'subtitles': subtitles,
aaf44a2f
RA
48 }
49
9fa57892
RA
50 def _real_extract(self, url):
51 return self._extract_uplynk_info(url)
52
aaf44a2f 53
6368e2e6 54class UplynkPreplayIE(UplynkIE): # XXX: Do not subclass from concrete IE
24eb13b1 55 IE_NAME = 'uplynk:preplay'
aaf44a2f
RA
56 _VALID_URL = r'https?://.*?\.uplynk\.com/preplay2?/(?P<path>ext/[0-9a-f]{32}/(?P<external_id>[^/?&]+)|(?P<id>[0-9a-f]{32}))\.json'
57
58 def _real_extract(self, url):
5ad28e7f 59 path, external_id, video_id = self._match_valid_url(url).groups()
aaf44a2f
RA
60 display_id = video_id or external_id
61 preplay = self._download_json(url, display_id)
62 content_url = 'http://content.uplynk.com/%s.m3u8' % path
63 session_id = preplay.get('sid')
64 if session_id:
65 content_url += '?pbs=' + session_id
9fa57892 66 return self._extract_uplynk_info(content_url)