<s> from __future__ import unicode_literals <EOL> import re <EOL> import json <EOL> from . common import InfoExtractor <EOL> from . . compat import ( <EOL> compat_str , <EOL> compat_urllib_parse_urlparse , <EOL> compat_urlparse , <EOL> ) <EOL> from . . utils import ( <EOL> ExtractorError , <EOL> find_xpath_attr , <EOL> int_or_none , <EOL> orderedSet , <EOL> xpath_with_ns , <EOL> ) <EOL> class LivestreamIE ( InfoExtractor ) : <EOL> IE_NAME = '<STR_LIT>' <EOL> _VALID_URL = r'<STR_LIT>' <EOL> _TESTS = [ { <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>' : int , <EOL> '<STR_LIT>' : int , <EOL> '<STR_LIT>' : '<STR_LIT>' <EOL> } <EOL> } , { <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:title>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> } , { <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> } ] <EOL> def _parse_smil ( self , video_id , smil_url ) : <EOL> formats = [ ] <EOL> _SWITCH_XPATH = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> smil_doc = self . _download_xml ( <EOL> smil_url , video_id , <EOL> note = '<STR_LIT>' , <EOL> errnote = '<STR_LIT>' , <EOL> fatal = False ) <EOL> if smil_doc is False : <EOL> return formats <EOL> title_node = find_xpath_attr ( <EOL> smil_doc , '<STR_LIT>' , <EOL> '<STR_LIT:name>' , '<STR_LIT:title>' ) <EOL> if title_node is None : <EOL> self . report_warning ( '<STR_LIT>' ) <EOL> switch_node = smil_doc . find ( _SWITCH_XPATH ) <EOL> else : <EOL> title_id = title_node . attrib [ '<STR_LIT:content>' ] <EOL> switch_node = find_xpath_attr ( <EOL> smil_doc , _SWITCH_XPATH , '<STR_LIT:id>' , title_id ) <EOL> if switch_node is None : <EOL> raise ExtractorError ( '<STR_LIT>' ) <EOL> video_nodes = switch_node . findall ( <EOL> '<STR_LIT>' ) <EOL> for vn in video_nodes : <EOL> tbr = int_or_none ( vn . attrib . get ( '<STR_LIT>' ) ) <EOL> furl = ( <EOL> '<STR_LIT>' % <EOL> ( vn . attrib [ '<STR_LIT:src>' ] ) ) <EOL> if '<STR_LIT>' in vn . attrib : <EOL> furl += '<STR_LIT>' + vn . attrib [ '<STR_LIT>' ] <EOL> formats . append ( { <EOL> '<STR_LIT:url>' : furl , <EOL> '<STR_LIT>' : '<STR_LIT>' % tbr , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : tbr , <EOL> '<STR_LIT>' : - <NUM_LIT:1000> , <EOL> } ) <EOL> return formats <EOL> def _extract_video_info ( self , video_data ) : <EOL> video_id = compat_str ( video_data [ '<STR_LIT:id>' ] ) <EOL> FORMAT_KEYS = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) <EOL> formats = [ { <EOL> '<STR_LIT>' : format_id , <EOL> '<STR_LIT:url>' : video_data [ key ] , <EOL> '<STR_LIT>' : i + <NUM_LIT:1> , <EOL> } for i , ( format_id , key ) in enumerate ( FORMAT_KEYS ) <EOL> if video_data . get ( key ) ] <EOL> smil_url = video_data . get ( '<STR_LIT>' ) <EOL> if smil_url : <EOL> formats . extend ( self . _parse_smil ( video_id , smil_url ) ) <EOL> self . _sort_formats ( formats ) <EOL> return { <EOL> '<STR_LIT:id>' : video_id , <EOL> '<STR_LIT>' : formats , <EOL> '<STR_LIT:title>' : video_data [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : video_data . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : video_data [ '<STR_LIT>' ] . replace ( '<STR_LIT:->' , '<STR_LIT>' ) [ : <NUM_LIT:8> ] , <EOL> '<STR_LIT>' : video_data . get ( '<STR_LIT>' , { } ) . get ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : video_data . get ( '<STR_LIT>' ) , <EOL> } <EOL> def _real_extract ( self , url ) : <EOL> mobj = re . match ( self . _VALID_URL , url ) <EOL> video_id = mobj . group ( '<STR_LIT:id>' ) <EOL> event_name = mobj . group ( '<STR_LIT>' ) <EOL> webpage = self . _download_webpage ( url , video_id or event_name ) <EOL> og_video = self . _og_search_video_url ( <EOL> webpage , '<STR_LIT>' , fatal = False , default = None ) <EOL> if og_video is not None : <EOL> query_str = compat_urllib_parse_urlparse ( og_video ) . query <EOL> query = compat_urlparse . parse_qs ( query_str ) <EOL> if '<STR_LIT>' in query : <EOL> api_url = query [ '<STR_LIT>' ] [ <NUM_LIT:0> ] . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> info = json . loads ( self . _download_webpage ( <EOL> api_url , video_id , '<STR_LIT>' ) ) <EOL> return self . _extract_video_info ( info ) <EOL> config_json = self . _search_regex ( <EOL> r'<STR_LIT>' , webpage , '<STR_LIT>' ) <EOL> info = json . loads ( config_json ) [ '<STR_LIT>' ] <EOL> def is_relevant ( vdata , vid ) : <EOL> result = vdata [ '<STR_LIT:type>' ] == '<STR_LIT>' <EOL> if video_id is not None : <EOL> result = result and compat_str ( vdata [ '<STR_LIT:data>' ] [ '<STR_LIT:id>' ] ) == vid <EOL> return result <EOL> videos = [ self . _extract_video_info ( video_data [ '<STR_LIT:data>' ] ) <EOL> for video_data in info [ '<STR_LIT>' ] [ '<STR_LIT:data>' ] <EOL> if is_relevant ( video_data , video_id ) ] <EOL> if video_id is None : <EOL> return self . playlist_result ( videos , info [ '<STR_LIT:id>' ] , info [ '<STR_LIT>' ] ) <EOL> else : <EOL> if not videos : <EOL> raise ExtractorError ( '<STR_LIT>' % video_id ) <EOL> return videos [ <NUM_LIT:0> ] <EOL> class LivestreamOriginalIE ( InfoExtractor ) : <EOL> IE_NAME = '<STR_LIT>' <EOL> _VALID_URL = r'''<STR_LIT>''' <EOL> _TESTS = [ { <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> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT:id>' : '<STR_LIT>' , <EOL> } , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> } ] <EOL> def _extract_video ( self , user , video_id ) : <EOL> api_url = '<STR_LIT>' . format ( user , video_id ) <EOL> info = self . _download_xml ( api_url , video_id ) <EOL> item = info . find ( '<STR_LIT>' ) . find ( '<STR_LIT>' ) <EOL> ns = { '<STR_LIT>' : '<STR_LIT>' } <EOL> thumbnail_url = item . find ( xpath_with_ns ( '<STR_LIT>' , ns ) ) . attrib [ '<STR_LIT:url>' ] <EOL> path = self . _search_regex ( r'<STR_LIT>' , thumbnail_url , '<STR_LIT:path>' ) <EOL> return { <EOL> '<STR_LIT:id>' : video_id , <EOL> '<STR_LIT:title>' : item . find ( '<STR_LIT:title>' ) . text , <EOL> '<STR_LIT:url>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' . format ( path ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : thumbnail_url , <EOL> } <EOL> def _extract_folder ( self , url , folder_id ) : <EOL> webpage = self . _download_webpage ( url , folder_id ) <EOL> paths = orderedSet ( re . findall ( <EOL> r'''<STR_LIT>''' , webpage ) ) <EOL> return { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:id>' : folder_id , <EOL> '<STR_LIT>' : [ { <EOL> '<STR_LIT>' : '<STR_LIT:url>' , <EOL> '<STR_LIT:url>' : compat_urlparse . urljoin ( url , p ) , <EOL> } for p in paths ] , <EOL> } <EOL> def _real_extract ( self , url ) : <EOL> mobj = re . match ( self . _VALID_URL , url ) <EOL> id = mobj . group ( '<STR_LIT:id>' ) <EOL> user = mobj . group ( '<STR_LIT:user>' ) <EOL> url_type = mobj . group ( '<STR_LIT:type>' ) <EOL> if url_type == '<STR_LIT>' : <EOL> return self . _extract_folder ( url , id ) <EOL> else : <EOL> return self . _extract_video ( user , id ) <EOL> class LivestreamShortenerIE ( InfoExtractor ) : <EOL> IE_NAME = '<STR_LIT>' <EOL> IE_DESC = False <EOL> _VALID_URL = r'<STR_LIT>' <EOL> def _real_extract ( self , url ) : <EOL> mobj = re . match ( self . _VALID_URL , url ) <EOL> id = mobj . group ( '<STR_LIT:id>' ) <EOL> webpage = self . _download_webpage ( url , id ) <EOL> return { <EOL> '<STR_LIT>' : '<STR_LIT:url>' , <EOL> '<STR_LIT:url>' : self . _og_search_url ( webpage ) , <EOL> } </s>
