[ciscolive] fix search

This commit is contained in:
Chris W 2024-05-10 23:28:36 +01:00
parent 0af2f585e7
commit dd2ee5e071

View File

@ -116,11 +116,11 @@ class CiscoLiveSessionIE(CiscoLiveBaseIE):
class CiscoLiveSearchIE(CiscoLiveBaseIE): class CiscoLiveSearchIE(CiscoLiveBaseIE):
_VALID_URL = r'https?://(?:www\.)?ciscolive(?:\.cisco)?\.com/(?:global/|on-demand/)?on-demand-library(?:\.html|/)' _VALID_URL = r'https?://(?:www\.)?ciscolive(?:\.cisco)?\.com/(?:global/|on-demand/)?on-demand-library(?:\.html|/)'
_TESTS = [{ _TESTS = [{
'url': 'https://www.ciscolive.com/on-demand/on-demand-library.html?search.event=1636046385176005FbBU&search.technology=scpsTechnology_dataCenter&search.technicallevel=scpsSkillLevel_aintroductory#/', 'url': 'https://www.ciscolive.com/on-demand/on-demand-library.html?search.technology=1614262524988009b6j9&search.technicallevel=scpsSkillLevel_bintermediate#/',
'info_dict': { 'info_dict': {
'title': 'Search query', 'title': 'Search query',
}, },
'playlist_count': 3, # example returns 4 results, only 3 have video 'playlist_count': 6,
}, { }, {
'url': 'https://www.ciscolive.com/on-demand/on-demand-library.html?search.technology=scpsTechnology_automation&search.technicallevel=scpsSkillLevel_cadvanced#/', 'url': 'https://www.ciscolive.com/on-demand/on-demand-library.html?search.technology=scpsTechnology_automation&search.technicallevel=scpsSkillLevel_cadvanced#/',
}, { }, {
@ -137,35 +137,25 @@ class CiscoLiveSearchIE(CiscoLiveBaseIE):
return int_or_none(try_get(rf_item, lambda x: x['videos'][0]['url'])) is not None return int_or_none(try_get(rf_item, lambda x: x['videos'][0]['url'])) is not None
def _entries(self, query, url): def _entries(self, query, url):
query['size'] = 50 results = self._call_api(
query['from'] = 0 'search', None, query, url,
for page_num in itertools.count(1): 'Downloading search JSON')
results = self._call_api( if int(results['totalSearchItems']) == 0:
'search', None, query, url, raise ExtractorError(
'Downloading search JSON page %d' % page_num) 'Search api returned no items (if matches are expected rfApiProfileId may be invalid)',
if int(results['totalSearchItems']) == 0: expected=True)
raise ExtractorError( sl = try_get(results, lambda x: x['sectionList'], list)
'Search api returned no items (if matches are expected rfApiProfileId may be invalid)', if sl is not None:
expected=True) for s in sl:
sl = try_get(results, lambda x: x['sectionList'][0], dict) items = s.get('items')
if sl: if not items or not isinstance(items, list):
results = sl break
items = results.get('items') for item in items:
if not items or not isinstance(items, list): if not isinstance(item, dict):
break continue
for item in items: if not self._check_bc_id_exists(item):
if not isinstance(item, dict): continue
continue yield self._parse_rf_item(item)
if not self._check_bc_id_exists(item):
continue
yield self._parse_rf_item(item)
size = int_or_none(results.get('size'))
if size is not None:
query['size'] = size
total = int_or_none(results.get('total'))
if total is not None and query['from'] + query['size'] > total:
break
query['from'] += query['size']
def _real_extract(self, url): def _real_extract(self, url):
query = compat_parse_qs(compat_urllib_parse_urlparse(url).query) query = compat_parse_qs(compat_urllib_parse_urlparse(url).query)