]>
Commit | Line | Data |
---|---|---|
183417a5 S |
1 | import itertools |
2 | ||
05bd5e9c | 3 | from .common import InfoExtractor |
05bd5e9c ACC |
4 | from ..utils import ( |
5 | clean_html, | |
6a6d7f06 | 6 | float_or_none, |
05bd5e9c | 7 | int_or_none, |
4dfbf869 | 8 | parse_qs, |
05bd5e9c ACC |
9 | try_get, |
10 | urlencode_postdata, | |
11 | ) | |
12 | ||
13 | ||
6a6d7f06 | 14 | class CiscoLiveBaseIE(InfoExtractor): |
05bd5e9c ACC |
15 | # These appear to be constant across all Cisco Live presentations |
16 | # and are not tied to any user session or event | |
17 | RAINFOCUS_API_URL = 'https://events.rainfocus.com/api/%s' | |
6a6d7f06 S |
18 | RAINFOCUS_API_PROFILE_ID = 'Na3vqYdAlJFSxhYTYQGuMbpafMqftalz' |
19 | RAINFOCUS_WIDGET_ID = 'n6l4Lo05R8fiy3RpUBm447dZN8uNWoye' | |
05bd5e9c ACC |
20 | BRIGHTCOVE_URL_TEMPLATE = 'http://players.brightcove.net/5647924234001/SyK2FdqjM_default/index.html?videoId=%s' |
21 | ||
6a6d7f06 S |
22 | HEADERS = { |
23 | 'Origin': 'https://ciscolive.cisco.com', | |
24 | 'rfApiProfileId': RAINFOCUS_API_PROFILE_ID, | |
25 | 'rfWidgetId': RAINFOCUS_WIDGET_ID, | |
26 | } | |
27 | ||
183417a5 | 28 | def _call_api(self, ep, rf_id, query, referrer, note=None): |
6a6d7f06 S |
29 | headers = self.HEADERS.copy() |
30 | headers['Referer'] = referrer | |
31 | return self._download_json( | |
183417a5 S |
32 | self.RAINFOCUS_API_URL % ep, rf_id, note=note, |
33 | data=urlencode_postdata(query), headers=headers) | |
6a6d7f06 | 34 | |
05bd5e9c | 35 | def _parse_rf_item(self, rf_item): |
05bd5e9c ACC |
36 | event_name = rf_item.get('eventName') |
37 | title = rf_item['title'] | |
38 | description = clean_html(rf_item.get('abstract')) | |
39 | presenter_name = try_get(rf_item, lambda x: x['participants'][0]['fullName']) | |
40 | bc_id = rf_item['videos'][0]['url'] | |
41 | bc_url = self.BRIGHTCOVE_URL_TEMPLATE % bc_id | |
6a6d7f06 | 42 | duration = float_or_none(try_get(rf_item, lambda x: x['times'][0]['length'])) |
05bd5e9c ACC |
43 | location = try_get(rf_item, lambda x: x['times'][0]['room']) |
44 | ||
45 | if duration: | |
46 | duration = duration * 60 | |
47 | ||
48 | return { | |
49 | '_type': 'url_transparent', | |
6a6d7f06 S |
50 | 'url': bc_url, |
51 | 'ie_key': 'BrightcoveNew', | |
52 | 'title': title, | |
05bd5e9c ACC |
53 | 'description': description, |
54 | 'duration': duration, | |
6a6d7f06 | 55 | 'creator': presenter_name, |
05bd5e9c ACC |
56 | 'location': location, |
57 | 'series': event_name, | |
05bd5e9c ACC |
58 | } |
59 | ||
6a6d7f06 S |
60 | |
61 | class CiscoLiveSessionIE(CiscoLiveBaseIE): | |
e5cfb779 ACC |
62 | _VALID_URL = r'https?://(?:www\.)?ciscolive(?:\.cisco)?\.com/[^#]*#/session/(?P<id>[^/?&]+)' |
63 | _TESTS = [{ | |
6a6d7f06 S |
64 | 'url': 'https://ciscolive.cisco.com/on-demand-library/?#/session/1423353499155001FoSs', |
65 | 'md5': 'c98acf395ed9c9f766941c70f5352e22', | |
66 | 'info_dict': { | |
67 | 'id': '5803694304001', | |
68 | 'ext': 'mp4', | |
69 | 'title': '13 Smart Automations to Monitor Your Cisco IOS Network', | |
70 | 'description': 'md5:ec4a436019e09a918dec17714803f7cc', | |
71 | 'timestamp': 1530305395, | |
72 | 'upload_date': '20180629', | |
73 | 'uploader_id': '5647924234001', | |
74 | 'location': '16B Mezz.', | |
75 | }, | |
e5cfb779 ACC |
76 | }, { |
77 | 'url': 'https://www.ciscolive.com/global/on-demand-library.html?search.event=ciscoliveemea2019#/session/15361595531500013WOU', | |
78 | 'only_matching': True, | |
79 | }, { | |
80 | 'url': 'https://www.ciscolive.com/global/on-demand-library.html?#/session/1490051371645001kNaS', | |
81 | 'only_matching': True, | |
82 | }] | |
05bd5e9c ACC |
83 | |
84 | def _real_extract(self, url): | |
6a6d7f06 S |
85 | rf_id = self._match_id(url) |
86 | rf_result = self._call_api('session', rf_id, {'id': rf_id}, url) | |
87 | return self._parse_rf_item(rf_result['items'][0]) | |
88 | ||
89 | ||
90 | class CiscoLiveSearchIE(CiscoLiveBaseIE): | |
e5cfb779 | 91 | _VALID_URL = r'https?://(?:www\.)?ciscolive(?:\.cisco)?\.com/(?:global/)?on-demand-library(?:\.html|/)' |
6a6d7f06 S |
92 | _TESTS = [{ |
93 | 'url': 'https://ciscolive.cisco.com/on-demand-library/?search.event=ciscoliveus2018&search.technicallevel=scpsSkillLevel_aintroductory&search.focus=scpsSessionFocus_designAndDeployment#/', | |
94 | 'info_dict': { | |
183417a5 | 95 | 'title': 'Search query', |
6a6d7f06 S |
96 | }, |
97 | 'playlist_count': 5, | |
6a6d7f06 S |
98 | }, { |
99 | 'url': 'https://ciscolive.cisco.com/on-demand-library/?search.technology=scpsTechnology_applicationDevelopment&search.technology=scpsTechnology_ipv6&search.focus=scpsSessionFocus_troubleshootingTroubleshooting#/', | |
100 | 'only_matching': True, | |
e5cfb779 ACC |
101 | }, { |
102 | '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#/', | |
103 | 'only_matching': True, | |
6a6d7f06 S |
104 | }] |
105 | ||
106 | @classmethod | |
107 | def suitable(cls, url): | |
108 | return False if CiscoLiveSessionIE.suitable(url) else super(CiscoLiveSearchIE, cls).suitable(url) | |
109 | ||
110 | @staticmethod | |
111 | def _check_bc_id_exists(rf_item): | |
112 | return int_or_none(try_get(rf_item, lambda x: x['videos'][0]['url'])) is not None | |
113 | ||
183417a5 S |
114 | def _entries(self, query, url): |
115 | query['size'] = 50 | |
116 | query['from'] = 0 | |
117 | for page_num in itertools.count(1): | |
118 | results = self._call_api( | |
119 | 'search', None, query, url, | |
120 | 'Downloading search JSON page %d' % page_num) | |
121 | sl = try_get(results, lambda x: x['sectionList'][0], dict) | |
122 | if sl: | |
123 | results = sl | |
124 | items = results.get('items') | |
125 | if not items or not isinstance(items, list): | |
126 | break | |
127 | for item in items: | |
128 | if not isinstance(item, dict): | |
129 | continue | |
130 | if not self._check_bc_id_exists(item): | |
131 | continue | |
132 | yield self._parse_rf_item(item) | |
133 | size = int_or_none(results.get('size')) | |
134 | if size is not None: | |
135 | query['size'] = size | |
136 | total = int_or_none(results.get('total')) | |
137 | if total is not None and query['from'] + query['size'] > total: | |
138 | break | |
139 | query['from'] += query['size'] | |
140 | ||
6a6d7f06 | 141 | def _real_extract(self, url): |
4dfbf869 | 142 | query = parse_qs(url) |
183417a5 S |
143 | query['type'] = 'session' |
144 | return self.playlist_result( | |
145 | self._entries(query, url), playlist_title='Search query') |