]>
Commit | Line | Data |
---|---|---|
1 | import calendar | |
2 | import datetime as dt | |
3 | import functools | |
4 | import json | |
5 | import random | |
6 | ||
7 | from .common import InfoExtractor | |
8 | from ..compat import ( | |
9 | compat_urllib_parse_urlparse, | |
10 | compat_urlparse | |
11 | ) | |
12 | ||
13 | from ..utils import ( | |
14 | bug_reports_message, | |
15 | ExtractorError, | |
16 | get_first, | |
17 | int_or_none, | |
18 | OnDemandPagedList, | |
19 | parse_qs, | |
20 | srt_subtitles_timecode, | |
21 | traverse_obj, | |
22 | ) | |
23 | ||
24 | ||
25 | class PanoptoBaseIE(InfoExtractor): | |
26 | BASE_URL_RE = r'(?P<base_url>https?://[\w.-]+\.panopto.(?:com|eu)/Panopto)' | |
27 | ||
28 | # see panopto core.js | |
29 | _SUB_LANG_MAPPING = { | |
30 | 0: 'en-US', | |
31 | 1: 'en-GB', | |
32 | 2: 'es-MX', | |
33 | 3: 'es-ES', | |
34 | 4: 'de-DE', | |
35 | 5: 'fr-FR', | |
36 | 6: 'nl-NL', | |
37 | 7: 'th-TH', | |
38 | 8: 'zh-CN', | |
39 | 9: 'zh-TW', | |
40 | 10: 'ko-KR', | |
41 | 11: 'ja-JP', | |
42 | 12: 'ru-RU', | |
43 | 13: 'pt-PT', | |
44 | 14: 'pl-PL', | |
45 | 15: 'en-AU', | |
46 | 16: 'da-DK', | |
47 | 17: 'fi-FI', | |
48 | 18: 'hu-HU', | |
49 | 19: 'nb-NO', | |
50 | 20: 'sv-SE', | |
51 | 21: 'it-IT' | |
52 | } | |
53 | ||
54 | def _call_api(self, base_url, path, video_id, data=None, fatal=True, **kwargs): | |
55 | response = self._download_json( | |
56 | base_url + path, video_id, data=json.dumps(data).encode('utf8') if data else None, | |
57 | fatal=fatal, headers={'accept': 'application/json', 'content-type': 'application/json'}, **kwargs) | |
58 | if not response: | |
59 | return | |
60 | error_code = traverse_obj(response, 'ErrorCode') | |
61 | if error_code == 2: | |
62 | self.raise_login_required(method='cookies') | |
63 | elif error_code is not None: | |
64 | msg = f'Panopto said: {response.get("ErrorMessage")}' | |
65 | if fatal: | |
66 | raise ExtractorError(msg, video_id=video_id, expected=True) | |
67 | else: | |
68 | self.report_warning(msg, video_id=video_id) | |
69 | return response | |
70 | ||
71 | @staticmethod | |
72 | def _parse_fragment(url): | |
73 | return {k: json.loads(v[0]) for k, v in compat_urlparse.parse_qs(compat_urllib_parse_urlparse(url).fragment).items()} | |
74 | ||
75 | ||
76 | class PanoptoIE(PanoptoBaseIE): | |
77 | _VALID_URL = PanoptoBaseIE.BASE_URL_RE + r'/Pages/(Viewer|Embed)\.aspx.*(?:\?|&)id=(?P<id>[a-f0-9-]+)' | |
78 | _EMBED_REGEX = [rf'<iframe[^>]+src=["\'](?P<url>{PanoptoBaseIE.BASE_URL_RE}/Pages/(Viewer|Embed|Sessions/List)\.aspx[^"\']+)'] | |
79 | _TESTS = [ | |
80 | { | |
81 | 'url': 'https://demo.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=26b3ae9e-4a48-4dcc-96ba-0befba08a0fb', | |
82 | 'info_dict': { | |
83 | 'id': '26b3ae9e-4a48-4dcc-96ba-0befba08a0fb', | |
84 | 'title': 'Panopto for Business - Use Cases', | |
85 | 'timestamp': 1459184200, | |
86 | 'thumbnail': r're:https://demo\.hosted\.panopto\.com/.+', | |
87 | 'upload_date': '20160328', | |
88 | 'ext': 'mp4', | |
89 | 'cast': [], | |
90 | 'chapters': [], | |
91 | 'duration': 88.17099999999999, | |
92 | 'average_rating': int, | |
93 | 'uploader_id': '2db6b718-47a0-4b0b-9e17-ab0b00f42b1e', | |
94 | 'channel_id': 'e4c6a2fc-1214-4ca0-8fb7-aef2e29ff63a', | |
95 | 'channel': 'Showcase Videos' | |
96 | }, | |
97 | }, | |
98 | { | |
99 | 'url': 'https://demo.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=ed01b077-c9e5-4c7b-b8ff-15fa306d7a59', | |
100 | 'info_dict': { | |
101 | 'id': 'ed01b077-c9e5-4c7b-b8ff-15fa306d7a59', | |
102 | 'title': 'Overcoming Top 4 Challenges of Enterprise Video', | |
103 | 'uploader': 'Panopto Support', | |
104 | 'timestamp': 1449409251, | |
105 | 'thumbnail': r're:https://demo\.hosted\.panopto\.com/.+', | |
106 | 'upload_date': '20151206', | |
107 | 'ext': 'mp4', | |
108 | 'chapters': 'count:12', | |
109 | 'cast': ['Panopto Support'], | |
110 | 'uploader_id': 'a96d1a31-b4de-489b-9eee-b4a5b414372c', | |
111 | 'average_rating': int, | |
112 | 'description': 'md5:4391837802b3fc856dadf630c4b375d1', | |
113 | 'duration': 1088.2659999999998, | |
114 | 'channel_id': '9f3c1921-43bb-4bda-8b3a-b8d2f05a8546', | |
115 | 'channel': 'Webcasts', | |
116 | }, | |
117 | }, | |
118 | { | |
119 | # Extra params in URL | |
120 | 'url': 'https://howtovideos.hosted.panopto.com/Panopto/Pages/Viewer.aspx?randomparam=thisisnotreal&id=5fa74e93-3d87-4694-b60e-aaa4012214ed&advance=true', | |
121 | 'info_dict': { | |
122 | 'id': '5fa74e93-3d87-4694-b60e-aaa4012214ed', | |
123 | 'ext': 'mp4', | |
124 | 'duration': 129.513, | |
125 | 'cast': ['Kathryn Kelly'], | |
126 | 'uploader_id': '316a0a58-7fa2-4cd9-be1c-64270d284a56', | |
127 | 'timestamp': 1569845768, | |
128 | 'tags': ['Viewer', 'Enterprise'], | |
129 | 'chapters': [], | |
130 | 'upload_date': '20190930', | |
131 | 'thumbnail': r're:https://howtovideos\.hosted\.panopto\.com/.+', | |
132 | 'description': 'md5:2d844aaa1b1a14ad0e2601a0993b431f', | |
133 | 'title': 'Getting Started: View a Video', | |
134 | 'average_rating': int, | |
135 | 'uploader': 'Kathryn Kelly', | |
136 | 'channel_id': 'fb93bc3c-6750-4b80-a05b-a921013735d3', | |
137 | 'channel': 'Getting Started', | |
138 | } | |
139 | }, | |
140 | { | |
141 | # Does not allow normal Viewer.aspx. AUDIO livestream has no url, so should be skipped and only give one stream. | |
142 | 'url': 'https://unisa.au.panopto.com/Panopto/Pages/Embed.aspx?id=9d9a0fa3-e99a-4ebd-a281-aac2017f4da4', | |
143 | 'info_dict': { | |
144 | 'id': '9d9a0fa3-e99a-4ebd-a281-aac2017f4da4', | |
145 | 'ext': 'mp4', | |
146 | 'cast': ['LTS CLI Script'], | |
147 | 'chapters': [], | |
148 | 'duration': 2178.45, | |
149 | 'description': 'md5:ee5cf653919f55b72bce2dbcf829c9fa', | |
150 | 'channel_id': 'b23e673f-c287-4cb1-8344-aae9005a69f8', | |
151 | 'average_rating': int, | |
152 | 'uploader_id': '38377323-6a23-41e2-9ff6-a8e8004bf6f7', | |
153 | 'uploader': 'LTS CLI Script', | |
154 | 'timestamp': 1572458134, | |
155 | 'title': 'WW2 Vets Interview 3 Ronald Stanley George', | |
156 | 'thumbnail': r're:https://unisa\.au\.panopto\.com/.+', | |
157 | 'channel': 'World War II Veteran Interviews', | |
158 | 'upload_date': '20191030', | |
159 | }, | |
160 | }, | |
161 | { | |
162 | # Slides/storyboard | |
163 | 'url': 'https://demo.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=a7f12f1d-3872-4310-84b0-f8d8ab15326b', | |
164 | 'info_dict': { | |
165 | 'id': 'a7f12f1d-3872-4310-84b0-f8d8ab15326b', | |
166 | 'ext': 'mhtml', | |
167 | 'timestamp': 1448798857, | |
168 | 'duration': 4712.681, | |
169 | 'title': 'Cache Memory - CompSci 15-213, Lecture 12', | |
170 | 'channel_id': 'e4c6a2fc-1214-4ca0-8fb7-aef2e29ff63a', | |
171 | 'uploader_id': 'a96d1a31-b4de-489b-9eee-b4a5b414372c', | |
172 | 'upload_date': '20151129', | |
173 | 'average_rating': 0, | |
174 | 'uploader': 'Panopto Support', | |
175 | 'channel': 'Showcase Videos', | |
176 | 'description': 'md5:55e51d54233ddb0e6c2ed388ca73822c', | |
177 | 'cast': ['ISR Videographer', 'Panopto Support'], | |
178 | 'chapters': 'count:28', | |
179 | 'thumbnail': r're:https://demo\.hosted\.panopto\.com/.+', | |
180 | }, | |
181 | 'params': {'format': 'mhtml', 'skip_download': True} | |
182 | }, | |
183 | { | |
184 | 'url': 'https://na-training-1.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=8285224a-9a2b-4957-84f2-acb0000c4ea9', | |
185 | 'info_dict': { | |
186 | 'id': '8285224a-9a2b-4957-84f2-acb0000c4ea9', | |
187 | 'ext': 'mp4', | |
188 | 'chapters': [], | |
189 | 'title': 'Company Policy', | |
190 | 'average_rating': 0, | |
191 | 'timestamp': 1615058901, | |
192 | 'channel': 'Human Resources', | |
193 | 'tags': ['HumanResources'], | |
194 | 'duration': 1604.243, | |
195 | 'thumbnail': r're:https://na-training-1\.hosted\.panopto\.com/.+', | |
196 | 'uploader_id': '8e8ba0a3-424f-40df-a4f1-ab3a01375103', | |
197 | 'uploader': 'Cait M.', | |
198 | 'upload_date': '20210306', | |
199 | 'cast': ['Cait M.'], | |
200 | 'subtitles': {'en-US': [{'ext': 'srt', 'data': 'md5:a3f4d25963fdeace838f327097c13265'}], | |
201 | 'es-ES': [{'ext': 'srt', 'data': 'md5:57e9dad365fd0fbaf0468eac4949f189'}]}, | |
202 | }, | |
203 | 'params': {'writesubtitles': True, 'skip_download': True} | |
204 | }, { | |
205 | # On Panopto there are two subs: "Default" and en-US. en-US is blank and should be skipped. | |
206 | 'url': 'https://na-training-1.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=940cbd41-f616-4a45-b13e-aaf1000c915b', | |
207 | 'info_dict': { | |
208 | 'id': '940cbd41-f616-4a45-b13e-aaf1000c915b', | |
209 | 'ext': 'mp4', | |
210 | 'subtitles': 'count:1', | |
211 | 'title': 'HR Benefits Review Meeting*', | |
212 | 'cast': ['Panopto Support'], | |
213 | 'chapters': [], | |
214 | 'timestamp': 1575024251, | |
215 | 'thumbnail': r're:https://na-training-1\.hosted\.panopto\.com/.+', | |
216 | 'channel': 'Zoom', | |
217 | 'description': 'md5:04f90a9c2c68b7828144abfb170f0106', | |
218 | 'uploader': 'Panopto Support', | |
219 | 'average_rating': 0, | |
220 | 'duration': 409.34499999999997, | |
221 | 'uploader_id': 'b6ac04ad-38b8-4724-a004-a851004ea3df', | |
222 | 'upload_date': '20191129', | |
223 | ||
224 | }, | |
225 | 'params': {'writesubtitles': True, 'skip_download': True} | |
226 | }, | |
227 | { | |
228 | 'url': 'https://ucc.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=0e8484a4-4ceb-4d98-a63f-ac0200b455cb', | |
229 | 'only_matching': True | |
230 | }, | |
231 | { | |
232 | 'url': 'https://brown.hosted.panopto.com/Panopto/Pages/Embed.aspx?id=0b3ff73b-36a0-46c5-8455-aadf010a3638', | |
233 | 'only_matching': True | |
234 | }, | |
235 | ] | |
236 | ||
237 | @classmethod | |
238 | def suitable(cls, url): | |
239 | return False if PanoptoPlaylistIE.suitable(url) else super().suitable(url) | |
240 | ||
241 | def _mark_watched(self, base_url, video_id, delivery_info): | |
242 | duration = traverse_obj(delivery_info, ('Delivery', 'Duration'), expected_type=float) | |
243 | invocation_id = delivery_info.get('InvocationId') | |
244 | stream_id = traverse_obj(delivery_info, ('Delivery', 'Streams', ..., 'PublicID'), get_all=False, expected_type=str) | |
245 | if invocation_id and stream_id and duration: | |
246 | timestamp_str = f'/Date({calendar.timegm(dt.datetime.now(dt.timezone.utc).timetuple())}000)/' | |
247 | data = { | |
248 | 'streamRequests': [ | |
249 | { | |
250 | 'ClientTimeStamp': timestamp_str, | |
251 | 'ID': 0, | |
252 | 'InvocationID': invocation_id, | |
253 | 'PlaybackSpeed': 1, | |
254 | 'SecondsListened': duration - 1, | |
255 | 'SecondsRejected': 0, | |
256 | 'StartPosition': 0, | |
257 | 'StartReason': 2, | |
258 | 'StopReason': None, | |
259 | 'StreamID': stream_id, | |
260 | 'TimeStamp': timestamp_str, | |
261 | 'UpdatesRejected': 0 | |
262 | }, | |
263 | ]} | |
264 | ||
265 | self._download_webpage( | |
266 | base_url + '/Services/Analytics.svc/AddStreamRequests', video_id, | |
267 | fatal=False, data=json.dumps(data).encode('utf8'), headers={'content-type': 'application/json'}, | |
268 | note='Marking watched', errnote='Unable to mark watched') | |
269 | ||
270 | @staticmethod | |
271 | def _extract_chapters(timestamps): | |
272 | chapters = [] | |
273 | for timestamp in timestamps or []: | |
274 | caption = timestamp.get('Caption') | |
275 | start, duration = int_or_none(timestamp.get('Time')), int_or_none(timestamp.get('Duration')) | |
276 | if not caption or start is None or duration is None: | |
277 | continue | |
278 | chapters.append({ | |
279 | 'start_time': start, | |
280 | 'end_time': start + duration, | |
281 | 'title': caption | |
282 | }) | |
283 | return chapters | |
284 | ||
285 | @staticmethod | |
286 | def _extract_mhtml_formats(base_url, timestamps): | |
287 | image_frags = {} | |
288 | for timestamp in timestamps or []: | |
289 | duration = timestamp.get('Duration') | |
290 | obj_id, obj_sn = timestamp.get('ObjectIdentifier'), timestamp.get('ObjectSequenceNumber'), | |
291 | if timestamp.get('EventTargetType') == 'PowerPoint' and obj_id is not None and obj_sn is not None: | |
292 | image_frags.setdefault('slides', []).append({ | |
293 | 'url': base_url + f'/Pages/Viewer/Image.aspx?id={obj_id}&number={obj_sn}', | |
294 | 'duration': duration | |
295 | }) | |
296 | ||
297 | obj_pid, session_id, abs_time = timestamp.get('ObjectPublicIdentifier'), timestamp.get('SessionID'), timestamp.get('AbsoluteTime') | |
298 | if None not in (obj_pid, session_id, abs_time): | |
299 | image_frags.setdefault('chapter', []).append({ | |
300 | 'url': base_url + f'/Pages/Viewer/Thumb.aspx?eventTargetPID={obj_pid}&sessionPID={session_id}&number={obj_sn}&isPrimary=false&absoluteTime={abs_time}', | |
301 | 'duration': duration, | |
302 | }) | |
303 | for name, fragments in image_frags.items(): | |
304 | yield { | |
305 | 'format_id': name, | |
306 | 'ext': 'mhtml', | |
307 | 'protocol': 'mhtml', | |
308 | 'acodec': 'none', | |
309 | 'vcodec': 'none', | |
310 | 'url': 'about:invalid', | |
311 | 'fragments': fragments | |
312 | } | |
313 | ||
314 | @staticmethod | |
315 | def _json2srt(data, delivery): | |
316 | def _gen_lines(): | |
317 | for i, line in enumerate(data): | |
318 | start_time = line['Time'] | |
319 | duration = line.get('Duration') | |
320 | if duration: | |
321 | end_time = start_time + duration | |
322 | else: | |
323 | end_time = traverse_obj(data, (i + 1, 'Time')) or delivery['Duration'] | |
324 | yield f'{i + 1}\n{srt_subtitles_timecode(start_time)} --> {srt_subtitles_timecode(end_time)}\n{line["Caption"]}' | |
325 | return '\n\n'.join(_gen_lines()) | |
326 | ||
327 | def _get_subtitles(self, base_url, video_id, delivery): | |
328 | subtitles = {} | |
329 | for lang in delivery.get('AvailableLanguages') or []: | |
330 | response = self._call_api( | |
331 | base_url, '/Pages/Viewer/DeliveryInfo.aspx', video_id, fatal=False, | |
332 | note='Downloading captions JSON metadata', query={ | |
333 | 'deliveryId': video_id, | |
334 | 'getCaptions': True, | |
335 | 'language': str(lang), | |
336 | 'responseType': 'json' | |
337 | } | |
338 | ) | |
339 | if not isinstance(response, list): | |
340 | continue | |
341 | subtitles.setdefault(self._SUB_LANG_MAPPING.get(lang) or 'default', []).append({ | |
342 | 'ext': 'srt', | |
343 | 'data': self._json2srt(response, delivery), | |
344 | }) | |
345 | return subtitles | |
346 | ||
347 | def _extract_streams_formats_and_subtitles(self, video_id, streams, **fmt_kwargs): | |
348 | formats = [] | |
349 | subtitles = {} | |
350 | for stream in streams or []: | |
351 | stream_formats = [] | |
352 | http_stream_url = stream.get('StreamHttpUrl') | |
353 | stream_url = stream.get('StreamUrl') | |
354 | ||
355 | if http_stream_url: | |
356 | stream_formats.append({'url': http_stream_url}) | |
357 | ||
358 | if stream_url: | |
359 | media_type = stream.get('ViewerMediaFileTypeName') | |
360 | if media_type in ('hls', ): | |
361 | m3u8_formats, stream_subtitles = self._extract_m3u8_formats_and_subtitles(stream_url, video_id) | |
362 | stream_formats.extend(m3u8_formats) | |
363 | subtitles = self._merge_subtitles(subtitles, stream_subtitles) | |
364 | else: | |
365 | stream_formats.append({ | |
366 | 'url': stream_url | |
367 | }) | |
368 | for fmt in stream_formats: | |
369 | fmt.update({ | |
370 | 'format_note': stream.get('Tag'), | |
371 | **fmt_kwargs | |
372 | }) | |
373 | formats.extend(stream_formats) | |
374 | ||
375 | return formats, subtitles | |
376 | ||
377 | def _real_extract(self, url): | |
378 | base_url, video_id = self._match_valid_url(url).group('base_url', 'id') | |
379 | delivery_info = self._call_api( | |
380 | base_url, '/Pages/Viewer/DeliveryInfo.aspx', video_id, | |
381 | query={ | |
382 | 'deliveryId': video_id, | |
383 | 'invocationId': '', | |
384 | 'isLiveNotes': 'false', | |
385 | 'refreshAuthCookie': 'true', | |
386 | 'isActiveBroadcast': 'false', | |
387 | 'isEditing': 'false', | |
388 | 'isKollectiveAgentInstalled': 'false', | |
389 | 'isEmbed': 'false', | |
390 | 'responseType': 'json', | |
391 | } | |
392 | ) | |
393 | ||
394 | delivery = delivery_info['Delivery'] | |
395 | session_start_time = int_or_none(delivery.get('SessionStartTime')) | |
396 | timestamps = delivery.get('Timestamps') | |
397 | ||
398 | # Podcast stream is usually the combined streams. We will prefer that by default. | |
399 | podcast_formats, podcast_subtitles = self._extract_streams_formats_and_subtitles( | |
400 | video_id, delivery.get('PodcastStreams'), format_note='PODCAST') | |
401 | ||
402 | streams_formats, streams_subtitles = self._extract_streams_formats_and_subtitles( | |
403 | video_id, delivery.get('Streams'), preference=-10) | |
404 | ||
405 | formats = podcast_formats + streams_formats | |
406 | formats.extend(self._extract_mhtml_formats(base_url, timestamps)) | |
407 | subtitles = self._merge_subtitles( | |
408 | podcast_subtitles, streams_subtitles, self.extract_subtitles(base_url, video_id, delivery)) | |
409 | ||
410 | self.mark_watched(base_url, video_id, delivery_info) | |
411 | ||
412 | return { | |
413 | 'id': video_id, | |
414 | 'title': delivery.get('SessionName'), | |
415 | 'cast': traverse_obj(delivery, ('Contributors', ..., 'DisplayName'), expected_type=lambda x: x or None), | |
416 | 'timestamp': session_start_time - 11640000000 if session_start_time else None, | |
417 | 'duration': delivery.get('Duration'), | |
418 | 'thumbnail': base_url + f'/Services/FrameGrabber.svc/FrameRedirect?objectId={video_id}&mode=Delivery&random={random.random()}', | |
419 | 'average_rating': delivery.get('AverageRating'), | |
420 | 'chapters': self._extract_chapters(timestamps), | |
421 | 'uploader': delivery.get('OwnerDisplayName') or None, | |
422 | 'uploader_id': delivery.get('OwnerId'), | |
423 | 'description': delivery.get('SessionAbstract'), | |
424 | 'tags': traverse_obj(delivery, ('Tags', ..., 'Content')), | |
425 | 'channel_id': delivery.get('SessionGroupPublicID'), | |
426 | 'channel': traverse_obj(delivery, 'SessionGroupLongName', 'SessionGroupShortName', get_all=False), | |
427 | 'formats': formats, | |
428 | 'subtitles': subtitles | |
429 | } | |
430 | ||
431 | ||
432 | class PanoptoPlaylistIE(PanoptoBaseIE): | |
433 | _VALID_URL = PanoptoBaseIE.BASE_URL_RE + r'/Pages/(Viewer|Embed)\.aspx.*(?:\?|&)pid=(?P<id>[a-f0-9-]+)' | |
434 | _TESTS = [ | |
435 | { | |
436 | 'url': 'https://howtovideos.hosted.panopto.com/Panopto/Pages/Viewer.aspx?pid=f3b39fcf-882f-4849-93d6-a9f401236d36&id=5fa74e93-3d87-4694-b60e-aaa4012214ed&advance=true', | |
437 | 'info_dict': { | |
438 | 'title': 'Featured Video Tutorials', | |
439 | 'id': 'f3b39fcf-882f-4849-93d6-a9f401236d36', | |
440 | 'description': '', | |
441 | }, | |
442 | 'playlist_mincount': 36 | |
443 | }, | |
444 | { | |
445 | 'url': 'https://utsa.hosted.panopto.com/Panopto/Pages/Viewer.aspx?pid=e2900555-3ad4-4bdb-854d-ad2401686190', | |
446 | 'info_dict': { | |
447 | 'title': 'Library Website Introduction Playlist', | |
448 | 'id': 'e2900555-3ad4-4bdb-854d-ad2401686190', | |
449 | 'description': 'md5:f958bca50a1cbda15fdc1e20d32b3ecb', | |
450 | }, | |
451 | 'playlist_mincount': 4 | |
452 | }, | |
453 | ||
454 | ] | |
455 | ||
456 | def _entries(self, base_url, playlist_id, session_list_id): | |
457 | session_list_info = self._call_api( | |
458 | base_url, f'/Api/SessionLists/{session_list_id}?collections[0].maxCount=500&collections[0].name=items', playlist_id) | |
459 | ||
460 | items = session_list_info['Items'] | |
461 | for item in items: | |
462 | if item.get('TypeName') != 'Session': | |
463 | self.report_warning('Got an item in the playlist that is not a Session' + bug_reports_message(), only_once=True) | |
464 | continue | |
465 | yield { | |
466 | '_type': 'url', | |
467 | 'id': item.get('Id'), | |
468 | 'url': item.get('ViewerUri'), | |
469 | 'title': item.get('Name'), | |
470 | 'description': item.get('Description'), | |
471 | 'duration': item.get('Duration'), | |
472 | 'channel': traverse_obj(item, ('Parent', 'Name')), | |
473 | 'channel_id': traverse_obj(item, ('Parent', 'Id')) | |
474 | } | |
475 | ||
476 | def _real_extract(self, url): | |
477 | base_url, playlist_id = self._match_valid_url(url).group('base_url', 'id') | |
478 | ||
479 | video_id = get_first(parse_qs(url), 'id') | |
480 | if video_id: | |
481 | if self.get_param('noplaylist'): | |
482 | self.to_screen('Downloading just video %s because of --no-playlist' % video_id) | |
483 | return self.url_result(base_url + f'/Pages/Viewer.aspx?id={video_id}', ie_key=PanoptoIE.ie_key(), video_id=video_id) | |
484 | else: | |
485 | self.to_screen(f'Downloading playlist {playlist_id}; add --no-playlist to just download video {video_id}') | |
486 | ||
487 | playlist_info = self._call_api(base_url, f'/Api/Playlists/{playlist_id}', playlist_id) | |
488 | return self.playlist_result( | |
489 | self._entries(base_url, playlist_id, playlist_info['SessionListId']), | |
490 | playlist_id=playlist_id, playlist_title=playlist_info.get('Name'), | |
491 | playlist_description=playlist_info.get('Description')) | |
492 | ||
493 | ||
494 | class PanoptoListIE(PanoptoBaseIE): | |
495 | _VALID_URL = PanoptoBaseIE.BASE_URL_RE + r'/Pages/Sessions/List\.aspx' | |
496 | _PAGE_SIZE = 250 | |
497 | _TESTS = [ | |
498 | { | |
499 | 'url': 'https://demo.hosted.panopto.com/Panopto/Pages/Sessions/List.aspx#folderID=%22e4c6a2fc-1214-4ca0-8fb7-aef2e29ff63a%22', | |
500 | 'info_dict': { | |
501 | 'id': 'e4c6a2fc-1214-4ca0-8fb7-aef2e29ff63a', | |
502 | 'title': 'Showcase Videos' | |
503 | }, | |
504 | 'playlist_mincount': 140 | |
505 | ||
506 | }, | |
507 | { | |
508 | 'url': 'https://demo.hosted.panopto.com/Panopto/Pages/Sessions/List.aspx#view=2&maxResults=250', | |
509 | 'info_dict': { | |
510 | 'id': 'panopto_list', | |
511 | 'title': 'panopto_list' | |
512 | }, | |
513 | 'playlist_mincount': 300 | |
514 | }, | |
515 | { | |
516 | # Folder that contains 8 folders and a playlist | |
517 | 'url': 'https://howtovideos.hosted.panopto.com/Panopto/Pages/Sessions/List.aspx?noredirect=true#folderID=%224b9de7ae-0080-4158-8496-a9ba01692c2e%22', | |
518 | 'info_dict': { | |
519 | 'id': '4b9de7ae-0080-4158-8496-a9ba01692c2e', | |
520 | 'title': 'Video Tutorials' | |
521 | }, | |
522 | 'playlist_mincount': 9 | |
523 | } | |
524 | ||
525 | ] | |
526 | ||
527 | def _fetch_page(self, base_url, query_params, display_id, page): | |
528 | ||
529 | params = { | |
530 | 'sortColumn': 1, | |
531 | 'getFolderData': True, | |
532 | 'includePlaylists': True, | |
533 | **query_params, | |
534 | 'page': page, | |
535 | 'maxResults': self._PAGE_SIZE, | |
536 | } | |
537 | ||
538 | response = self._call_api( | |
539 | base_url, '/Services/Data.svc/GetSessions', f'{display_id} page {page + 1}', | |
540 | data={'queryParameters': params}, fatal=False) | |
541 | ||
542 | for result in get_first(response, 'Results', default=[]): | |
543 | # This could be a video, playlist (or maybe something else) | |
544 | item_id = result.get('DeliveryID') | |
545 | yield { | |
546 | '_type': 'url', | |
547 | 'id': item_id, | |
548 | 'title': result.get('SessionName'), | |
549 | 'url': traverse_obj(result, 'ViewerUrl', 'EmbedUrl', get_all=False) or (base_url + f'/Pages/Viewer.aspx?id={item_id}'), | |
550 | 'duration': result.get('Duration'), | |
551 | 'channel': result.get('FolderName'), | |
552 | 'channel_id': result.get('FolderID'), | |
553 | } | |
554 | ||
555 | for folder in get_first(response, 'Subfolders', default=[]): | |
556 | folder_id = folder.get('ID') | |
557 | yield self.url_result( | |
558 | base_url + f'/Pages/Sessions/List.aspx#folderID="{folder_id}"', | |
559 | ie_key=PanoptoListIE.ie_key(), video_id=folder_id, title=folder.get('Name')) | |
560 | ||
561 | def _extract_folder_metadata(self, base_url, folder_id): | |
562 | response = self._call_api( | |
563 | base_url, '/Services/Data.svc/GetFolderInfo', folder_id, | |
564 | data={'folderID': folder_id}, fatal=False) | |
565 | return { | |
566 | 'title': get_first(response, 'Name') | |
567 | } | |
568 | ||
569 | def _real_extract(self, url): | |
570 | mobj = self._match_valid_url(url) | |
571 | base_url = mobj.group('base_url') | |
572 | ||
573 | query_params = self._parse_fragment(url) | |
574 | folder_id, display_id = query_params.get('folderID'), 'panopto_list' | |
575 | ||
576 | if query_params.get('isSubscriptionsPage'): | |
577 | display_id = 'subscriptions' | |
578 | if not query_params.get('subscribableTypes'): | |
579 | query_params['subscribableTypes'] = [0, 1, 2] | |
580 | elif query_params.get('isSharedWithMe'): | |
581 | display_id = 'sharedwithme' | |
582 | elif folder_id: | |
583 | display_id = folder_id | |
584 | ||
585 | query = query_params.get('query') | |
586 | if query: | |
587 | display_id += f': query "{query}"' | |
588 | ||
589 | info = { | |
590 | '_type': 'playlist', | |
591 | 'id': display_id, | |
592 | 'title': display_id, | |
593 | } | |
594 | if folder_id: | |
595 | info.update(self._extract_folder_metadata(base_url, folder_id)) | |
596 | ||
597 | info['entries'] = OnDemandPagedList( | |
598 | functools.partial(self._fetch_page, base_url, query_params, display_id), self._PAGE_SIZE) | |
599 | ||
600 | return info |