]>
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): | |
14 | _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>[^&]+))?' | |
15 | _TEST = { | |
16 | 'url': 'http://content.uplynk.com/e89eaf2ce9054aa89d92ddb2d817a52e.m3u8', | |
17 | 'info_dict': { | |
18 | 'id': 'e89eaf2ce9054aa89d92ddb2d817a52e', | |
19 | 'ext': 'mp4', | |
20 | 'title': '030816-kgo-530pm-solar-eclipse-vid_web.mp4', | |
21 | 'uploader_id': '4413701bf5a1488db55b767f8ae9d4fa', | |
22 | }, | |
23 | 'params': { | |
24 | # m3u8 download | |
25 | 'skip_download': True, | |
26 | }, | |
27 | } | |
28 | ||
9fa57892 RA |
29 | def _extract_uplynk_info(self, uplynk_content_url): |
30 | path, external_id, video_id, session_id = re.match(UplynkIE._VALID_URL, uplynk_content_url).groups() | |
aaf44a2f RA |
31 | display_id = video_id or external_id |
32 | formats = self._extract_m3u8_formats('http://content.uplynk.com/%s.m3u8' % path, display_id, 'mp4') | |
33 | if session_id: | |
34 | for f in formats: | |
35 | f['extra_param_to_segment_url'] = { | |
36 | 'pbs': session_id, | |
37 | } | |
38 | self._sort_formats(formats) | |
39 | asset = self._download_json('http://content.uplynk.com/player/assetinfo/%s.json' % path, display_id) | |
40 | if asset.get('error') == 1: | |
41 | raise ExtractorError('% said: %s' % (self.IE_NAME, asset['msg']), expected=True) | |
42 | ||
43 | return { | |
44 | 'id': asset['asset'], | |
45 | 'title': asset['desc'], | |
46 | 'thumbnail': asset.get('default_poster_url'), | |
47 | 'duration': float_or_none(asset.get('duration')), | |
48 | 'uploader_id': asset.get('owner'), | |
49 | 'formats': formats, | |
50 | } | |
51 | ||
9fa57892 RA |
52 | def _real_extract(self, url): |
53 | return self._extract_uplynk_info(url) | |
54 | ||
aaf44a2f | 55 | |
9fa57892 | 56 | class UplynkPreplayIE(UplynkIE): |
aaf44a2f RA |
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' |
58 | ||
59 | def _real_extract(self, url): | |
60 | path, external_id, video_id = re.match(self._VALID_URL, url).groups() | |
61 | display_id = video_id or external_id | |
62 | preplay = self._download_json(url, display_id) | |
63 | content_url = 'http://content.uplynk.com/%s.m3u8' % path | |
64 | session_id = preplay.get('sid') | |
65 | if session_id: | |
66 | content_url += '?pbs=' + session_id | |
9fa57892 | 67 | return self._extract_uplynk_info(content_url) |