<s> from __future__ import unicode_literals <EOL> import re <EOL> from . common import InfoExtractor <EOL> from . . compat import ( <EOL> compat_urllib_request , <EOL> ) <EOL> from . . utils import ( <EOL> clean_html , <EOL> parse_duration , <EOL> str_to_int , <EOL> unified_strdate , <EOL> ) <EOL> class FourTubeIE ( InfoExtractor ) : <EOL> IE_NAME = '<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> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> } <EOL> } <EOL> def _real_extract ( self , url ) : <EOL> video_id = self . _match_id ( url ) <EOL> webpage_url = '<STR_LIT>' + video_id <EOL> webpage = self . _download_webpage ( webpage_url , video_id ) <EOL> self . report_extraction ( video_id ) <EOL> playlist_json = self . _html_search_regex ( r'<STR_LIT>' , webpage , '<STR_LIT>' ) <EOL> media_id = self . _search_regex ( r'<STR_LIT>' , playlist_json , '<STR_LIT>' ) <EOL> sources = self . _search_regex ( r'<STR_LIT>' , playlist_json , '<STR_LIT>' ) . split ( '<STR_LIT:U+002C>' ) <EOL> title = self . _search_regex ( r'<STR_LIT>' , playlist_json , '<STR_LIT>' ) <EOL> thumbnail_url = self . _search_regex ( r'<STR_LIT>' , playlist_json , '<STR_LIT>' , fatal = False ) <EOL> uploader_str = self . _search_regex ( r'<STR_LIT>' , webpage , '<STR_LIT>' , fatal = False ) <EOL> mobj = re . search ( r'<STR_LIT>' , uploader_str ) <EOL> ( uploader , uploader_id ) = ( mobj . group ( '<STR_LIT:name>' ) , mobj . group ( '<STR_LIT:id>' ) ) if mobj else ( clean_html ( uploader_str ) , None ) <EOL> upload_date = None <EOL> view_count = None <EOL> duration = None <EOL> description = self . _html_search_meta ( '<STR_LIT:description>' , webpage , '<STR_LIT:description>' ) <EOL> if description : <EOL> upload_date = self . _search_regex ( r'<STR_LIT>' , description , '<STR_LIT>' , <EOL> fatal = False ) <EOL> if upload_date : <EOL> upload_date = unified_strdate ( upload_date ) <EOL> view_count = self . _search_regex ( r'<STR_LIT>' , description , '<STR_LIT>' , fatal = False ) <EOL> if view_count : <EOL> view_count = str_to_int ( view_count ) <EOL> duration = parse_duration ( self . _search_regex ( r'<STR_LIT>' , description , '<STR_LIT>' , fatal = False ) ) <EOL> token_url = "<STR_LIT>" . format ( media_id , "<STR_LIT:+>" . join ( sources ) ) <EOL> headers = { <EOL> b'<STR_LIT:Content-Type>' : b'<STR_LIT>' , <EOL> b'<STR_LIT>' : b'<STR_LIT>' , <EOL> } <EOL> token_req = compat_urllib_request . Request ( token_url , b'<STR_LIT:{}>' , headers ) <EOL> tokens = self . _download_json ( token_req , video_id ) <EOL> formats = [ { <EOL> '<STR_LIT:url>' : tokens [ format ] [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : format + '<STR_LIT:p>' , <EOL> '<STR_LIT>' : format + '<STR_LIT:p>' , <EOL> '<STR_LIT>' : int ( format ) , <EOL> } for format in sources ] <EOL> self . _sort_formats ( formats ) <EOL> return { <EOL> '<STR_LIT:id>' : video_id , <EOL> '<STR_LIT:title>' : title , <EOL> '<STR_LIT>' : formats , <EOL> '<STR_LIT>' : thumbnail_url , <EOL> '<STR_LIT>' : uploader , <EOL> '<STR_LIT>' : uploader_id , <EOL> '<STR_LIT>' : upload_date , <EOL> '<STR_LIT>' : view_count , <EOL> '<STR_LIT>' : duration , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : webpage_url , <EOL> } </s>
