3 from .common import InfoExtractor
13 class StanfordOpenClassroomIE(InfoExtractor):
14 IE_NAME = u'stanfordoc'
15 IE_DESC = u'Stanford Open ClassRoom'
16 _VALID_URL = r'^(?:https?://)?openclassroom\.stanford\.edu(?P<path>/?|(/MainFolder/(?:HomePage|CoursePage|VideoPage)\.php([?]course=(?P<course>[^&]+)(&video=(?P<video>[^&]+))?(&.*)?)?))$'
18 u'url': u'http://openclassroom.stanford.edu/MainFolder/VideoPage.php?course=PracticalUnix&video=intro-environment&speed=100',
19 u'file': u'PracticalUnix_intro-environment.mp4',
20 u'md5': u'544a9468546059d4e80d76265b0443b8',
22 u"title": u"Intro Environment"
26 def _real_extract(self, url):
27 mobj = re.match(self._VALID_URL, url)
29 raise ExtractorError(u'Invalid URL: %s' % url)
31 if mobj.group('course') and mobj.group('video'): # A specific video
32 course = mobj.group('course')
33 video = mobj.group('video')
35 'id': course + '_' + video,
40 self.report_extraction(info['id'])
41 baseUrl = 'http://openclassroom.stanford.edu/MainFolder/courses/' + course + '/videos/'
42 xmlUrl = baseUrl + video + '.xml'
43 mdoc = self._download_xml(xmlUrl, info['id'])
45 info['title'] = mdoc.findall('./title')[0].text
46 info['url'] = baseUrl + mdoc.findall('./videoFile')[0].text
48 raise ExtractorError(u'Invalid metadata XML file')
49 info['ext'] = info['url'].rpartition('.')[2]
51 elif mobj.group('course'): # A course page
52 course = mobj.group('course')
60 coursepage = self._download_webpage(url, info['id'],
61 note='Downloading course info page',
62 errnote='Unable to download course info page')
64 info['title'] = self._html_search_regex('<h1>([^<]+)</h1>', coursepage, 'title', default=info['id'])
66 info['description'] = self._html_search_regex('<description>([^<]+)</description>',
67 coursepage, u'description', fatal=False)
69 links = orderedSet(re.findall('<a href="(VideoPage.php\?[^"]+)">', coursepage))
73 'url': 'http://openclassroom.stanford.edu/MainFolder/' + unescapeHTML(vpage),
77 for entry in info['list']:
78 assert entry['type'] == 'reference'
79 results += self.extract(entry['url'])
83 'id': 'Stanford OpenClassroom',
89 rootURL = 'http://openclassroom.stanford.edu/MainFolder/HomePage.php'
90 rootpage = self._download_webpage(rootURL, info['id'],
91 errnote=u'Unable to download course info page')
93 info['title'] = info['id']
95 links = orderedSet(re.findall('<a href="(CoursePage.php\?[^"]+)">', rootpage))
99 'url': 'http://openclassroom.stanford.edu/MainFolder/' + unescapeHTML(cpage),
104 for entry in info['list']:
105 assert entry['type'] == 'reference'
106 results += self.extract(entry['url'])