]>
Commit | Line | Data |
---|---|---|
e248be33 | 1 | import calendar |
2 | import json | |
3 | import functools | |
4 | from datetime import datetime | |
5 | from random 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, | |
e6552207 | 20 | srt_subtitles_timecode, |
e248be33 | 21 | traverse_obj, |
22 | ) | |
23 | ||
24 | ||
25 | class PanoptoBaseIE(InfoExtractor): | |
e6552207 | 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 | } | |
e248be33 | 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 | |
e6552207 | 60 | error_code = traverse_obj(response, 'ErrorCode') |
e248be33 | 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 | ||
e248be33 | 75 | |
76 | class PanoptoIE(PanoptoBaseIE): | |
77 | _VALID_URL = PanoptoBaseIE.BASE_URL_RE + r'/Pages/(Viewer|Embed)\.aspx.*(?:\?|&)id=(?P<id>[a-f0-9-]+)' | |
bfd973ec | 78 | _EMBED_REGEX = [rf'<iframe[^>]+src=["\'](?P<url>{PanoptoBaseIE.BASE_URL_RE}/Pages/(Viewer|Embed|Sessions/List)\.aspx[^"\']+)'] |
e248be33 | 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, | |
e6552207 | 86 | 'thumbnail': r're:https://demo\.hosted\.panopto\.com/.+', |
e248be33 | 87 | 'upload_date': '20160328', |
88 | 'ext': 'mp4', | |
89 | 'cast': [], | |
e6552207 | 90 | 'chapters': [], |
e248be33 | 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, | |
e6552207 | 105 | 'thumbnail': r're:https://demo\.hosted\.panopto\.com/.+', |
e248be33 | 106 | 'upload_date': '20151206', |
107 | 'ext': 'mp4', | |
e6552207 | 108 | 'chapters': 'count:12', |
e248be33 | 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'], | |
e6552207 | 129 | 'chapters': [], |
e248be33 | 130 | 'upload_date': '20190930', |
e6552207 | 131 | 'thumbnail': r're:https://howtovideos\.hosted\.panopto\.com/.+', |
e248be33 | 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'], | |
e6552207 | 147 | 'chapters': [], |
e248be33 | 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', | |
e6552207 | 156 | 'thumbnail': r're:https://unisa\.au\.panopto\.com/.+', |
e248be33 | 157 | 'channel': 'World War II Veteran Interviews', |
158 | 'upload_date': '20191030', | |
159 | }, | |
160 | }, | |
e6552207 | 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 | }, | |
e248be33 | 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(datetime.utcnow().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 | |
e6552207 | 271 | def _extract_chapters(timestamps): |
e248be33 | 272 | chapters = [] |
e6552207 | 273 | for timestamp in timestamps or []: |
274 | caption = timestamp.get('Caption') | |
e248be33 | 275 | start, duration = int_or_none(timestamp.get('Time')), int_or_none(timestamp.get('Duration')) |
e6552207 | 276 | if not caption or start is None or duration is None: |
e248be33 | 277 | continue |
278 | chapters.append({ | |
279 | 'start_time': start, | |
280 | 'end_time': start + duration, | |
e6552207 | 281 | 'title': caption |
e248be33 | 282 | }) |
283 | return chapters | |
284 | ||
e6552207 | 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 | ||
e248be33 | 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')) | |
e6552207 | 396 | timestamps = delivery.get('Timestamps') |
e248be33 | 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 | |
e6552207 | 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)) | |
e248be33 | 409 | |
e6552207 | 410 | self._sort_formats(formats) |
e248be33 | 411 | self.mark_watched(base_url, video_id, delivery_info) |
412 | ||
413 | return { | |
414 | 'id': video_id, | |
415 | 'title': delivery.get('SessionName'), | |
416 | 'cast': traverse_obj(delivery, ('Contributors', ..., 'DisplayName'), default=[], expected_type=lambda x: x or None), | |
417 | 'timestamp': session_start_time - 11640000000 if session_start_time else None, | |
418 | 'duration': delivery.get('Duration'), | |
419 | 'thumbnail': base_url + f'/Services/FrameGrabber.svc/FrameRedirect?objectId={video_id}&mode=Delivery&random={random()}', | |
420 | 'average_rating': delivery.get('AverageRating'), | |
e6552207 | 421 | 'chapters': self._extract_chapters(timestamps), |
e248be33 | 422 | 'uploader': delivery.get('OwnerDisplayName') or None, |
423 | 'uploader_id': delivery.get('OwnerId'), | |
424 | 'description': delivery.get('SessionAbstract'), | |
425 | 'tags': traverse_obj(delivery, ('Tags', ..., 'Content')), | |
426 | 'channel_id': delivery.get('SessionGroupPublicID'), | |
427 | 'channel': traverse_obj(delivery, 'SessionGroupLongName', 'SessionGroupShortName', get_all=False), | |
428 | 'formats': formats, | |
429 | 'subtitles': subtitles | |
430 | } | |
431 | ||
432 | ||
433 | class PanoptoPlaylistIE(PanoptoBaseIE): | |
434 | _VALID_URL = PanoptoBaseIE.BASE_URL_RE + r'/Pages/(Viewer|Embed)\.aspx.*(?:\?|&)pid=(?P<id>[a-f0-9-]+)' | |
435 | _TESTS = [ | |
436 | { | |
437 | 'url': 'https://howtovideos.hosted.panopto.com/Panopto/Pages/Viewer.aspx?pid=f3b39fcf-882f-4849-93d6-a9f401236d36&id=5fa74e93-3d87-4694-b60e-aaa4012214ed&advance=true', | |
438 | 'info_dict': { | |
439 | 'title': 'Featured Video Tutorials', | |
440 | 'id': 'f3b39fcf-882f-4849-93d6-a9f401236d36', | |
441 | 'description': '', | |
442 | }, | |
443 | 'playlist_mincount': 36 | |
444 | }, | |
445 | { | |
446 | 'url': 'https://utsa.hosted.panopto.com/Panopto/Pages/Viewer.aspx?pid=e2900555-3ad4-4bdb-854d-ad2401686190', | |
447 | 'info_dict': { | |
448 | 'title': 'Library Website Introduction Playlist', | |
449 | 'id': 'e2900555-3ad4-4bdb-854d-ad2401686190', | |
450 | 'description': 'md5:f958bca50a1cbda15fdc1e20d32b3ecb', | |
451 | }, | |
452 | 'playlist_mincount': 4 | |
453 | }, | |
454 | ||
455 | ] | |
456 | ||
457 | def _entries(self, base_url, playlist_id, session_list_id): | |
458 | session_list_info = self._call_api( | |
459 | base_url, f'/Api/SessionLists/{session_list_id}?collections[0].maxCount=500&collections[0].name=items', playlist_id) | |
460 | ||
461 | items = session_list_info['Items'] | |
462 | for item in items: | |
463 | if item.get('TypeName') != 'Session': | |
464 | self.report_warning('Got an item in the playlist that is not a Session' + bug_reports_message(), only_once=True) | |
465 | continue | |
466 | yield { | |
467 | '_type': 'url', | |
468 | 'id': item.get('Id'), | |
469 | 'url': item.get('ViewerUri'), | |
470 | 'title': item.get('Name'), | |
471 | 'description': item.get('Description'), | |
472 | 'duration': item.get('Duration'), | |
473 | 'channel': traverse_obj(item, ('Parent', 'Name')), | |
474 | 'channel_id': traverse_obj(item, ('Parent', 'Id')) | |
475 | } | |
476 | ||
477 | def _real_extract(self, url): | |
478 | base_url, playlist_id = self._match_valid_url(url).group('base_url', 'id') | |
479 | ||
480 | video_id = get_first(parse_qs(url), 'id') | |
481 | if video_id: | |
482 | if self.get_param('noplaylist'): | |
483 | self.to_screen('Downloading just video %s because of --no-playlist' % video_id) | |
484 | return self.url_result(base_url + f'/Pages/Viewer.aspx?id={video_id}', ie_key=PanoptoIE.ie_key(), video_id=video_id) | |
485 | else: | |
486 | self.to_screen(f'Downloading playlist {playlist_id}; add --no-playlist to just download video {video_id}') | |
487 | ||
488 | playlist_info = self._call_api(base_url, f'/Api/Playlists/{playlist_id}', playlist_id) | |
489 | return self.playlist_result( | |
490 | self._entries(base_url, playlist_id, playlist_info['SessionListId']), | |
491 | playlist_id=playlist_id, playlist_title=playlist_info.get('Name'), | |
492 | playlist_description=playlist_info.get('Description')) | |
493 | ||
494 | ||
495 | class PanoptoListIE(PanoptoBaseIE): | |
496 | _VALID_URL = PanoptoBaseIE.BASE_URL_RE + r'/Pages/Sessions/List\.aspx' | |
497 | _PAGE_SIZE = 250 | |
498 | _TESTS = [ | |
499 | { | |
500 | 'url': 'https://demo.hosted.panopto.com/Panopto/Pages/Sessions/List.aspx#folderID=%22e4c6a2fc-1214-4ca0-8fb7-aef2e29ff63a%22', | |
501 | 'info_dict': { | |
502 | 'id': 'e4c6a2fc-1214-4ca0-8fb7-aef2e29ff63a', | |
503 | 'title': 'Showcase Videos' | |
504 | }, | |
505 | 'playlist_mincount': 140 | |
506 | ||
507 | }, | |
508 | { | |
509 | 'url': 'https://demo.hosted.panopto.com/Panopto/Pages/Sessions/List.aspx#view=2&maxResults=250', | |
510 | 'info_dict': { | |
511 | 'id': 'panopto_list', | |
512 | 'title': 'panopto_list' | |
513 | }, | |
514 | 'playlist_mincount': 300 | |
515 | }, | |
516 | { | |
517 | # Folder that contains 8 folders and a playlist | |
518 | 'url': 'https://howtovideos.hosted.panopto.com/Panopto/Pages/Sessions/List.aspx?noredirect=true#folderID=%224b9de7ae-0080-4158-8496-a9ba01692c2e%22', | |
519 | 'info_dict': { | |
520 | 'id': '4b9de7ae-0080-4158-8496-a9ba01692c2e', | |
521 | 'title': 'Video Tutorials' | |
522 | }, | |
523 | 'playlist_mincount': 9 | |
524 | } | |
525 | ||
526 | ] | |
527 | ||
528 | def _fetch_page(self, base_url, query_params, display_id, page): | |
529 | ||
530 | params = { | |
531 | 'sortColumn': 1, | |
532 | 'getFolderData': True, | |
533 | 'includePlaylists': True, | |
534 | **query_params, | |
535 | 'page': page, | |
536 | 'maxResults': self._PAGE_SIZE, | |
537 | } | |
538 | ||
539 | response = self._call_api( | |
540 | base_url, '/Services/Data.svc/GetSessions', f'{display_id} page {page+1}', | |
541 | data={'queryParameters': params}, fatal=False) | |
542 | ||
543 | for result in get_first(response, 'Results', default=[]): | |
544 | # This could be a video, playlist (or maybe something else) | |
545 | item_id = result.get('DeliveryID') | |
546 | yield { | |
547 | '_type': 'url', | |
548 | 'id': item_id, | |
549 | 'title': result.get('SessionName'), | |
550 | 'url': traverse_obj(result, 'ViewerUrl', 'EmbedUrl', get_all=False) or (base_url + f'/Pages/Viewer.aspx?id={item_id}'), | |
551 | 'duration': result.get('Duration'), | |
552 | 'channel': result.get('FolderName'), | |
553 | 'channel_id': result.get('FolderID'), | |
554 | } | |
555 | ||
556 | for folder in get_first(response, 'Subfolders', default=[]): | |
557 | folder_id = folder.get('ID') | |
558 | yield self.url_result( | |
559 | base_url + f'/Pages/Sessions/List.aspx#folderID="{folder_id}"', | |
560 | ie_key=PanoptoListIE.ie_key(), video_id=folder_id, title=folder.get('Name')) | |
561 | ||
562 | def _extract_folder_metadata(self, base_url, folder_id): | |
563 | response = self._call_api( | |
564 | base_url, '/Services/Data.svc/GetFolderInfo', folder_id, | |
565 | data={'folderID': folder_id}, fatal=False) | |
566 | return { | |
567 | 'title': get_first(response, 'Name', default=[]) | |
568 | } | |
569 | ||
570 | def _real_extract(self, url): | |
571 | mobj = self._match_valid_url(url) | |
572 | base_url = mobj.group('base_url') | |
573 | ||
574 | query_params = self._parse_fragment(url) | |
575 | folder_id, display_id = query_params.get('folderID'), 'panopto_list' | |
576 | ||
577 | if query_params.get('isSubscriptionsPage'): | |
578 | display_id = 'subscriptions' | |
579 | if not query_params.get('subscribableTypes'): | |
580 | query_params['subscribableTypes'] = [0, 1, 2] | |
581 | elif query_params.get('isSharedWithMe'): | |
582 | display_id = 'sharedwithme' | |
583 | elif folder_id: | |
584 | display_id = folder_id | |
585 | ||
586 | query = query_params.get('query') | |
587 | if query: | |
588 | display_id += f': query "{query}"' | |
589 | ||
590 | info = { | |
591 | '_type': 'playlist', | |
592 | 'id': display_id, | |
593 | 'title': display_id, | |
594 | } | |
595 | if folder_id: | |
596 | info.update(self._extract_folder_metadata(base_url, folder_id)) | |
597 | ||
598 | info['entries'] = OnDemandPagedList( | |
599 | functools.partial(self._fetch_page, base_url, query_params, display_id), self._PAGE_SIZE) | |
600 | ||
601 | return info |