def METHOD_NAME(self, lib, opts, args):
    file_path = opts.output
    file_mode = 'a' if opts.append else 'w'
    file_format = opts.format or self.config['default_format'].get(str)
    file_format_is_line_based = (file_format == 'jsonlines')
    format_options = self.config[file_format]['formatting'].get(dict)
    export_format = ExportFormat.factory(
        file_type=file_format,
        **{
            'file_path': file_path,
            'file_mode': file_mode
        }
    )
    if opts.library or opts.album:
        data_collector = library_data
    else:
        data_collector = tag_data
    included_keys = []
    for keys in opts.included_keys:
        included_keys.extend(keys.split(','))
    items = []
    for data_emitter in data_collector(
            lib, ui.decargs(args),
            album=opts.album,
    ):
        try:
            data, item = data_emitter(included_keys or '*')
        except (mediafile.UnreadableFileError, OSError) as ex:
            self._log.error('cannot read file: {0}', ex)
            continue
        for key, value in data.items():
            if isinstance(value, bytes):
                data[key] = util.displayable_path(value)
        if file_format_is_line_based:
            export_format.export(data, **format_options)
        else:
            items += [data]
    if not file_format_is_line_based:
        export_format.export(items, **format_options)