<s> from __future__ import unicode_literals <EOL> import re <EOL> from . common import InfoExtractor <EOL> from . . utils import ( <EOL> ExtractorError , <EOL> orderedSet , <EOL> unescapeHTML , <EOL> ) <EOL> class StanfordOpenClassroomIE ( InfoExtractor ) : <EOL> IE_NAME = '<STR_LIT>' <EOL> IE_DESC = '<STR_LIT>' <EOL> _VALID_URL = r'<STR_LIT>' <EOL> _TEST = { <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> } <EOL> } <EOL> def _real_extract ( self , url ) : <EOL> mobj = re . match ( self . _VALID_URL , url ) <EOL> if mobj . group ( '<STR_LIT>' ) and mobj . group ( '<STR_LIT>' ) : <EOL> course = mobj . group ( '<STR_LIT>' ) <EOL> video = mobj . group ( '<STR_LIT>' ) <EOL> info = { <EOL> '<STR_LIT:id>' : course + '<STR_LIT:_>' + video , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> baseUrl = '<STR_LIT>' + course + '<STR_LIT>' <EOL> xmlUrl = baseUrl + video + '<STR_LIT>' <EOL> mdoc = self . _download_xml ( xmlUrl , info [ '<STR_LIT:id>' ] ) <EOL> try : <EOL> info [ '<STR_LIT:title>' ] = mdoc . findall ( '<STR_LIT>' ) [ <NUM_LIT:0> ] . text <EOL> info [ '<STR_LIT:url>' ] = baseUrl + mdoc . findall ( '<STR_LIT>' ) [ <NUM_LIT:0> ] . text <EOL> except IndexError : <EOL> raise ExtractorError ( '<STR_LIT>' ) <EOL> return info <EOL> elif mobj . group ( '<STR_LIT>' ) : <EOL> course = mobj . group ( '<STR_LIT>' ) <EOL> info = { <EOL> '<STR_LIT:id>' : course , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> coursepage = self . _download_webpage ( <EOL> url , info [ '<STR_LIT:id>' ] , <EOL> note = '<STR_LIT>' , <EOL> errnote = '<STR_LIT>' ) <EOL> info [ '<STR_LIT:title>' ] = self . _html_search_regex ( <EOL> r'<STR_LIT>' , coursepage , '<STR_LIT:title>' , default = info [ '<STR_LIT:id>' ] ) <EOL> info [ '<STR_LIT:description>' ] = self . _html_search_regex ( <EOL> r'<STR_LIT>' , <EOL> coursepage , '<STR_LIT:description>' , fatal = False ) <EOL> links = orderedSet ( re . findall ( '<STR_LIT>' , coursepage ) ) <EOL> info [ '<STR_LIT>' ] = [ self . url_result ( <EOL> '<STR_LIT>' % unescapeHTML ( l ) <EOL> ) for l in links ] <EOL> return info <EOL> else : <EOL> info = { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> info [ '<STR_LIT:title>' ] = info [ '<STR_LIT:id>' ] <EOL> rootURL = '<STR_LIT>' <EOL> rootpage = self . _download_webpage ( rootURL , info [ '<STR_LIT:id>' ] , <EOL> errnote = '<STR_LIT>' ) <EOL> links = orderedSet ( re . findall ( '<STR_LIT>' , rootpage ) ) <EOL> info [ '<STR_LIT>' ] = [ self . url_result ( <EOL> '<STR_LIT>' % unescapeHTML ( l ) <EOL> ) for l in links ] <EOL> return info </s>
