#NEWLINE# def get_episode( self , url , imdb , tvdb , title , date , season , episode ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# ( tvshowtitle , year ) = re . compile ( '(.+?) [(](\\d{4})[)]$' ) . findall ( url ) [ 0 ] #NEWLINE# ( season , episode ) = ( ( '%01d' % int ( season ) ) , ( '%01d' % int ( episode ) ) ) #NEWLINE# query = ( '%s season %s' % ( tvshowtitle , season ) ) #NEWLINE# query = ( self . search_link % urllib . quote_plus ( query ) ) #NEWLINE# result = client . source ( query ) #NEWLINE# result = json . loads ( result ) #NEWLINE# result = result [ 'results' ] #NEWLINE# tvshowtitle = cleantitle . tv ( tvshowtitle ) #NEWLINE# years = [ ( '%s' % str ( year ) ) , ( '%s' % str ( ( int ( year ) + 1 ) ) ) , ( '%s' % str ( ( int ( x ) - 1 ) ) ) ] #NEWLINE# result = [ ( i [ 'url' ] , i [ 'titleNoFormatting' ] ) for i in result ] #NEWLINE# result = [ ( i [ 0 ] , re . compile ( '(^Watch Full "|^Watch |)(.+?[(]\\d{4}[)])' ) . findall ( i [ 1 ] ) ) for i in result ] #NEWLINE# result = [ ( i [ 0 ] , i [ 1 ] [ 0 ] [ ( - 1 ) ] . lower ( ) ) for i in result if ( len ( i [ 1 ] ) > 0 ) ] #NEWLINE# result = [ ( i [ 0 ] , re . compile ( '(.+) season (\\d+)\\s*[(](\\d{4})[)]' ) . findall ( i [ 1 ] ) ) for i in result ] #NEWLINE# result = [ ( i [ 0 ] , cleantitle . tv ( i [ 1 ] [ 0 ] [ 0 ] ) , i [ 1 ] [ 0 ] [ 1 ] , i [ 1 ] [ 0 ] [ 2 ] ) for i in result if ( len ( i [ 1 ] ) > 0 ) ] #NEWLINE# result = [ i for i in result if ( tvshowtitle == cleantitle . tv ( i [ 1 ] ) ) ] #NEWLINE# result = [ i for i in result if ( season == i [ 2 ] ) ] #NEWLINE# result = [ ( i [ 0 ] , i [ 1 ] , str ( ( ( int ( i [ 3 ] ) - int ( i [ 2 ] ) ) + 1 ) ) ) for i in result ] #NEWLINE# result = [ i [ 0 ] for i in result if any ( ( ( x in i [ 2 ] ) for x in years ) ) ] [ 0 ] #NEWLINE# result += ( '?S%02dE%02d' % ( int ( season ) , int ( episode ) ) ) #NEWLINE# try : #NEWLINE# #INDENT# url = re . compile ( '//.+?(/.+)' ) . findall ( result ) [ 0 ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# url = result #NEWLINE# #UNINDENT# url = client . replaceHTMLCodes ( url ) #NEWLINE# url = url . encode ( 'utf-8' ) #NEWLINE# return url #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# return