Example #1
0
def format_group(db, notify_changes, is_remote, args):
    formats, add_duplicates, cover_data = args
    with add_ctx(), TemporaryDirectory(
            'add-multiple') as tdir, run_import_plugins_before_metadata(tdir):
        if is_remote:
            paths = []
            for name, data in formats:
                with lopen(os.path.join(tdir, os.path.basename(name)),
                           'wb') as f:
                    f.write(data)
                paths.append(f.name)
        else:
            paths = list(formats)
        paths = run_import_plugins(paths)
        mi = metadata_from_formats(paths)
        if mi.title is None:
            return None, set(), False
        if cover_data and not mi.cover_data or not mi.cover_data[1]:
            mi.cover_data = 'jpeg', cover_data
        ids, dups = db.add_books([(mi, create_format_map(paths))],
                                 add_duplicates=add_duplicates,
                                 run_hooks=False)
        if is_remote:
            notify_changes(books_added(ids))
        db.dump_metadata()
        return mi.title, ids, bool(dups)
Example #2
0
def format_group(db, notify_changes, is_remote, args):
    formats, add_duplicates, oautomerge, request_id, cover_data = args
    with add_ctx(), TemporaryDirectory(
            'add-multiple') as tdir, run_import_plugins_before_metadata(tdir):
        updated_ids = {}
        if is_remote:
            paths = []
            for name, data in formats:
                with lopen(os.path.join(tdir, os.path.basename(name)),
                           'wb') as f:
                    f.write(data)
                paths.append(f.name)
        else:
            paths = list(formats)
        paths = run_import_plugins(paths)
        mi = metadata_from_formats(paths)
        if mi.title is None:
            return None, set(), set(), False
        if cover_data and not mi.cover_data or not mi.cover_data[1]:
            mi.cover_data = 'jpeg', cover_data
        format_map = create_format_map(paths)
        added_ids, updated_ids, duplicates = do_adding(
            db, request_id, notify_changes, is_remote, mi, format_map,
            add_duplicates, oautomerge)
        return mi.title, set(added_ids), set(updated_ids), bool(duplicates)
Example #3
0
def format_group(db, notify_changes, is_remote, args):
    formats, add_duplicates = args
    with add_ctx(), TemporaryDirectory('add-multiple') as tdir, run_import_plugins_before_metadata(tdir):
        if is_remote:
            paths = []
            for name, data in formats:
                with lopen(os.path.join(tdir, name), 'wb') as f:
                    f.write(data)
                paths.append(f.name)
        else:
            paths = list(formats)
        paths = run_import_plugins(paths)
        mi = metadata_from_formats(paths)
        if mi.title is None:
            return None, set(), False
        ids, dups = db.add_books([(mi, create_format_map(paths))], add_duplicates=add_duplicates, run_hooks=False)
        if is_remote:
            notify_changes(books_added(ids))
        db.dump_metadata()
        return mi.title, ids, bool(dups)