[Enhancement] Paste metadata - Override 'exclude_fields_on_paste' setting

Bug #1953739 reported by No Name
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
calibre
Fix Released
Undecided
Unassigned

Bug Description

Hi ...

A feature to override the 'exclude_fields_on_paste' settings woulde be nice.

I usually use copy/Paste metadata to copy metadata from/to similar books like series ... so i excluded filds like title,comments,... by 'exclude_fields_on_paste' setting

But somtimes i would like to copy ALL metadata ... means override my exclude settings.

This coulde be done in 2 ways:

Changing/adding the Paste metadata submenu to somthing like

Paste metadata(Custom)
Paste metadata(ALL)

where ALL ignores 'exclude_fields_on_paste' setting

or faster and easyer

by Modifier Key ... if i press/hold Ctr or Alt or Shift when clicking "Paste metadata" then exclude is ignored and ALL metadata are inserted.

Thanks

Revision history for this message
Kovid Goyal (kovid) wrote : Re: calibre bug 1953739

This is not worth the effort for me personally. If some one else wants to implement it, I will be happy to supply any needed guidance. If so, re-open the ticket and we can discuss it.

 status wontfix

Changed in calibre:
status: New → Won't Fix
Revision history for this message
No Name (regdummy71) wrote :

I checked the needed code ... its only a small change (2 Lines + Include)...

I'm no Python-Coder and can't compile/test it, but something like this shoulde work:

Changes in edit_metadata.py:

from PyQt5 import QtCore, QtWidgets

<...>

    def paste_metadata(self):
        rows = self.gui.library_view.selectionModel().selectedRows()
        if not rows or len(rows) == 0:
            return error_dialog(self.gui, _('Cannot paste metadata'),
                                _('No books selected'), show=True)
        c = QApplication.clipboard()
        md = c.mimeData()
        if not md.hasFormat('application/calibre-book-metadata'):
            return error_dialog(self.gui, _('Cannot paste metadata'),
                                _('No copied metadata available'), show=True)
        if len(rows) > 1:
            if not confirm(_(
                    'You are pasting metadata onto <b>multiple books</b> ({num_of_books}). Are you'
                    ' sure you want to do that?').format(num_of_books=len(rows)), 'paste-onto-multiple', parent=self.gui):
                return
        data = bytes(md.data('application/calibre-book-metadata'))
        mi = OPF(BytesIO(data), populate_spine=False, read_toc=False, try_to_guess_cover=False).to_book_metadata()
        mi.application_id = mi.uuid_id = None
        exclude = set(tweaks['exclude_fields_on_paste'])
        paste_cover = 'cover' not in exclude
        cover = md.imageData() if paste_cover else None
        exclude.discard('cover')

        # CHANGE START

        if QtWidgets.QApplication.keyboardModifiers() == QtCore.Qt.ControlModifier:
            exclude = []

        # CHANGE END

        for field in exclude:
            mi.set_null(field)
        db = self.gui.current_db
        book_ids = {db.id(r.row()) for r in rows}
        title_excluded = 'title' in exclude
        authors_excluded = 'authors' in exclude

<...>

If control is pressed we let it look like exclude_fields_on_paste = []
It coulde be more fancy but this is the SIMPLEST one ... no other parts of code affected,
all the rest stays unchanged ....

Is the Tichet now Re-Opened ?

Revision history for this message
Kovid Goyal (kovid) wrote :

yes of course, if one is willing to use keyboard modifiers for it, which
I am not. It's completely undiscoverable and counter intuitive that menu
items do different things depending ont he state of keyboard modifiers.

But feel free to use your patch locally, running calibre from source,
just requires setting a single environment variable:
https://manual.calibre-ebook.com/develop.html

Revision history for this message
Charles Haley (cbhaley) wrote :

Coding and testing the change yourself is easy. You don't need to compile or build calibre. See https://manual.calibre-ebook.com/#setting-up-a-calibre-development-environment

Revision history for this message
No Name (regdummy71) wrote :

Yes ... your right ... it isn't intuitive ... but the whole 'exclude_fields_on_paste' isn't intuitive too and oly for Calibre User ... with 'special needs' ;)

It coulde be explained in the comments to the 'exclude_fields_on_paste' setting.
So if sombody need it ... the explanation is there .. at the right place.
If somebody isn't aware if this Setting, he does't even have to know the modifier Key ...

Patching it localy has the downside ... i have to do it for every new version ...
But thanks for the hint with the developement environment ... i wasn't aware of it.

I hope i have more luck with my
'[Enhancement] Polish books - metadata blacklist' Feature Request:

Affter a short check over the code it shoulde be something like this:
(Yes .... i borrowd the code from edit_metadata.py)

In ...\polish\main.py:

def update_metadata(ebook, new_opf):
    from calibre.ebooks.metadata.opf import get_metadata, set_metadata
    with ebook.open(ebook.opf_name, 'r+b') as stream, open(new_opf, 'rb') as ns:
        mi = get_metadata(ns)[0]
        mi.cover, mi.cover_data = None, (None, None)

        # CHANGES START

        exclude = set(tweaks['exclude_fields_on_polish'])
        for field in exclude:
            mi.set_null(field)

        # CHANGES END

        opfbytes = set_metadata(stream, mi, apply_null=True, update_timestamp=True)[0]
        stream.seek(0)
        stream.truncate()
        stream.write(opfbytes)

+ An entry and explenation in the default_tweaks.py config file

Thanks ...

Revision history for this message
Kovid Goyal (kovid) wrote : Fixed in master

Fixed in branch master. The fix will be in the next release. calibre is usually released every alternate Friday.

 status fixreleased

Changed in calibre:
status: Won't Fix → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers