2018-10-27 11:15:44 +09:00
|
|
|
# coding: utf-8
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from .common import InfoExtractor
|
|
|
|
from ..compat import (
|
2018-11-21 07:25:43 +09:00
|
|
|
compat_parse_qs,
|
2018-10-27 11:15:44 +09:00
|
|
|
compat_urllib_parse_urlparse,
|
|
|
|
)
|
|
|
|
from ..utils import (
|
|
|
|
clean_html,
|
2022-04-18 00:55:03 +09:00
|
|
|
ExtractorError,
|
2018-11-21 07:25:43 +09:00
|
|
|
float_or_none,
|
2018-10-27 11:15:44 +09:00
|
|
|
int_or_none,
|
|
|
|
try_get,
|
|
|
|
urlencode_postdata,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2018-11-21 07:25:43 +09:00
|
|
|
class CiscoLiveBaseIE(InfoExtractor):
|
2018-10-27 11:15:44 +09:00
|
|
|
# These appear to be constant across all Cisco Live presentations
|
|
|
|
# and are not tied to any user session or event
|
|
|
|
RAINFOCUS_API_URL = 'https://events.rainfocus.com/api/%s'
|
2022-04-18 00:55:03 +09:00
|
|
|
RAINFOCUS_API_PROFILE_ID = '' # if blank will be fetched at runtime from site javascript
|
|
|
|
RAINFOCUS_WIDGET_ID = '' # if blank will be fetched at runtime from site javascript
|
|
|
|
RAINFOCUS_TOKENS_URL = 'https://cdn-events.rainfocus.com/pages/cisco/clondemand/catalog.js'
|
2018-10-27 11:15:44 +09:00
|
|
|
BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/5647924234001/SyK2FdqjM_default/index.html?videoId=%s'
|
|
|
|
|
2018-11-21 07:25:43 +09:00
|
|
|
HEADERS = {
|
2022-04-18 00:55:03 +09:00
|
|
|
'Origin': 'https://ciscolive.com',
|
2018-11-21 07:25:43 +09:00
|
|
|
'rfApiProfileId': RAINFOCUS_API_PROFILE_ID,
|
|
|
|
'rfWidgetId': RAINFOCUS_WIDGET_ID,
|
|
|
|
}
|
|
|
|
|
2018-11-21 08:04:34 +09:00
|
|
|
def _call_api(self, ep, rf_id, query, referrer, note=None):
|
2018-11-21 07:25:43 +09:00
|
|
|
headers = self.HEADERS.copy()
|
|
|
|
headers['Referer'] = referrer
|
2022-05-01 19:42:45 +09:00
|
|
|
if not self.RAINFOCUS_API_PROFILE_ID or not self.RAINFOCUS_WIDGET_ID:
|
2022-04-18 00:55:03 +09:00
|
|
|
rf_token_js = self._download_webpage(self.RAINFOCUS_TOKENS_URL, 'catalog.js', headers=headers)
|
2022-05-01 19:42:45 +09:00
|
|
|
for token in ('apiToken', 'widgetId'):
|
|
|
|
if token not in rf_token_js:
|
|
|
|
raise ExtractorError(
|
|
|
|
'Unable to fetch ' + token, expected=True)
|
2022-04-18 00:55:03 +09:00
|
|
|
api_token = self._html_search_regex(
|
2022-05-01 19:42:45 +09:00
|
|
|
r'''apiToken:\s+["'](\w+)''', rf_token_js, 'apiToken')
|
2022-04-18 00:55:03 +09:00
|
|
|
widget_id = self._html_search_regex(
|
2022-05-01 19:42:45 +09:00
|
|
|
r'''widgetId:\s+["'](\w+)''', rf_token_js, 'widgetId')
|
|
|
|
headers['rfApiProfileId'] = api_token
|
|
|
|
headers['rfWidgetId'] = widget_id
|
|
|
|
rf_result = self._download_json(
|
2018-11-21 08:04:34 +09:00
|
|
|
self.RAINFOCUS_API_URL % ep, rf_id, note=note,
|
|
|
|
data=urlencode_postdata(query), headers=headers)
|
2022-05-01 19:42:45 +09:00
|
|
|
if int(rf_result['responseCode']) != 0:
|
|
|
|
raise ExtractorError(
|
|
|
|
'Rainfocus %s api returned a non success responseCode: %s. api keys might be invalid' % (ep, rf_result['responseCode']), expected=True)
|
|
|
|
return rf_result
|
2018-11-21 07:25:43 +09:00
|
|
|
|
2018-10-27 11:15:44 +09:00
|
|
|
def _parse_rf_item(self, rf_item):
|
|
|
|
event_name = rf_item.get('eventName')
|
|
|
|
title = rf_item['title']
|
|
|
|
description = clean_html(rf_item.get('abstract'))
|
|
|
|
presenter_name = try_get(rf_item, lambda x: x['participants'][0]['fullName'])
|
|
|
|
bc_id = rf_item['videos'][0]['url']
|
|
|
|
bc_url = self.BRIGHTCOVE_URL_TEMPLATE % bc_id
|
2018-11-21 07:25:43 +09:00
|
|
|
duration = float_or_none(try_get(rf_item, lambda x: x['times'][0]['length']))
|
2018-10-27 11:15:44 +09:00
|
|
|
location = try_get(rf_item, lambda x: x['times'][0]['room'])
|
|
|
|
|
|
|
|
if duration:
|
|
|
|
duration = duration * 60
|
|
|
|
|
|
|
|
return {
|
|
|
|
'_type': 'url_transparent',
|
2018-11-21 07:25:43 +09:00
|
|
|
'url': bc_url,
|
|
|
|
'ie_key': 'BrightcoveNew',
|
|
|
|
'title': title,
|
2018-10-27 11:15:44 +09:00
|
|
|
'description': description,
|
|
|
|
'duration': duration,
|
2018-11-21 07:25:43 +09:00
|
|
|
'creator': presenter_name,
|
2018-10-27 11:15:44 +09:00
|
|
|
'location': location,
|
|
|
|
'series': event_name,
|
|
|
|
}
|
|
|
|
|
2018-11-21 07:25:43 +09:00
|
|
|
|
|
|
|
class CiscoLiveSessionIE(CiscoLiveBaseIE):
|
2022-05-01 19:42:45 +09:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?ciscolive(?:\.cisco)?\.com/[^#]*#/session/(?P<id>[^/?&]+)'
|
2019-03-17 09:18:54 +09:00
|
|
|
_TESTS = [{
|
2022-04-18 00:55:03 +09:00
|
|
|
'url': 'https://www.ciscolive.com/on-demand/on-demand-library.html?search=#/session/16360600004400017rMx',
|
|
|
|
'md5': 'e0f5b0b2927b586ebff619294fec6926',
|
2018-11-21 07:25:43 +09:00
|
|
|
'info_dict': {
|
2022-04-18 00:55:03 +09:00
|
|
|
'id': '6128601216001',
|
2018-11-21 07:25:43 +09:00
|
|
|
'ext': 'mp4',
|
2022-04-18 00:55:03 +09:00
|
|
|
'title': 'A Deeper Dive into the Telco Cloud Architecture Evolution to support 5G and MEC - BRKSPG-1565',
|
|
|
|
'description': 'md5:04bc54ec8ede2bbd9d21264bfaf16cb3',
|
|
|
|
'timestamp': 1580474594,
|
|
|
|
'upload_date': '20200131',
|
2018-11-21 07:25:43 +09:00
|
|
|
'uploader_id': '5647924234001',
|
|
|
|
},
|
2019-03-17 09:18:54 +09:00
|
|
|
}, {
|
|
|
|
'url': 'https://www.ciscolive.com/global/on-demand-library.html?search.event=ciscoliveemea2019#/session/15361595531500013WOU',
|
|
|
|
'only_matching': True,
|
|
|
|
}, {
|
|
|
|
'url': 'https://www.ciscolive.com/global/on-demand-library.html?#/session/1490051371645001kNaS',
|
|
|
|
'only_matching': True,
|
2022-04-18 00:55:03 +09:00
|
|
|
}, {
|
|
|
|
'url': 'https://www.ciscolive.com/on-demand/on-demand-library.html?#/session/16360600774720017Iby',
|
|
|
|
'only_matching': True,
|
2019-03-17 09:18:54 +09:00
|
|
|
}]
|
2018-10-27 11:15:44 +09:00
|
|
|
|
|
|
|
def _real_extract(self, url):
|
2018-11-21 07:25:43 +09:00
|
|
|
rf_id = self._match_id(url)
|
|
|
|
rf_result = self._call_api('session', rf_id, {'id': rf_id}, url)
|
|
|
|
return self._parse_rf_item(rf_result['items'][0])
|
|
|
|
|
|
|
|
|
|
|
|
class CiscoLiveSearchIE(CiscoLiveBaseIE):
|
2022-05-01 19:42:45 +09:00
|
|
|
_VALID_URL = r'https?://(?:www\.)?ciscolive(?:\.cisco)?\.com/(?:global/|on-demand/)?on-demand-library(?:\.html|/)'
|
2018-11-21 07:25:43 +09:00
|
|
|
_TESTS = [{
|
2024-05-11 07:28:36 +09:00
|
|
|
'url': 'https://www.ciscolive.com/on-demand/on-demand-library.html?search.technology=1614262524988009b6j9&search.technicallevel=scpsSkillLevel_bintermediate#/',
|
2018-11-21 07:25:43 +09:00
|
|
|
'info_dict': {
|
2018-11-21 08:04:34 +09:00
|
|
|
'title': 'Search query',
|
2018-11-21 07:25:43 +09:00
|
|
|
},
|
2024-05-11 07:28:36 +09:00
|
|
|
'playlist_count': 6,
|
2018-11-21 07:25:43 +09:00
|
|
|
}, {
|
2022-04-18 00:55:03 +09:00
|
|
|
'url': 'https://www.ciscolive.com/on-demand/on-demand-library.html?search.technology=scpsTechnology_automation&search.technicallevel=scpsSkillLevel_cadvanced#/',
|
2019-03-17 09:18:54 +09:00
|
|
|
}, {
|
|
|
|
'url': 'https://www.ciscolive.com/global/on-demand-library.html?search.technicallevel=scpsSkillLevel_aintroductory&search.event=ciscoliveemea2019&search.technology=scpsTechnology_dataCenter&search.focus=scpsSessionFocus_bestPractices#/',
|
|
|
|
'only_matching': True,
|
2018-11-21 07:25:43 +09:00
|
|
|
}]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def suitable(cls, url):
|
|
|
|
return False if CiscoLiveSessionIE.suitable(url) else super(CiscoLiveSearchIE, cls).suitable(url)
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _check_bc_id_exists(rf_item):
|
|
|
|
return int_or_none(try_get(rf_item, lambda x: x['videos'][0]['url'])) is not None
|
|
|
|
|
2018-11-21 08:04:34 +09:00
|
|
|
def _entries(self, query, url):
|
2024-05-11 07:28:36 +09:00
|
|
|
results = self._call_api(
|
|
|
|
'search', None, query, url,
|
|
|
|
'Downloading search JSON')
|
|
|
|
if int(results['totalSearchItems']) == 0:
|
|
|
|
raise ExtractorError(
|
|
|
|
'Search api returned no items (if matches are expected rfApiProfileId may be invalid)',
|
|
|
|
expected=True)
|
|
|
|
sl = try_get(results, lambda x: x['sectionList'], list)
|
|
|
|
if sl is not None:
|
|
|
|
for s in sl:
|
|
|
|
items = s.get('items')
|
|
|
|
if not items or not isinstance(items, list):
|
|
|
|
break
|
|
|
|
for item in items:
|
|
|
|
if not isinstance(item, dict):
|
|
|
|
continue
|
|
|
|
if not self._check_bc_id_exists(item):
|
|
|
|
continue
|
|
|
|
yield self._parse_rf_item(item)
|
2018-11-21 08:04:34 +09:00
|
|
|
|
2018-11-21 07:25:43 +09:00
|
|
|
def _real_extract(self, url):
|
2018-11-21 08:04:34 +09:00
|
|
|
query = compat_parse_qs(compat_urllib_parse_urlparse(url).query)
|
|
|
|
query['type'] = 'session'
|
|
|
|
return self.playlist_result(
|
|
|
|
self._entries(query, url), playlist_title='Search query')
|