]>
Commit | Line | Data |
---|---|---|
aaf44a2f RA |
1 | # coding: utf-8 |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
7 | from ..utils import ( | |
8 | float_or_none, | |
9 | ExtractorError, | |
10 | ) | |
11 | ||
12 | ||
13 | class UplynkIE(InfoExtractor): | |
24eb13b1 | 14 | IE_NAME = 'uplynk' |
aaf44a2f RA |
15 | _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>[^&]+))?' |
16 | _TEST = { | |
17 | 'url': 'http://content.uplynk.com/e89eaf2ce9054aa89d92ddb2d817a52e.m3u8', | |
18 | 'info_dict': { | |
19 | 'id': 'e89eaf2ce9054aa89d92ddb2d817a52e', | |
20 | 'ext': 'mp4', | |
21 | 'title': '030816-kgo-530pm-solar-eclipse-vid_web.mp4', | |
22 | 'uploader_id': '4413701bf5a1488db55b767f8ae9d4fa', | |
23 | }, | |
24 | 'params': { | |
25 | # m3u8 download | |
26 | 'skip_download': True, | |
27 | }, | |
28 | } | |
29 | ||
9fa57892 RA |
30 | def _extract_uplynk_info(self, uplynk_content_url): |
31 | path, external_id, video_id, session_id = re.match(UplynkIE._VALID_URL, uplynk_content_url).groups() | |
aaf44a2f RA |
32 | display_id = video_id or external_id |
33 | formats = self._extract_m3u8_formats('http://content.uplynk.com/%s.m3u8' % path, display_id, 'mp4') | |
34 | if session_id: | |
35 | for f in formats: | |
b8079a40 | 36 | f['extra_param_to_segment_url'] = 'pbs=' + session_id |
aaf44a2f RA |
37 | self._sort_formats(formats) |
38 | asset = self._download_json('http://content.uplynk.com/player/assetinfo/%s.json' % path, display_id) | |
39 | if asset.get('error') == 1: | |
40 | raise ExtractorError('% said: %s' % (self.IE_NAME, asset['msg']), expected=True) | |
41 | ||
42 | return { | |
43 | 'id': asset['asset'], | |
44 | 'title': asset['desc'], | |
45 | 'thumbnail': asset.get('default_poster_url'), | |
46 | 'duration': float_or_none(asset.get('duration')), | |
47 | 'uploader_id': asset.get('owner'), | |
48 | 'formats': formats, | |
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): | |
61 | path, external_id, video_id = re.match(self._VALID_URL, url).groups() | |
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) |