<s> '''<STR_LIT>''' <EOL> import re , urllib , json , urlparse , base64 , random <EOL> from resources . lib . libraries import client <EOL> from resources . lib . libraries import control <EOL> class trailer : <EOL> def __init__ ( self ) : <EOL> self . base_link = '<STR_LIT>' <EOL> self . key_link = random . choice ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . key_link = '<STR_LIT>' % base64 . urlsafe_b64decode ( self . key_link ) <EOL> self . search_link = '<STR_LIT>' <EOL> self . youtube_search = '<STR_LIT>' <EOL> self . youtube_watch = '<STR_LIT>' <EOL> def play ( self , name , url = None ) : <EOL> try : <EOL> url = self . worker ( name , url ) <EOL> if url == None : return <EOL> item = control . item ( path = url ) <EOL> item . setProperty ( '<STR_LIT>' , '<STR_LIT:true>' ) <EOL> control . player . play ( url , item ) <EOL> except : <EOL> pass <EOL> def worker ( self , name , url ) : <EOL> try : <EOL> if url . startswith ( self . base_link ) : <EOL> url = self . resolve ( url ) <EOL> if url == None : raise Exception ( ) <EOL> return url <EOL> elif not url . startswith ( '<STR_LIT>' ) : <EOL> url = self . youtube_watch % url <EOL> url = self . resolve ( url ) <EOL> if url == None : raise Exception ( ) <EOL> return url <EOL> else : <EOL> raise Exception ( ) <EOL> except : <EOL> query = name + '<STR_LIT>' <EOL> query = self . youtube_search + query <EOL> url = self . search ( query ) <EOL> if url == None : return <EOL> return url <EOL> def search ( self , url ) : <EOL> try : <EOL> query = urlparse . parse_qs ( urlparse . urlparse ( url ) . query ) [ '<STR_LIT:q>' ] [ <NUM_LIT:0> ] <EOL> url = self . search_link % urllib . quote_plus ( query ) + self . key_link <EOL> result = client . request ( url ) <EOL> items = json . loads ( result ) [ '<STR_LIT>' ] <EOL> items = [ ( i [ '<STR_LIT:id>' ] [ '<STR_LIT>' ] ) for i in items ] <EOL> for url in items : <EOL> url = self . resolve ( url ) <EOL> if not url is None : return url <EOL> except : <EOL> return <EOL> def resolve ( self , url ) : <EOL> try : <EOL> id = url . split ( '<STR_LIT>' ) [ - <NUM_LIT:1> ] . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] . split ( '<STR_LIT:?>' ) [ <NUM_LIT:0> ] . split ( '<STR_LIT:&>' ) [ <NUM_LIT:0> ] <EOL> result = client . request ( '<STR_LIT>' % id ) <EOL> message = client . parseDOM ( result , '<STR_LIT>' , attrs = { '<STR_LIT:id>' : '<STR_LIT>' } ) <EOL> message = '<STR_LIT>' . join ( message ) <EOL> alert = client . parseDOM ( result , '<STR_LIT>' , attrs = { '<STR_LIT:id>' : '<STR_LIT>' } ) <EOL> if len ( alert ) > <NUM_LIT:0> : raise Exception ( ) <EOL> if re . search ( '<STR_LIT>' , message ) : raise Exception ( ) <EOL> url = '<STR_LIT>' % id <EOL> return url <EOL> except : <EOL> return </s>
