def __searchParser(self, query):

        """
        Parse `query` for advanced search options.

        Parameters
        ----------
        query : str
            Search query to parse. Besides a search query, user can specify additional search parameters and YTFS
            specific options. Syntax:
            Additional search parameters: ``option:value``. if `value` contains spaces, then surround it with
            parentheses; available parameters: `channel`, `max`, `before`, `after`, `order`.
            YTFS options: specify options between ``[`` and ``]``; Available options: `a`, `v`, `f`, `P`, `s`, `m`.
            If an option takes a parameter, then specify it beetween parentheses.

            Examples: ``channel:foo search query``, ``my favourite music [a]``,
            ``channel:(the famous funny cats channel) [vf(240)P] funny cats max:20``.

            Invalid parameters/options are ignored.

        Returns
        -------
        params : tuple
            Tuple: 0 - dictionary of url GET parameters; 1 - dictionary of YTStor options.
        """

        ret = dict()

        parse_params = True

        buf = ""
        ptr = ""

        p_avail = ("channel", "max", "before", "after", "order")

        opts = dict()
        par_open = False

        translate = {
            'a': 'audio',
            'v': 'video',
            'f': 'format',
            's': 'stream',
            'P': 'stream',
            'm': 'metadata',
            'max': 'maxResults',
            'channel': 'channelId',
            'before': 'publishedBefore',
            'after': 'publishedAfter',
            'order': 'order',
            '': 'q'
        }

        for i in query+' ':

            if parse_params:

                if not par_open:

                    if i == ' ': # flush buf

                        try:
                            if ret.get(translate[ptr]):
                                ret[ translate[ptr] ] += ' '
                            else:
                                ret[ translate[ptr] ] = ''

                            ret[ translate[ptr] ] += buf

                        except KeyError:
                            pass

                        ptr = ""
                        buf = ""

                    elif i == ':' and buf in p_avail:

                        ptr = buf
                        buf = ""

                    elif not buf and i == '[': # buf must be empty

                        parse_params = False
                        ptr = ""

                    elif i != '(':
                        buf += i

                elif not (par_open == 1 and i == ')'):
                    buf += i

                if i == '(': par_open += 1
                if par_open > 0 and i == ')': par_open -= 1


            else:

                if i == ']':

                    parse_params = True
                    par_open = False
                    ptr = ""
                    buf = ""

                elif ptr and not par_open and i == '(':
                    par_open = True

                elif par_open:

                    if i == ')':

                        try:
                            opts[ translate[ptr] ] = buf
                        except KeyError:
                            pass

                        par_open = False
                        buf = ""

                    else:
                        buf += i

                elif i.isalpha():

                    ptr = i

                    try:
                        opts[ translate[ptr] ] = not i.isupper()
                    except __HOLE__:
                        pass

        return (ret, opts)
dataset/ETHPy150Open rasguanabana/ytfs/ytfs/actions.py/YTActions.__searchParser