'Command handler for the metasync function.'

def func(self, lib, opts, args):

    pretend = opts.pretend
    query = ui.decargs(args)
    sources = []
    for source in opts.sources:
        sources.extend(source.split(','))
    sources = (sources or self.config['source'].as_str_seq())
    meta_source_instances = {}
    items = lib.items(query)
    if (not items):
        self._log.info(u'No    items    found    matching    query')
        return
    for player in sources:
        try:
            cls = META_SOURCES[player]
        except KeyError:
            self._log.error(u"Unknown    metadata    source    '{0}'".format(player))
        try:
            meta_source_instances[player] = cls(self.config, self._log)
        except (ImportError, ConfigValueError) as e:
            self._log.error(u"Failed    to    instantiate    metadata    source    '{0}':    {1}".format(player, e))
    if (not meta_source_instances):
        self._log.error(u'No    valid    metadata    sources    found')
        return
    for item in items:
        for meta_source in meta_source_instances.values():
            meta_source.sync_from_source(item)
        changed = ui.show_model_changes(item)
        if (changed and (not pretend)):
            item.store()
