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