[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / stanfordoc.py
blobab41091cff4170b41c181b6f8d29b49277f5964f
1 import re
3 from .common import InfoExtractor
4 from ..utils import (
5 ExtractorError,
6 orderedSet,
7 unescapeHTML,
11 class StanfordOpenClassroomIE(InfoExtractor):
12 IE_NAME = 'stanfordoc'
13 IE_DESC = 'Stanford Open ClassRoom'
14 _VALID_URL = r'https?://openclassroom\.stanford\.edu(?P<path>/?|(/MainFolder/(?:HomePage|CoursePage|VideoPage)\.php([?]course=(?P<course>[^&]+)(&video=(?P<video>[^&]+))?(&.*)?)?))$'
15 _TEST = {
16 'url': 'http://openclassroom.stanford.edu/MainFolder/VideoPage.php?course=PracticalUnix&video=intro-environment&speed=100',
17 'md5': '544a9468546059d4e80d76265b0443b8',
18 'info_dict': {
19 'id': 'PracticalUnix_intro-environment',
20 'ext': 'mp4',
21 'title': 'Intro Environment',
25 def _real_extract(self, url):
26 mobj = self._match_valid_url(url)
28 if mobj.group('course') and mobj.group('video'): # A specific video
29 course = mobj.group('course')
30 video = mobj.group('video')
31 info = {
32 'id': course + '_' + video,
33 'uploader': None,
34 'upload_date': None,
37 base_url = 'http://openclassroom.stanford.edu/MainFolder/courses/' + course + '/videos/'
38 xml_url = base_url + video + '.xml'
39 mdoc = self._download_xml(xml_url, info['id'])
40 try:
41 info['title'] = mdoc.findall('./title')[0].text
42 info['url'] = base_url + mdoc.findall('./videoFile')[0].text
43 except IndexError:
44 raise ExtractorError('Invalid metadata XML file')
45 return info
46 elif mobj.group('course'): # A course page
47 course = mobj.group('course')
48 info = {
49 'id': course,
50 '_type': 'playlist',
51 'uploader': None,
52 'upload_date': None,
55 coursepage = self._download_webpage(
56 url, info['id'],
57 note='Downloading course info page',
58 errnote='Unable to download course info page')
60 info['title'] = self._html_search_regex(
61 r'<h1>([^<]+)</h1>', coursepage, 'title', default=info['id'])
63 info['description'] = self._html_search_regex(
64 r'(?s)<description>([^<]+)</description>',
65 coursepage, 'description', fatal=False)
67 links = orderedSet(re.findall(r'<a href="(VideoPage\.php\?[^"]+)">', coursepage))
68 info['entries'] = [self.url_result(
69 f'http://openclassroom.stanford.edu/MainFolder/{unescapeHTML(l)}',
70 ) for l in links]
71 return info
72 else: # Root page
73 info = {
74 'id': 'Stanford OpenClassroom',
75 '_type': 'playlist',
76 'uploader': None,
77 'upload_date': None,
79 info['title'] = info['id']
81 root_url = 'http://openclassroom.stanford.edu/MainFolder/HomePage.php'
82 rootpage = self._download_webpage(root_url, info['id'],
83 errnote='Unable to download course info page')
85 links = orderedSet(re.findall(r'<a href="(CoursePage\.php\?[^"]+)">', rootpage))
86 info['entries'] = [self.url_result(
87 f'http://openclassroom.stanford.edu/MainFolder/{unescapeHTML(l)}',
88 ) for l in links]
89 return info