From f24ea24a29d101fc23c6ce61e0ef3d297ed35548 Mon Sep 17 00:00:00 2001 From: Chris W <84198105+L0wbyte@users.noreply.github.com> Date: Sun, 17 Apr 2022 16:55:03 +0100 Subject: [PATCH 1/5] fix issues and dynamically fetch tokens --- youtube_dl/extractor/ciscolive.py | 59 ++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/youtube_dl/extractor/ciscolive.py b/youtube_dl/extractor/ciscolive.py index da404e4dc..470e42e9c 100644 --- a/youtube_dl/extractor/ciscolive.py +++ b/youtube_dl/extractor/ciscolive.py @@ -10,6 +10,7 @@ from ..compat import ( ) from ..utils import ( clean_html, + ExtractorError, float_or_none, int_or_none, try_get, @@ -21,12 +22,13 @@ class CiscoLiveBaseIE(InfoExtractor): # 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' - RAINFOCUS_API_PROFILE_ID = 'Na3vqYdAlJFSxhYTYQGuMbpafMqftalz' - RAINFOCUS_WIDGET_ID = 'n6l4Lo05R8fiy3RpUBm447dZN8uNWoye' + 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' BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/5647924234001/SyK2FdqjM_default/index.html?videoId=%s' HEADERS = { - 'Origin': 'https://ciscolive.cisco.com', + 'Origin': 'https://ciscolive.com', 'rfApiProfileId': RAINFOCUS_API_PROFILE_ID, 'rfWidgetId': RAINFOCUS_WIDGET_ID, } @@ -34,6 +36,21 @@ class CiscoLiveBaseIE(InfoExtractor): def _call_api(self, ep, rf_id, query, referrer, note=None): headers = self.HEADERS.copy() headers['Referer'] = referrer + if not self.RAINFOCUS_API_PROFILE_ID and not self.RAINFOCUS_WIDGET_ID: + rf_token_js = self._download_webpage(self.RAINFOCUS_TOKENS_URL, 'catalog.js', headers=headers) + if "apiToken" not in rf_token_js: + raise ExtractorError( + 'Unable to fetch api profile (apiToken) value.', expected=True) + if "widgetId" not in rf_token_js: + raise ExtractorError( + 'Unable to fetch widgetId value', expected=True) + api_token = self._html_search_regex( + r'(?:apiToken): \'(\w+)\',', rf_token_js, 'apiToken') + widget_id = self._html_search_regex( + r'(?:widgetId): \'(\w+)\',', rf_token_js, 'widgetId') + if api_token and widget_id: + headers['rfApiProfileId'] = api_token + headers['rfWidgetId'] = widget_id return self._download_json( self.RAINFOCUS_API_URL % ep, rf_id, note=note, data=urlencode_postdata(query), headers=headers) @@ -65,19 +82,18 @@ class CiscoLiveBaseIE(InfoExtractor): class CiscoLiveSessionIE(CiscoLiveBaseIE): - _VALID_URL = r'https?://(?:www\.)?ciscolive(?:\.cisco)?\.com/[^#]*#/session/(?P[^/?&]+)' + _VALID_URL = r'https?://(?:www\.)?ciscolive\.com/[^#]*#/session/(?P[^/?&]+)' _TESTS = [{ - 'url': 'https://ciscolive.cisco.com/on-demand-library/?#/session/1423353499155001FoSs', - 'md5': 'c98acf395ed9c9f766941c70f5352e22', + 'url': 'https://www.ciscolive.com/on-demand/on-demand-library.html?search=#/session/16360600004400017rMx', + 'md5': 'e0f5b0b2927b586ebff619294fec6926', 'info_dict': { - 'id': '5803694304001', + 'id': '6128601216001', 'ext': 'mp4', - 'title': '13 Smart Automations to Monitor Your Cisco IOS Network', - 'description': 'md5:ec4a436019e09a918dec17714803f7cc', - 'timestamp': 1530305395, - 'upload_date': '20180629', + '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', 'uploader_id': '5647924234001', - 'location': '16B Mezz.', }, }, { 'url': 'https://www.ciscolive.com/global/on-demand-library.html?search.event=ciscoliveemea2019#/session/15361595531500013WOU', @@ -85,25 +101,30 @@ class CiscoLiveSessionIE(CiscoLiveBaseIE): }, { 'url': 'https://www.ciscolive.com/global/on-demand-library.html?#/session/1490051371645001kNaS', 'only_matching': True, + }, { + 'url': 'https://www.ciscolive.com/on-demand/on-demand-library.html?#/session/16360600774720017Iby', + 'only_matching': True, }] def _real_extract(self, url): rf_id = self._match_id(url) rf_result = self._call_api('session', rf_id, {'id': rf_id}, url) + if int(rf_result['responseCode']) != 0: + raise ExtractorError( + 'Rainfocus session api returned a non success responseCode: %s. api keys might be invalid' % rf_result['responseCode'], expected=True) return self._parse_rf_item(rf_result['items'][0]) class CiscoLiveSearchIE(CiscoLiveBaseIE): - _VALID_URL = r'https?://(?:www\.)?ciscolive(?:\.cisco)?\.com/(?:global/)?on-demand-library(?:\.html|/)' + _VALID_URL = r'https?://(?:www\.)?ciscolive\.com/(?:global|on-demand/)?on-demand-library(?:\.html|/)' _TESTS = [{ - 'url': 'https://ciscolive.cisco.com/on-demand-library/?search.event=ciscoliveus2018&search.technicallevel=scpsSkillLevel_aintroductory&search.focus=scpsSessionFocus_designAndDeployment#/', + 'url': 'https://www.ciscolive.com/on-demand/on-demand-library.html?search.event=1636046385176005FbBU&search.technology=scpsTechnology_dataCenter&search.technicallevel=scpsSkillLevel_aintroductory#/', 'info_dict': { 'title': 'Search query', }, - 'playlist_count': 5, + 'playlist_count': 3, # example returns 4 results, only 3 have video }, { - 'url': 'https://ciscolive.cisco.com/on-demand-library/?search.technology=scpsTechnology_applicationDevelopment&search.technology=scpsTechnology_ipv6&search.focus=scpsSessionFocus_troubleshootingTroubleshooting#/', - 'only_matching': True, + 'url': 'https://www.ciscolive.com/on-demand/on-demand-library.html?search.technology=scpsTechnology_automation&search.technicallevel=scpsSkillLevel_cadvanced#/', }, { '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, @@ -124,6 +145,10 @@ class CiscoLiveSearchIE(CiscoLiveBaseIE): results = self._call_api( 'search', None, query, url, 'Downloading search JSON page %d' % page_num) + if int(results['totalSearchItems']) == 0: + raise ExtractorError( + 'Search api returned 0 items (if matches are expected rfApiProfileId may be invalid)', + expected=True) sl = try_get(results, lambda x: x['sectionList'][0], dict) if sl: results = sl From 9409e00d95c0f0ad656349bb43e449233a66c7c9 Mon Sep 17 00:00:00 2001 From: Chris W <84198105+L0wbyte@users.noreply.github.com> Date: Sun, 1 May 2022 11:42:45 +0100 Subject: [PATCH 2/5] [ciscolive] add maintainers suggestions --- youtube_dl/extractor/ciscolive.py | 36 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/youtube_dl/extractor/ciscolive.py b/youtube_dl/extractor/ciscolive.py index 470e42e9c..b41f51111 100644 --- a/youtube_dl/extractor/ciscolive.py +++ b/youtube_dl/extractor/ciscolive.py @@ -36,24 +36,25 @@ class CiscoLiveBaseIE(InfoExtractor): def _call_api(self, ep, rf_id, query, referrer, note=None): headers = self.HEADERS.copy() headers['Referer'] = referrer - if not self.RAINFOCUS_API_PROFILE_ID and not self.RAINFOCUS_WIDGET_ID: + if not self.RAINFOCUS_API_PROFILE_ID or not self.RAINFOCUS_WIDGET_ID: rf_token_js = self._download_webpage(self.RAINFOCUS_TOKENS_URL, 'catalog.js', headers=headers) - if "apiToken" not in rf_token_js: - raise ExtractorError( - 'Unable to fetch api profile (apiToken) value.', expected=True) - if "widgetId" not in rf_token_js: - raise ExtractorError( - 'Unable to fetch widgetId value', expected=True) + for token in ('apiToken', 'widgetId'): + if token not in rf_token_js: + raise ExtractorError( + 'Unable to fetch ' + token, expected=True) api_token = self._html_search_regex( - r'(?:apiToken): \'(\w+)\',', rf_token_js, 'apiToken') + r'''apiToken:\s+["'](\w+)''', rf_token_js, 'apiToken') widget_id = self._html_search_regex( - r'(?:widgetId): \'(\w+)\',', rf_token_js, 'widgetId') - if api_token and widget_id: - headers['rfApiProfileId'] = api_token - headers['rfWidgetId'] = widget_id - return self._download_json( + r'''widgetId:\s+["'](\w+)''', rf_token_js, 'widgetId') + headers['rfApiProfileId'] = api_token + headers['rfWidgetId'] = widget_id + rf_result = self._download_json( self.RAINFOCUS_API_URL % ep, rf_id, note=note, data=urlencode_postdata(query), headers=headers) + 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 def _parse_rf_item(self, rf_item): event_name = rf_item.get('eventName') @@ -82,7 +83,7 @@ class CiscoLiveBaseIE(InfoExtractor): class CiscoLiveSessionIE(CiscoLiveBaseIE): - _VALID_URL = r'https?://(?:www\.)?ciscolive\.com/[^#]*#/session/(?P[^/?&]+)' + _VALID_URL = r'https?://(?:www\.)?ciscolive(?:\.cisco)?\.com/[^#]*#/session/(?P[^/?&]+)' _TESTS = [{ 'url': 'https://www.ciscolive.com/on-demand/on-demand-library.html?search=#/session/16360600004400017rMx', 'md5': 'e0f5b0b2927b586ebff619294fec6926', @@ -109,14 +110,11 @@ class CiscoLiveSessionIE(CiscoLiveBaseIE): def _real_extract(self, url): rf_id = self._match_id(url) rf_result = self._call_api('session', rf_id, {'id': rf_id}, url) - if int(rf_result['responseCode']) != 0: - raise ExtractorError( - 'Rainfocus session api returned a non success responseCode: %s. api keys might be invalid' % rf_result['responseCode'], expected=True) return self._parse_rf_item(rf_result['items'][0]) class CiscoLiveSearchIE(CiscoLiveBaseIE): - _VALID_URL = r'https?://(?:www\.)?ciscolive\.com/(?:global|on-demand/)?on-demand-library(?:\.html|/)' + _VALID_URL = r'https?://(?:www\.)?ciscolive(?:\.cisco)?\.com/(?:global/|on-demand/)?on-demand-library(?:\.html|/)' _TESTS = [{ 'url': 'https://www.ciscolive.com/on-demand/on-demand-library.html?search.event=1636046385176005FbBU&search.technology=scpsTechnology_dataCenter&search.technicallevel=scpsSkillLevel_aintroductory#/', 'info_dict': { @@ -147,7 +145,7 @@ class CiscoLiveSearchIE(CiscoLiveBaseIE): 'Downloading search JSON page %d' % page_num) if int(results['totalSearchItems']) == 0: raise ExtractorError( - 'Search api returned 0 items (if matches are expected rfApiProfileId may be invalid)', + 'Search api returned no items (if matches are expected rfApiProfileId may be invalid)', expected=True) sl = try_get(results, lambda x: x['sectionList'][0], dict) if sl: From dd2ee5e071ec633d9bf5c3e26502e1aae34dfcd7 Mon Sep 17 00:00:00 2001 From: Chris W Date: Fri, 10 May 2024 23:28:36 +0100 Subject: [PATCH 3/5] [ciscolive] fix search --- youtube_dl/extractor/ciscolive.py | 52 +++++++++++++------------------ 1 file changed, 21 insertions(+), 31 deletions(-) diff --git a/youtube_dl/extractor/ciscolive.py b/youtube_dl/extractor/ciscolive.py index b41f51111..23f17eedc 100644 --- a/youtube_dl/extractor/ciscolive.py +++ b/youtube_dl/extractor/ciscolive.py @@ -116,11 +116,11 @@ class CiscoLiveSessionIE(CiscoLiveBaseIE): class CiscoLiveSearchIE(CiscoLiveBaseIE): _VALID_URL = r'https?://(?:www\.)?ciscolive(?:\.cisco)?\.com/(?:global/|on-demand/)?on-demand-library(?:\.html|/)' _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': { '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#/', }, { @@ -137,35 +137,25 @@ class CiscoLiveSearchIE(CiscoLiveBaseIE): return int_or_none(try_get(rf_item, lambda x: x['videos'][0]['url'])) is not None def _entries(self, query, url): - query['size'] = 50 - query['from'] = 0 - for page_num in itertools.count(1): - results = self._call_api( - 'search', None, query, url, - 'Downloading search JSON page %d' % page_num) - 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'][0], dict) - if sl: - results = sl - items = results.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) - 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'] + 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) def _real_extract(self, url): query = compat_parse_qs(compat_urllib_parse_urlparse(url).query) From 3fa061e297b4fc9d9063bbea93bc7121fa10b1da Mon Sep 17 00:00:00 2001 From: dirkf Date: Tue, 14 May 2024 11:38:55 +0100 Subject: [PATCH 4/5] Give lint a chance All we are saying is ... --- youtube_dl/extractor/ciscolive.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/youtube_dl/extractor/ciscolive.py b/youtube_dl/extractor/ciscolive.py index 23f17eedc..7dd61092d 100644 --- a/youtube_dl/extractor/ciscolive.py +++ b/youtube_dl/extractor/ciscolive.py @@ -1,8 +1,6 @@ # coding: utf-8 from __future__ import unicode_literals -import itertools - from .common import InfoExtractor from ..compat import ( compat_parse_qs, From 43fe4b597f502273cce97c9d1a181f1847288c84 Mon Sep 17 00:00:00 2001 From: dirkf Date: Wed, 15 May 2024 17:12:10 +0100 Subject: [PATCH 5/5] [workflows/ci.yml] Temporary workaround for Python 3.5 _pip_ failures --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 93562afd7..d3b9ae016 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -159,6 +159,9 @@ jobs: # wrap broken actions/setup-python@v4 # NB may run apt-get install in Linux uses: ytdl-org/setup-python@v1 + env: + # Temporary workaround for Python 3.5 failures - May 2024 + PIP_TRUSTED_HOST: "pypi.python.org pypi.org files.pythonhosted.org" with: python-version: ${{ matrix.python-version }} cache-build: true