#NEWLINE# def query( self , language , keyword , season = None , episode = None , year = None ) : #NEWLINE# #INDENT# params = { #NEWLINE# #INDENT# 'sXML' : 1 , #NEWLINE# 'sL' : str ( language ) , #NEWLINE# 'sK' : keyword , #NEWLINE# #UNINDENT# } #NEWLINE# is_episode = False #NEWLINE# if ( season and episode ) : #NEWLINE# #INDENT# is_episode = True #NEWLINE# params [ 'sTS' ] = season #NEWLINE# params [ 'sTE' ] = episode #NEWLINE# #UNINDENT# if year : #NEWLINE# #INDENT# params [ 'sY' ] = year #NEWLINE# #UNINDENT# logger . info ( 'Searching subtitles %r' , params ) #NEWLINE# subtitles = [ ] #NEWLINE# pids = set ( ) #NEWLINE# while True : #NEWLINE# #INDENT# xml = etree . fromstring ( self . session . get ( ( self . server_url + 'search/old' ) , params = params , timeout = 10 ) . content ) #NEWLINE# if ( not int ( xml . find ( 'pagination/results' ) . text ) ) : #NEWLINE# #INDENT# logger . debug ( 'No subtitles found' ) #NEWLINE# break #NEWLINE# #UNINDENT# for subtitle_xml in xml . findall ( 'subtitle' ) : #NEWLINE# #INDENT# language = Language . fromietf ( subtitle_xml . find ( 'language' ) . text ) #NEWLINE# hearing_impaired = ( 'n' in ( subtitle_xml . find ( 'flags' ) . text or '' ) ) #NEWLINE# page_link = subtitle_xml . find ( 'url' ) . text #NEWLINE# pid = subtitle_xml . find ( 'pid' ) . text #NEWLINE# releases = [ ] #NEWLINE# if subtitle_xml . find ( 'release' ) . text : #NEWLINE# #INDENT# for release in subtitle_xml . find ( 'release' ) . text . split ( ) : #NEWLINE# #INDENT# release = re . sub ( '\\.+$' , '' , release ) #NEWLINE# release = '' . join ( filter ( ( lambda x : ( ord ( x ) < 128 ) ) , release ) ) #NEWLINE# releases . append ( release ) #NEWLINE# #UNINDENT# #UNINDENT# title = subtitle_xml . find ( 'title' ) . text #NEWLINE# season = int ( subtitle_xml . find ( 'tvSeason' ) . text ) #NEWLINE# episode = int ( subtitle_xml . find ( 'tvEpisode' ) . text ) #NEWLINE# year = int ( subtitle_xml . find ( 'year' ) . text ) #NEWLINE# if is_episode : #NEWLINE# #INDENT# subtitle = PodnapisiSubtitle ( language , hearing_impaired , page_link , pid , releases , title , season = season , episode = episode , year = year ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# subtitle = PodnapisiSubtitle ( language , params , page_link , pid , releases , title , year = year ) #NEWLINE# #UNINDENT# if ( pid in pids ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# logger . debug ( 'Found subtitle %r' , subtitle ) #NEWLINE# subtitles . append ( subtitle ) #NEWLINE# pids . add ( pid ) #NEWLINE# #UNINDENT# if ( int ( xml . find ( 'pagination/current' ) . text ) >= int ( xml . find ( 'pagination/count' ) . text ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# params [ 'page' ] = ( int ( xml . find ( 'pagination/current' ) . text ) + 1 ) #NEWLINE# logger . debug ( 'Getting page %d' , params [ 'page' ] ) #NEWLINE# #UNINDENT# return subtitles