]>
Commit | Line | Data |
---|---|---|
aaf44a2f RA |
1 | import re |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import ( | |
5 | float_or_none, | |
6 | ExtractorError, | |
7 | ) | |
8 | ||
9 | ||
10 | class 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 | self._sort_formats(formats) |
37 | asset = self._download_json('http://content.uplynk.com/player/assetinfo/%s.json' % path, display_id) | |
38 | if asset.get('error') == 1: | |
39 | raise ExtractorError('% said: %s' % (self.IE_NAME, asset['msg']), expected=True) | |
40 | ||
41 | return { | |
42 | 'id': asset['asset'], | |
43 | 'title': asset['desc'], | |
44 | 'thumbnail': asset.get('default_poster_url'), | |
45 | 'duration': float_or_none(asset.get('duration')), | |
46 | 'uploader_id': asset.get('owner'), | |
47 | 'formats': formats, | |
2de3b21e | 48 | 'subtitles': subtitles, |
aaf44a2f RA |
49 | } |
50 | ||
9fa57892 RA |
51 | def _real_extract(self, url): |
52 | return self._extract_uplynk_info(url) | |
53 | ||
aaf44a2f | 54 | |
9fa57892 | 55 | class UplynkPreplayIE(UplynkIE): |
24eb13b1 | 56 | IE_NAME = 'uplynk:preplay' |
aaf44a2f | 57 | _VALID_URL = r'https?://.*?\.uplynk\.com/preplay2?/(?P<path>ext/[0-9a-f]{32}/(?P<external_id>[^/?&]+)|(?P<id>[0-9a-f]{32}))\.json' |
24eb13b1 | 58 | _TEST = None |
aaf44a2f RA |
59 | |
60 | def _real_extract(self, url): | |
5ad28e7f | 61 | path, external_id, video_id = self._match_valid_url(url).groups() |
aaf44a2f RA |
62 | display_id = video_id or external_id |
63 | preplay = self._download_json(url, display_id) | |
64 | content_url = 'http://content.uplynk.com/%s.m3u8' % path | |
65 | session_id = preplay.get('sid') | |
66 | if session_id: | |
67 | content_url += '?pbs=' + session_id | |
9fa57892 | 68 | return self._extract_uplynk_info(content_url) |