-import re
import calendar
-import json
+import datetime as dt
import functools
-from datetime import datetime
-from random import random
+import json
+import random
+import urllib.parse
from .common import InfoExtractor
-from ..compat import (
- compat_urllib_parse_urlparse,
- compat_urlparse
-)
-
from ..utils import (
- bug_reports_message,
ExtractorError,
+ OnDemandPagedList,
+ bug_reports_message,
get_first,
int_or_none,
- OnDemandPagedList,
parse_qs,
srt_subtitles_timecode,
traverse_obj,
18: 'hu-HU',
19: 'nb-NO',
20: 'sv-SE',
- 21: 'it-IT'
+ 21: 'it-IT',
}
def _call_api(self, base_url, path, video_id, data=None, fatal=True, **kwargs):
@staticmethod
def _parse_fragment(url):
- return {k: json.loads(v[0]) for k, v in compat_urlparse.parse_qs(compat_urllib_parse_urlparse(url).fragment).items()}
-
- @staticmethod
- def _extract_urls(webpage):
- return [m.group('url') for m in re.finditer(
- r'<iframe[^>]+src=["\'](?P<url>%s/Pages/(Viewer|Embed|Sessions/List)\.aspx[^"\']+)' % PanoptoIE.BASE_URL_RE,
- webpage)]
+ return {k: json.loads(v[0]) for k, v in urllib.parse.parse_qs(urllib.parse.urlparse(url).fragment).items()}
class PanoptoIE(PanoptoBaseIE):
_VALID_URL = PanoptoBaseIE.BASE_URL_RE + r'/Pages/(Viewer|Embed)\.aspx.*(?:\?|&)id=(?P<id>[a-f0-9-]+)'
+ _EMBED_REGEX = [rf'<iframe[^>]+src=["\'](?P<url>{PanoptoBaseIE.BASE_URL_RE}/Pages/(Viewer|Embed|Sessions/List)\.aspx[^"\']+)']
_TESTS = [
{
'url': 'https://demo.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=26b3ae9e-4a48-4dcc-96ba-0befba08a0fb',
'average_rating': int,
'uploader_id': '2db6b718-47a0-4b0b-9e17-ab0b00f42b1e',
'channel_id': 'e4c6a2fc-1214-4ca0-8fb7-aef2e29ff63a',
- 'channel': 'Showcase Videos'
+ 'channel': 'Showcase Videos',
},
},
{
'uploader': 'Kathryn Kelly',
'channel_id': 'fb93bc3c-6750-4b80-a05b-a921013735d3',
'channel': 'Getting Started',
- }
+ },
},
{
# Does not allow normal Viewer.aspx. AUDIO livestream has no url, so should be skipped and only give one stream.
'chapters': 'count:28',
'thumbnail': r're:https://demo\.hosted\.panopto\.com/.+',
},
- 'params': {'format': 'mhtml', 'skip_download': True}
+ 'params': {'format': 'mhtml', 'skip_download': True},
},
{
'url': 'https://na-training-1.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=8285224a-9a2b-4957-84f2-acb0000c4ea9',
'subtitles': {'en-US': [{'ext': 'srt', 'data': 'md5:a3f4d25963fdeace838f327097c13265'}],
'es-ES': [{'ext': 'srt', 'data': 'md5:57e9dad365fd0fbaf0468eac4949f189'}]},
},
- 'params': {'writesubtitles': True, 'skip_download': True}
+ 'params': {'writesubtitles': True, 'skip_download': True},
}, {
# On Panopto there are two subs: "Default" and en-US. en-US is blank and should be skipped.
'url': 'https://na-training-1.hosted.panopto.com/Panopto/Pages/Viewer.aspx?id=940cbd41-f616-4a45-b13e-aaf1000c915b',
'upload_date': '20191129',
},
- 'params': {'writesubtitles': True, 'skip_download': True}
+ 'params': {'writesubtitles': True, 'skip_download': True},
},
{
'url': 'https://ucc.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=0e8484a4-4ceb-4d98-a63f-ac0200b455cb',
- 'only_matching': True
+ 'only_matching': True,
},
{
'url': 'https://brown.hosted.panopto.com/Panopto/Pages/Embed.aspx?id=0b3ff73b-36a0-46c5-8455-aadf010a3638',
- 'only_matching': True
+ 'only_matching': True,
},
]
invocation_id = delivery_info.get('InvocationId')
stream_id = traverse_obj(delivery_info, ('Delivery', 'Streams', ..., 'PublicID'), get_all=False, expected_type=str)
if invocation_id and stream_id and duration:
- timestamp_str = f'/Date({calendar.timegm(datetime.utcnow().timetuple())}000)/'
+ timestamp_str = f'/Date({calendar.timegm(dt.datetime.now(dt.timezone.utc).timetuple())}000)/'
data = {
'streamRequests': [
{
'StopReason': None,
'StreamID': stream_id,
'TimeStamp': timestamp_str,
- 'UpdatesRejected': 0
+ 'UpdatesRejected': 0,
},
]}
chapters.append({
'start_time': start,
'end_time': start + duration,
- 'title': caption
+ 'title': caption,
})
return chapters
image_frags = {}
for timestamp in timestamps or []:
duration = timestamp.get('Duration')
- obj_id, obj_sn = timestamp.get('ObjectIdentifier'), timestamp.get('ObjectSequenceNumber'),
+ obj_id, obj_sn = timestamp.get('ObjectIdentifier'), timestamp.get('ObjectSequenceNumber')
if timestamp.get('EventTargetType') == 'PowerPoint' and obj_id is not None and obj_sn is not None:
image_frags.setdefault('slides', []).append({
'url': base_url + f'/Pages/Viewer/Image.aspx?id={obj_id}&number={obj_sn}',
- 'duration': duration
+ 'duration': duration,
})
obj_pid, session_id, abs_time = timestamp.get('ObjectPublicIdentifier'), timestamp.get('SessionID'), timestamp.get('AbsoluteTime')
'acodec': 'none',
'vcodec': 'none',
'url': 'about:invalid',
- 'fragments': fragments
+ 'fragments': fragments,
}
@staticmethod
'deliveryId': video_id,
'getCaptions': True,
'language': str(lang),
- 'responseType': 'json'
- }
+ 'responseType': 'json',
+ },
)
if not isinstance(response, list):
continue
subtitles = self._merge_subtitles(subtitles, stream_subtitles)
else:
stream_formats.append({
- 'url': stream_url
+ 'url': stream_url,
})
for fmt in stream_formats:
fmt.update({
'format_note': stream.get('Tag'),
- **fmt_kwargs
+ **fmt_kwargs,
})
formats.extend(stream_formats)
'isKollectiveAgentInstalled': 'false',
'isEmbed': 'false',
'responseType': 'json',
- }
+ },
)
delivery = delivery_info['Delivery']
subtitles = self._merge_subtitles(
podcast_subtitles, streams_subtitles, self.extract_subtitles(base_url, video_id, delivery))
- self._sort_formats(formats)
self.mark_watched(base_url, video_id, delivery_info)
return {
'id': video_id,
'title': delivery.get('SessionName'),
- 'cast': traverse_obj(delivery, ('Contributors', ..., 'DisplayName'), default=[], expected_type=lambda x: x or None),
+ 'cast': traverse_obj(delivery, ('Contributors', ..., 'DisplayName'), expected_type=lambda x: x or None),
'timestamp': session_start_time - 11640000000 if session_start_time else None,
'duration': delivery.get('Duration'),
- 'thumbnail': base_url + f'/Services/FrameGrabber.svc/FrameRedirect?objectId={video_id}&mode=Delivery&random={random()}',
+ 'thumbnail': base_url + f'/Services/FrameGrabber.svc/FrameRedirect?objectId={video_id}&mode=Delivery&random={random.random()}',
'average_rating': delivery.get('AverageRating'),
'chapters': self._extract_chapters(timestamps),
'uploader': delivery.get('OwnerDisplayName') or None,
'channel_id': delivery.get('SessionGroupPublicID'),
'channel': traverse_obj(delivery, 'SessionGroupLongName', 'SessionGroupShortName', get_all=False),
'formats': formats,
- 'subtitles': subtitles
+ 'subtitles': subtitles,
}
'id': 'f3b39fcf-882f-4849-93d6-a9f401236d36',
'description': '',
},
- 'playlist_mincount': 36
+ 'playlist_mincount': 36,
},
{
'url': 'https://utsa.hosted.panopto.com/Panopto/Pages/Viewer.aspx?pid=e2900555-3ad4-4bdb-854d-ad2401686190',
'id': 'e2900555-3ad4-4bdb-854d-ad2401686190',
'description': 'md5:f958bca50a1cbda15fdc1e20d32b3ecb',
},
- 'playlist_mincount': 4
+ 'playlist_mincount': 4,
},
]
'description': item.get('Description'),
'duration': item.get('Duration'),
'channel': traverse_obj(item, ('Parent', 'Name')),
- 'channel_id': traverse_obj(item, ('Parent', 'Id'))
+ 'channel_id': traverse_obj(item, ('Parent', 'Id')),
}
def _real_extract(self, url):
video_id = get_first(parse_qs(url), 'id')
if video_id:
if self.get_param('noplaylist'):
- self.to_screen('Downloading just video %s because of --no-playlist' % video_id)
+ self.to_screen(f'Downloading just video {video_id} because of --no-playlist')
return self.url_result(base_url + f'/Pages/Viewer.aspx?id={video_id}', ie_key=PanoptoIE.ie_key(), video_id=video_id)
else:
self.to_screen(f'Downloading playlist {playlist_id}; add --no-playlist to just download video {video_id}')
'url': 'https://demo.hosted.panopto.com/Panopto/Pages/Sessions/List.aspx#folderID=%22e4c6a2fc-1214-4ca0-8fb7-aef2e29ff63a%22',
'info_dict': {
'id': 'e4c6a2fc-1214-4ca0-8fb7-aef2e29ff63a',
- 'title': 'Showcase Videos'
+ 'title': 'Showcase Videos',
},
- 'playlist_mincount': 140
+ 'playlist_mincount': 140,
},
{
'url': 'https://demo.hosted.panopto.com/Panopto/Pages/Sessions/List.aspx#view=2&maxResults=250',
'info_dict': {
'id': 'panopto_list',
- 'title': 'panopto_list'
+ 'title': 'panopto_list',
},
- 'playlist_mincount': 300
+ 'playlist_mincount': 300,
},
{
# Folder that contains 8 folders and a playlist
'url': 'https://howtovideos.hosted.panopto.com/Panopto/Pages/Sessions/List.aspx?noredirect=true#folderID=%224b9de7ae-0080-4158-8496-a9ba01692c2e%22',
'info_dict': {
'id': '4b9de7ae-0080-4158-8496-a9ba01692c2e',
- 'title': 'Video Tutorials'
+ 'title': 'Video Tutorials',
},
- 'playlist_mincount': 9
- }
+ 'playlist_mincount': 9,
+ },
]
}
response = self._call_api(
- base_url, '/Services/Data.svc/GetSessions', f'{display_id} page {page+1}',
+ base_url, '/Services/Data.svc/GetSessions', f'{display_id} page {page + 1}',
data={'queryParameters': params}, fatal=False)
for result in get_first(response, 'Results', default=[]):
base_url, '/Services/Data.svc/GetFolderInfo', folder_id,
data={'folderID': folder_id}, fatal=False)
return {
- 'title': get_first(response, 'Name', default=[])
+ 'title': get_first(response, 'Name'),
}
def _real_extract(self, url):