<s> from __future__ import unicode_literals <EOL> import re <EOL> from . common import InfoExtractor <EOL> from . . compat import ( <EOL> compat_urllib_parse , <EOL> compat_urllib_request , <EOL> ) <EOL> class GDCVaultIE ( InfoExtractor ) : <EOL> _VALID_URL = r'<STR_LIT>' <EOL> _TESTS = [ <EOL> { <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> { <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : '<STR_LIT>' <EOL> } , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : True , <EOL> } <EOL> } , <EOL> { <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> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> ] <EOL> def _parse_mp4 ( self , xml_description ) : <EOL> video_formats = [ ] <EOL> mp4_video = xml_description . find ( '<STR_LIT>' ) <EOL> if mp4_video is None : <EOL> return None <EOL> mobj = re . match ( r'<STR_LIT>' , mp4_video . text ) <EOL> video_root = mobj . group ( '<STR_LIT:root>' ) <EOL> formats = xml_description . findall ( '<STR_LIT>' ) <EOL> for format in formats : <EOL> mobj = re . match ( r'<STR_LIT>' , format . find ( '<STR_LIT>' ) . text ) <EOL> url = video_root + mobj . group ( '<STR_LIT:path>' ) <EOL> vbr = format . find ( '<STR_LIT>' ) . text <EOL> video_formats . append ( { <EOL> '<STR_LIT:url>' : url , <EOL> '<STR_LIT>' : int ( vbr ) , <EOL> } ) <EOL> return video_formats <EOL> def _parse_flv ( self , xml_description ) : <EOL> video_formats = [ ] <EOL> akami_url = xml_description . find ( '<STR_LIT>' ) . text <EOL> slide_video_path = xml_description . find ( '<STR_LIT>' ) . text <EOL> video_formats . append ( { <EOL> '<STR_LIT:url>' : '<STR_LIT>' + akami_url + '<STR_LIT:/>' + slide_video_path , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : - <NUM_LIT:2> , <EOL> '<STR_LIT>' : - <NUM_LIT:2> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> speaker_video_path = xml_description . find ( '<STR_LIT>' ) . text <EOL> video_formats . append ( { <EOL> '<STR_LIT:url>' : '<STR_LIT>' + akami_url + '<STR_LIT:/>' + speaker_video_path , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : - <NUM_LIT:1> , <EOL> '<STR_LIT>' : - <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> return video_formats <EOL> def _login ( self , webpage_url , video_id ) : <EOL> ( username , password ) = self . _get_login_info ( ) <EOL> if username is None or password is None : <EOL> self . report_warning ( '<STR_LIT>' + webpage_url + '<STR_LIT>' ) <EOL> return None <EOL> mobj = re . match ( r'<STR_LIT>' , webpage_url ) <EOL> login_url = mobj . group ( '<STR_LIT>' ) + '<STR_LIT>' <EOL> logout_url = mobj . group ( '<STR_LIT>' ) + '<STR_LIT>' <EOL> login_form = { <EOL> '<STR_LIT:email>' : username , <EOL> '<STR_LIT:password>' : password , <EOL> } <EOL> request = compat_urllib_request . Request ( login_url , compat_urllib_parse . urlencode ( login_form ) ) <EOL> request . add_header ( '<STR_LIT:Content-Type>' , '<STR_LIT>' ) <EOL> self . _download_webpage ( request , video_id , '<STR_LIT>' ) <EOL> start_page = self . _download_webpage ( webpage_url , video_id , '<STR_LIT>' ) <EOL> self . _download_webpage ( logout_url , video_id , '<STR_LIT>' ) <EOL> return start_page <EOL> def _real_extract ( self , url ) : <EOL> mobj = re . match ( self . _VALID_URL , url ) <EOL> video_id = mobj . group ( '<STR_LIT:id>' ) <EOL> webpage_url = '<STR_LIT>' + video_id <EOL> start_page = self . _download_webpage ( webpage_url , video_id ) <EOL> direct_url = self . _search_regex ( <EOL> r'<STR_LIT>' , <EOL> start_page , '<STR_LIT:url>' , default = None ) <EOL> if direct_url : <EOL> video_url = '<STR_LIT>' + direct_url <EOL> title = self . _html_search_regex ( <EOL> r'<STR_LIT>' , <EOL> start_page , '<STR_LIT:title>' ) <EOL> return { <EOL> '<STR_LIT:id>' : video_id , <EOL> '<STR_LIT:url>' : video_url , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:title>' : title , <EOL> } <EOL> xml_root = self . _html_search_regex ( <EOL> r'<STR_LIT>' , <EOL> start_page , '<STR_LIT>' , default = None ) <EOL> if xml_root is None : <EOL> login_res = self . _login ( webpage_url , video_id ) <EOL> if login_res is None : <EOL> self . report_warning ( '<STR_LIT>' ) <EOL> else : <EOL> start_page = login_res <EOL> xml_root = self . _html_search_regex ( <EOL> r'<STR_LIT>' , <EOL> start_page , '<STR_LIT>' ) <EOL> xml_name = self . _html_search_regex ( <EOL> r'<STR_LIT>' , <EOL> start_page , '<STR_LIT>' , default = None ) <EOL> if xml_name is None : <EOL> xml_name = self . _html_search_regex ( r'<STR_LIT>' , start_page , '<STR_LIT>' ) <EOL> xml_decription_url = xml_root + '<STR_LIT>' + xml_name <EOL> xml_description = self . _download_xml ( xml_decription_url , video_id ) <EOL> video_title = xml_description . find ( '<STR_LIT>' ) . text <EOL> video_formats = self . _parse_mp4 ( xml_description ) <EOL> if video_formats is None : <EOL> video_formats = self . _parse_flv ( xml_description ) <EOL> return { <EOL> '<STR_LIT:id>' : video_id , <EOL> '<STR_LIT:title>' : video_title , <EOL> '<STR_LIT>' : video_formats , <EOL> } </s>
