<s> import re <EOL> from livestreamer . plugin import Plugin <EOL> from livestreamer . plugin . api import http , validate <EOL> from livestreamer . plugin . api . utils import parse_query <EOL> from livestreamer . stream import HLSStream , HTTPStream <EOL> CHANNEL_INFO_URL = "<STR_LIT>" <EOL> STREAM_INFO_URL = "<STR_LIT>" <EOL> _url_re = re . compile ( "<STR_LIT>" ) ; <EOL> _channel_schema = validate . Schema ( <EOL> { <EOL> "<STR_LIT:data>" : validate . any ( None , { <EOL> "<STR_LIT>" : validate . any ( None , { <EOL> "<STR_LIT:id>" : validate . all ( <EOL> validate . text , <EOL> validate . transform ( int ) <EOL> ) , <EOL> "<STR_LIT>" : int <EOL> } ) <EOL> } ) <EOL> } , <EOL> validate . get ( "<STR_LIT:data>" ) <EOL> ) ; <EOL> _qq_schema = validate . Schema ( { <EOL> validate . optional ( "<STR_LIT>" ) : validate . url ( scheme = "<STR_LIT:http>" ) <EOL> } , <EOL> validate . get ( "<STR_LIT>" ) <EOL> ) <EOL> STREAM_WEIGHTS = { <EOL> "<STR_LIT>" : <NUM_LIT> , <EOL> "<STR_LIT:source>" : <NUM_LIT> <EOL> } <EOL> class Tga ( Plugin ) : <EOL> @ classmethod <EOL> def can_handle_url ( self , url ) : <EOL> return _url_re . match ( url ) <EOL> @ classmethod <EOL> def stream_weight ( cls , stream ) : <EOL> if stream in STREAM_WEIGHTS : <EOL> return STREAM_WEIGHTS [ stream ] , "<STR_LIT>" <EOL> return Plugin . stream_weight ( stream ) <EOL> def _get_channel_id ( self , domain ) : <EOL> channel_info = http . get ( CHANNEL_INFO_URL % str ( domain ) ) <EOL> info = http . json ( channel_info , schema = _channel_schema ) <EOL> if info is None : <EOL> return False <EOL> cnid = info [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> if cnid <= <NUM_LIT:0> : <EOL> return False <EOL> return cnid <EOL> def _get_qq_stream_url ( self , cnid , weight = <NUM_LIT:1> ) : <EOL> qq_stream_url = http . get ( STREAM_INFO_URL % ( int ( cnid ) , int ( weight ) ) ) ; <EOL> qq_info = http . json ( qq_stream_url , schema = _qq_schema ) <EOL> return qq_info ; <EOL> def _get_streams ( self ) : <EOL> match = _url_re . match ( self . url ) ; <EOL> domain = match . group ( '<STR_LIT>' ) <EOL> cnid = self . _get_channel_id ( domain ) ; <EOL> if cnid == False : <EOL> return ; <EOL> flash_stream = HTTPStream ( self . session , self . _get_qq_stream_url ( cnid , <NUM_LIT:1> ) ) <EOL> if flash_stream : <EOL> yield "<STR_LIT>" , flash_stream <EOL> mobile_stream = HLSStream ( self . session , self . _get_qq_stream_url ( cnid , <NUM_LIT:2> ) ) <EOL> if mobile_stream : <EOL> yield "<STR_LIT>" , mobile_stream <EOL> __plugin__ = Tga </s>
