1
1
mirror of https://github.com/ytdl-org/youtube-dl synced 2024-11-18 12:39:26 +01:00

[ciscolive] Fix issues and improve extraction (closes #17984)

This commit is contained in:
Sergey M․ 2018-11-21 05:25:43 +07:00
parent 05bd5e9c77
commit 6a6d7f0641
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D
2 changed files with 87 additions and 94 deletions

View File

@ -1,84 +1,49 @@
# coding: utf-8 # coding: utf-8
from __future__ import unicode_literals from __future__ import unicode_literals
import re
from .common import InfoExtractor from .common import InfoExtractor
from ..compat import ( from ..compat import (
compat_parse_qs,
compat_urllib_parse_urlparse, compat_urllib_parse_urlparse,
compat_parse_qs
) )
from ..utils import ( from ..utils import (
clean_html, clean_html,
float_or_none,
int_or_none, int_or_none,
try_get, try_get,
urlencode_postdata, urlencode_postdata,
) )
class CiscoLiveIE(InfoExtractor): class CiscoLiveBaseIE(InfoExtractor):
IE_NAME = 'ciscolive'
_VALID_URL = r'(?:https?://)?ciscolive\.cisco\.com/on-demand-library/\??(?P<query>[^#]+)#/(?:session/(?P<id>.+))?$'
_TESTS = [
{
'url': 'https://ciscolive.cisco.com/on-demand-library/?#/session/1423353499155001FoSs',
'md5': 'c98acf395ed9c9f766941c70f5352e22',
'info_dict': {
'id': '5803694304001',
'ext': 'mp4',
'title': '13 Smart Automations to Monitor Your Cisco IOS Network',
'description': 'md5:ec4a436019e09a918dec17714803f7cc',
'timestamp': 1530305395,
'uploader_id': '5647924234001',
'upload_date': '20180629',
'location': '16B Mezz.',
},
},
{
'url': 'https://ciscolive.cisco.com/on-demand-library/?search.event=ciscoliveus2018&search.technicallevel=scpsSkillLevel_aintroductory&search.focus=scpsSessionFocus_designAndDeployment#/',
'md5': '993d4cf051f6174059328b1dce8e94bd',
'info_dict': {
'upload_date': '20180629',
'title': 'DevNet Panel-Applying Design Thinking to Building Products in Cisco',
'timestamp': 1530316421,
'uploader_id': '5647924234001',
'id': '5803751616001',
'description': 'md5:5f144575cd6848117fe2f756855b038b',
'location': 'WoS, DevNet Theater',
'ext': 'mp4',
},
},
{
'url': 'https://ciscolive.cisco.com/on-demand-library/?search.technology=scpsTechnology_applicationDevelopment&search.technology=scpsTechnology_ipv6&search.focus=scpsSessionFocus_troubleshootingTroubleshooting#/',
'md5': '80e0c3b87e373fe3a3316b934b8915bf',
'info_dict': {
'upload_date': '20180629',
'title': 'Beating the CCIE Routing & Switching',
'timestamp': 1530311842,
'uploader_id': '5647924234001',
'id': '5803735679001',
'description': 'md5:e71970799e92d7f5ff57ae23f64b0929',
'location': 'Tulúm 02',
'ext': 'mp4',
},
}
]
# These appear to be constant across all Cisco Live presentations # These appear to be constant across all Cisco Live presentations
# and are not tied to any user session or event # and are not tied to any user session or event
RAINFOCUS_API_URL = 'https://events.rainfocus.com/api/%s' RAINFOCUS_API_URL = 'https://events.rainfocus.com/api/%s'
RAINFOCUS_APIPROFILEID = 'Na3vqYdAlJFSxhYTYQGuMbpafMqftalz' RAINFOCUS_API_PROFILE_ID = 'Na3vqYdAlJFSxhYTYQGuMbpafMqftalz'
RAINFOCUS_WIDGETID = 'n6l4Lo05R8fiy3RpUBm447dZN8uNWoye' RAINFOCUS_WIDGET_ID = 'n6l4Lo05R8fiy3RpUBm447dZN8uNWoye'
BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/5647924234001/SyK2FdqjM_default/index.html?videoId=%s' BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/5647924234001/SyK2FdqjM_default/index.html?videoId=%s'
HEADERS = {
'Origin': 'https://ciscolive.cisco.com',
'rfApiProfileId': RAINFOCUS_API_PROFILE_ID,
'rfWidgetId': RAINFOCUS_WIDGET_ID,
}
def _call_api(self, ep, rf_id, query, referrer):
headers = self.HEADERS.copy()
headers['Referer'] = referrer
return self._download_json(
self.RAINFOCUS_API_URL % ep, rf_id, data=urlencode_postdata(query),
headers=headers)
def _parse_rf_item(self, rf_item): def _parse_rf_item(self, rf_item):
''' Parses metadata and passes to Brightcove extractor '''
event_name = rf_item.get('eventName') event_name = rf_item.get('eventName')
title = rf_item['title'] title = rf_item['title']
description = clean_html(rf_item.get('abstract')) description = clean_html(rf_item.get('abstract'))
presenter_name = try_get(rf_item, lambda x: x['participants'][0]['fullName']) presenter_name = try_get(rf_item, lambda x: x['participants'][0]['fullName'])
bc_id = rf_item['videos'][0]['url'] bc_id = rf_item['videos'][0]['url']
bc_url = self.BRIGHTCOVE_URL_TEMPLATE % bc_id bc_url = self.BRIGHTCOVE_URL_TEMPLATE % bc_id
duration = int_or_none(try_get(rf_item, lambda x: x['times'][0]['length'])) duration = float_or_none(try_get(rf_item, lambda x: x['times'][0]['length']))
location = try_get(rf_item, lambda x: x['times'][0]['room']) location = try_get(rf_item, lambda x: x['times'][0]['room'])
if duration: if duration:
@ -86,51 +51,76 @@ class CiscoLiveIE(InfoExtractor):
return { return {
'_type': 'url_transparent', '_type': 'url_transparent',
'creator': presenter_name, 'url': bc_url,
'ie_key': 'BrightcoveNew',
'title': title,
'description': description, 'description': description,
'duration': duration, 'duration': duration,
'ie_key': 'BrightcoveNew', 'creator': presenter_name,
'location': location, 'location': location,
'series': event_name, 'series': event_name,
'title': title,
'url': bc_url,
} }
def _check_bc_id_exists(self, rf_item):
''' Checks for the existence of a Brightcove URL in an API result ''' class CiscoLiveSessionIE(CiscoLiveBaseIE):
bc_id = try_get(rf_item, lambda x: x['videos'][0]['url']) _VALID_URL = r'https?://ciscolive\.cisco\.com/on-demand-library/\??[^#]*#/session/(?P<id>[^/?&]+)'
if bc_id: _TEST = {
if bc_id.strip().isdigit(): 'url': 'https://ciscolive.cisco.com/on-demand-library/?#/session/1423353499155001FoSs',
return rf_item 'md5': 'c98acf395ed9c9f766941c70f5352e22',
'info_dict': {
'id': '5803694304001',
'ext': 'mp4',
'title': '13 Smart Automations to Monitor Your Cisco IOS Network',
'description': 'md5:ec4a436019e09a918dec17714803f7cc',
'timestamp': 1530305395,
'upload_date': '20180629',
'uploader_id': '5647924234001',
'location': '16B Mezz.',
},
'params': {
'proxy': '127.0.0.1:8118',
}
}
def _real_extract(self, url): def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url) rf_id = self._match_id(url)
HEADERS = { rf_result = self._call_api('session', rf_id, {'id': rf_id}, url)
'Origin': 'https://ciscolive.cisco.com', return self._parse_rf_item(rf_result['items'][0])
'rfApiProfileId': self.RAINFOCUS_APIPROFILEID,
'rfWidgetId': self.RAINFOCUS_WIDGETID,
'Referer': url, class CiscoLiveSearchIE(CiscoLiveBaseIE):
_VALID_URL = r'https?://ciscolive\.cisco\.com/on-demand-library/'
_TESTS = [{
'url': 'https://ciscolive.cisco.com/on-demand-library/?search.event=ciscoliveus2018&search.technicallevel=scpsSkillLevel_aintroductory&search.focus=scpsSessionFocus_designAndDeployment#/',
'info_dict': {
'title': 'Filter query',
},
'playlist_count': 5,
'params': {
'proxy': '127.0.0.1:8118',
} }
# Single session URL (single video) }, {
if mobj.group('id'): 'url': 'https://ciscolive.cisco.com/on-demand-library/?search.technology=scpsTechnology_applicationDevelopment&search.technology=scpsTechnology_ipv6&search.focus=scpsSessionFocus_troubleshootingTroubleshooting#/',
rf_id = mobj.group('id') 'only_matching': True,
request = self.RAINFOCUS_API_URL % 'session' }]
data = urlencode_postdata({'id': rf_id})
rf_result = self._download_json(request, rf_id, data=data, headers=HEADERS) @classmethod
rf_item = self._check_bc_id_exists(rf_result['items'][0]) def suitable(cls, url):
return self._parse_rf_item(rf_item) return False if CiscoLiveSessionIE.suitable(url) else super(CiscoLiveSearchIE, cls).suitable(url)
else:
# Filter query URL (multiple videos) @staticmethod
rf_query = compat_parse_qs((compat_urllib_parse_urlparse(url).query)) def _check_bc_id_exists(rf_item):
rf_query['type'] = 'session' return int_or_none(try_get(rf_item, lambda x: x['videos'][0]['url'])) is not None
rf_query['size'] = 1000
data = urlencode_postdata(rf_query) def _real_extract(self, url):
request = self.RAINFOCUS_API_URL % 'search' rf_query = compat_parse_qs(compat_urllib_parse_urlparse(url).query)
rf_results = self._download_json(request, 'Filter query', data=data, headers=HEADERS) rf_query['type'] = 'session'
entries = [ rf_query['size'] = 1000
self._parse_rf_item(rf_item) rf_results = self._call_api('search', None, rf_query, url)
for rf_item entries = [
in rf_results['sectionList'][0]['items'] self._parse_rf_item(rf_item)
if self._check_bc_id_exists(rf_item) for rf_item
] in rf_results['sectionList'][0]['items']
return self.playlist_result(entries, 'Filter query') if self._check_bc_id_exists(rf_item)
]
return self.playlist_result(entries, playlist_title='Filter query')

View File

@ -194,7 +194,10 @@ from .chirbit import (
ChirbitProfileIE, ChirbitProfileIE,
) )
from .cinchcast import CinchcastIE from .cinchcast import CinchcastIE
from .ciscolive import CiscoLiveIE from .ciscolive import (
CiscoLiveSessionIE,
CiscoLiveSearchIE,
)
from .cjsw import CJSWIE from .cjsw import CJSWIE
from .cliphunter import CliphunterIE from .cliphunter import CliphunterIE
from .clippit import ClippitIE from .clippit import ClippitIE