#NEWLINE# def __searchParser( self , query ) : #NEWLINE# #INDENT# '\n        Parse `query` for advanced search options.\n\n        Parameters\n        ----------\n        query : str\n            Search query to parse. Besides a search query, user can specify additional search parameters and YTFS\n            specific options. Syntax:\n            Additional search parameters: ``option:value``. if `value` contains spaces, then surround it with\n            parentheses; available parameters: `channel`, `max`, `before`, `after`, `order`.\n            YTFS options: specify options between ``[`` and ``]``; Available options: `a`, `v`, `f`, `P`, `s`, `m`.\n            If an option takes a parameter, then specify it beetween parentheses.\n\n            Examples: ``channel:foo search query``, ``my favourite music [a]``,\n            ``channel:(the famous funny cats channel) [vf(240)P] funny cats max:20``.\n\n            Invalid parameters/options are ignored.\n\n        Returns\n        -------\n        params : tuple\n            Tuple: 0 - dictionary of url GET parameters; 1 - dictionary of YTStor options.\n        ' #NEWLINE# ret = dict ( ) #NEWLINE# parse_params = True #NEWLINE# buf = '' #NEWLINE# ptr = '' #NEWLINE# p_avail = ( 'channel' , 'max' , 'before' , 'after' , 'order' ) #NEWLINE# opts = dict ( ) #NEWLINE# par_open = False #NEWLINE# translate = { #NEWLINE# #INDENT# 'a' : 'audio' , #NEWLINE# 'v' : 'video' , #NEWLINE# 'f' : 'format' , #NEWLINE# 's' : 'stream' , #NEWLINE# 'P' : 'stream' , #NEWLINE# 'm' : 'metadata' , #NEWLINE# 'max' : 'maxResults' , #NEWLINE# 'channel' : 'channelId' , #NEWLINE# 'before' : 'publishedBefore' , #NEWLINE# 'after' : 'publishedAfter' , #NEWLINE# 'order' : 'order' , #NEWLINE# '' : 'q' , #NEWLINE# #UNINDENT# } #NEWLINE# for i in ( query + ' ' ) : #NEWLINE# #INDENT# if parse_params : #NEWLINE# #INDENT# if ( not par_open ) : #NEWLINE# #INDENT# if ( i == ' ' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ret . get ( translate [ ptr ] ) : #NEWLINE# #INDENT# ret [ translate [ ptr ] ] += ' ' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret [ translate [ ptr ] ] = '' #NEWLINE# #UNINDENT# ret [ translate [ ptr ] ] += buf #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# ptr = '' #NEWLINE# buf = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( i == ':' ) and ( buf in p_avail ) ) : #NEWLINE# #INDENT# ptr = buf #NEWLINE# buf = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( not buf ) and ( i == '[' ) ) : #NEWLINE# #INDENT# parse_params = False #NEWLINE# ptr = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( i != '(' ) : #NEWLINE# #INDENT# buf += i #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( not ( ( par_open == 1 ) and ( i == ')' ) ) ) : #NEWLINE# #INDENT# buf += i #NEWLINE# #UNINDENT# #UNINDENT# if ( i == '(' ) : #NEWLINE# #INDENT# par_open += 1 #NEWLINE# #UNINDENT# if ( ( par_open > 0 ) and ( i == ')' ) ) : #NEWLINE# #INDENT# par_open -= 1 #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( i == ']' ) : #NEWLINE# #INDENT# parse_params = True #NEWLINE# par_open = False #NEWLINE# ptr = '' #NEWLINE# buf = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ptr and ( not par_open ) and ( i == '(' ) ) : #NEWLINE# #INDENT# par_open = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if par_open : #NEWLINE# #INDENT# if ( i == ')' ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# opts [ translate [ ptr ] ] = buf #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# par_open = False #NEWLINE# buf = '' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# buf += i #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if i . isalpha ( ) : #NEWLINE# #INDENT# ptr = i #NEWLINE# try : #NEWLINE# #INDENT# opts [ translate [ ptr ] ] = ( not i . isupper ( ) ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return ( ret , self )