2016-08-13 23:53:07 +02:00
|
|
|
import re
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..utils import (
|
|
|
|
ExtractorError,
|
2022-12-10 00:43:10 +01:00
|
|
|
float_or_none,
|
|
|
|
smuggle_url,
|
|
|
|
traverse_obj,
|
|
|
|
unsmuggle_url,
|
|
|
|
update_url_query,
|
2016-08-13 23:53:07 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-12-10 00:43:10 +01:00
|
|
|
class UplynkBaseIE(InfoExtractor):
|
|
|
|
_UPLYNK_URL_RE = r'''(?x)
|
|
|
|
https?://[\w-]+\.uplynk\.com/(?P<path>
|
|
|
|
ext/[0-9a-f]{32}/(?P<external_id>[^/?&]+)|
|
|
|
|
(?P<id>[0-9a-f]{32})
|
|
|
|
)\.(?:m3u8|json)
|
|
|
|
(?:.*?\bpbs=(?P<session_id>[^&]+))?'''
|
2016-08-13 23:53:07 +02:00
|
|
|
|
2022-12-10 00:43:10 +01:00
|
|
|
def _extract_uplynk_info(self, url):
|
|
|
|
uplynk_content_url, smuggled_data = unsmuggle_url(url, {})
|
|
|
|
mobj = re.match(self._UPLYNK_URL_RE, uplynk_content_url)
|
|
|
|
if not mobj:
|
|
|
|
raise ExtractorError('Necessary parameters not found in Uplynk URL')
|
|
|
|
path, external_id, video_id, session_id = mobj.group('path', 'external_id', 'id', 'session_id')
|
2016-08-13 23:53:07 +02:00
|
|
|
display_id = video_id or external_id
|
2022-12-10 00:43:10 +01:00
|
|
|
headers = traverse_obj(
|
|
|
|
smuggled_data, {'Referer': 'Referer', 'Origin': 'Origin'}, casesense=False)
|
2021-04-18 08:41:46 +02:00
|
|
|
formats, subtitles = self._extract_m3u8_formats_and_subtitles(
|
2022-12-10 00:43:10 +01:00
|
|
|
f'http://content.uplynk.com/{path}.m3u8', display_id, 'mp4', headers=headers)
|
2016-08-13 23:53:07 +02:00
|
|
|
if session_id:
|
|
|
|
for f in formats:
|
2022-12-10 00:43:10 +01:00
|
|
|
f['extra_param_to_segment_url'] = f'pbs={session_id}'
|
|
|
|
asset = self._download_json(
|
|
|
|
f'http://content.uplynk.com/player/assetinfo/{path}.json', display_id)
|
2016-08-13 23:53:07 +02:00
|
|
|
if asset.get('error') == 1:
|
2022-12-10 00:43:10 +01:00
|
|
|
msg = asset.get('msg') or 'unknown error'
|
|
|
|
raise ExtractorError(f'{self.IE_NAME} said: {msg}', expected=True)
|
2016-08-13 23:53:07 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
'id': asset['asset'],
|
|
|
|
'title': asset['desc'],
|
|
|
|
'thumbnail': asset.get('default_poster_url'),
|
|
|
|
'duration': float_or_none(asset.get('duration')),
|
|
|
|
'uploader_id': asset.get('owner'),
|
|
|
|
'formats': formats,
|
2021-04-18 08:41:46 +02:00
|
|
|
'subtitles': subtitles,
|
2016-08-13 23:53:07 +02:00
|
|
|
}
|
|
|
|
|
2022-12-10 00:43:10 +01:00
|
|
|
|
|
|
|
class UplynkIE(UplynkBaseIE):
|
|
|
|
IE_NAME = 'uplynk'
|
|
|
|
_VALID_URL = UplynkBaseIE._UPLYNK_URL_RE
|
|
|
|
_TEST = {
|
|
|
|
'url': 'http://content.uplynk.com/e89eaf2ce9054aa89d92ddb2d817a52e.m3u8',
|
|
|
|
'info_dict': {
|
|
|
|
'id': 'e89eaf2ce9054aa89d92ddb2d817a52e',
|
|
|
|
'ext': 'mp4',
|
|
|
|
'title': '030816-kgo-530pm-solar-eclipse-vid_web.mp4',
|
|
|
|
'uploader_id': '4413701bf5a1488db55b767f8ae9d4fa',
|
|
|
|
'duration': 530.2739166666679,
|
|
|
|
'thumbnail': r're:^https?://.*\.jpg$',
|
|
|
|
},
|
|
|
|
'params': {
|
|
|
|
'skip_download': 'm3u8',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-08-14 20:04:23 +02:00
|
|
|
def _real_extract(self, url):
|
|
|
|
return self._extract_uplynk_info(url)
|
|
|
|
|
2016-08-13 23:53:07 +02:00
|
|
|
|
2022-12-10 00:43:10 +01:00
|
|
|
class UplynkPreplayIE(UplynkBaseIE):
|
2016-08-14 23:45:43 +02:00
|
|
|
IE_NAME = 'uplynk:preplay'
|
2022-12-10 00:43:10 +01:00
|
|
|
_VALID_URL = r'https?://[\w-]+\.uplynk\.com/preplay2?/(?P<path>ext/[0-9a-f]{32}/(?P<external_id>[^/?&]+)|(?P<id>[0-9a-f]{32}))\.json'
|
2016-08-13 23:53:07 +02:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2022-12-10 00:43:10 +01:00
|
|
|
url, smuggled_data = unsmuggle_url(url, {})
|
2021-08-19 03:41:24 +02:00
|
|
|
path, external_id, video_id = self._match_valid_url(url).groups()
|
2016-08-13 23:53:07 +02:00
|
|
|
display_id = video_id or external_id
|
|
|
|
preplay = self._download_json(url, display_id)
|
2022-12-10 00:43:10 +01:00
|
|
|
content_url = f'http://content.uplynk.com/{path}.m3u8'
|
2016-08-13 23:53:07 +02:00
|
|
|
session_id = preplay.get('sid')
|
|
|
|
if session_id:
|
2022-12-10 00:43:10 +01:00
|
|
|
content_url = update_url_query(content_url, {'pbs': session_id})
|
|
|
|
return self._extract_uplynk_info(smuggle_url(content_url, smuggled_data))
|