def __init__(self, filename, filetype='autodetect', opts=None, transfo_opts=None): if opts is None: opts = [] if not isinstance(opts, list): raise ValueError('opts must be a list of option names! Received: type=%s val=%s', type(opts), opts) if transfo_opts is None: transfo_opts = {} if not isinstance(transfo_opts, dict): raise ValueError('transfo_opts must be a dict of { transfo_name: (args, kwargs) }. ' + 'Received: type=%s val=%s', type(transfo_opts), transfo_opts) valid_filetypes = ('autodetect', 'subtitle', 'info', 'video', 'movie', 'moviesubtitle', 'movieinfo', 'episode', 'episodesubtitle', 'episodeinfo') if filetype not in valid_filetypes: raise ValueError("filetype needs to be one of %s" % valid_filetypes) if not PY3 and not isinstance(filename, unicode): log.warning('Given filename to matcher is not unicode...') filename = filename.decode('utf-8') filename = normalize_unicode(filename) self.filename = filename self.match_tree = MatchTree(filename) self.filetype = filetype self.opts = opts self.transfo_opts = transfo_opts self._transfo_calls = [] # sanity check: make sure we don't process a (mostly) empty string if clean_string(filename) == '': return try: mtree = self.match_tree mtree.guess.set('type', filetype, confidence=1.0) for transformer in transfo_manager.get_transformers(): self._apply_transfo(transformer) log.debug('Found match tree:\n%s' % u(mtree)) except TransfoException as e: log.debug('An error has occured in Transformer %s: %s' % (e.transformer, e.message))
def display_properties(): print('Available transformers:') for transformer in transfo_manager.get_transformers(): priority = 0 if hasattr(transformer, 'priority'): priority = transformer.priority print('\t%s [%i]' % (transformer.__name__, priority)) if hasattr(transformer, 'supported_properties'): for property_name, possible_values in transformer.supported_properties.items(): order_values = sorted(list(set(possible_values)), key=unicode.lower) values_str = u'' for v in order_values: if values_str: values_str += ', ' values_str += v print('\t\t%s: [%s]' % (property_name, values_str)) print('Available properties:') pass