Overwriting of formats with different languages

Bug #864172 reported by EnriqueP
16
This bug affects 3 people
Affects Status Importance Assigned to Milestone
calibre
Fix Released
Undecided
Unassigned

Bug Description

When preferences are set to "Automerge added books if they already exist in the calibre library" _and_ "Overwrite existing duplicate formats", adding a book in language xx to the library overwrites an existing book file (if same title & author) in language yy.

Two facilitate keeping two different versions of the same book in two different languages, I suggest that Calibre does not consider two books in different languages as "the same book", even if they have the same title & author. When this happens (same title, same author, different language) "Automerge added books" should automatically revert to "Create new record for each duplicate format" (or give the option to do so, adding a duplicate entry), instead of plainly "Overwriting....", even if that is set as the default behavior.

Using Calibre 0.8.21, Windows 7 x64

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

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
Juan Pedro Paredes (juampe) wrote :

The automerge is very useful functionality to keep unicity in muntilingual librarys (avoid duplicates and update book with new versions )
(In my Library management I have to update with new versions of the book's content along the time, and keep the last one)
I have several books with the title in English but in diferent languages,(for example Dune in english and spanish). Automerge did not work well for this case,( it overwrite the spanish version with the english version, and book data is lost).
I think this is a killer functionality.
Please help me to help.

Revision history for this message
Juan Pedro Paredes (juampe) wrote :

Tryng to reopen

Changed in calibre:
assignee: nobody → Juan Pedro Paredes (juampe)
Changed in calibre:
assignee: Juan Pedro Paredes (juampe) → nobody
Revision history for this message
Kovid Goyal (kovid) wrote :

The code for adding and duplicate processing is in gui2/add.py instructions for setting upa calibre devlopment anvironment are in the user manual. Feel free to ask if you have more questions.

Changed in calibre:
status: Won't Fix → New
Revision history for this message
Juan Pedro Paredes (juampe) wrote :

Thanks Kovid for the information, I'm reviewing the instructions and code.

Revision history for this message
Juan Pedro Paredes (juampe) wrote :

With the calibre manual I have trouble for Debian distro
The environment variable to develop instead of
CALIBRE_DEVELOP_FROM
is
CALIBRE_PYTHON_PATH

I continue reviewing the code

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

Do not use the distro provided version of calibre, use the official
calibre binary from http://calibre-ebook.com/download_linux

Revision history for this message
Juan Pedro Paredes (juampe) wrote :

Hi!
Some study, some work and some tests later, I think I found a fix for this problem.
Thanks for your help.

Revision history for this message
Juan Pedro Paredes (juampe) wrote :

In linux (official download and install as requested ) works well the fix, but in windows I have some trouble , I'll work in this.

both calibre, version 2.50.1 with development GIT up-to-date

ERROR: Errors while adding: Failed to add any books, click "Show details" for more information

----------------------------------------------------------------------
Failed to read metadata from the file(s):
 //Books/[Dune 01] Herbert, Frank - Dune [325] (r1.8).epub
With error:
Traceback (most recent call last):
  File "P:\Work\calibre\src\calibre\gui2\add.py", line 263, in monitor_pool
  File "P:\Work\calibre\src\calibre\gui2\add.py", line 315, in process_result
  File "P:\Work\calibre\src\calibre\db\utils.py", line 63, in find_identical_books
  File "P:\Work\calibre\src\calibre\db\utils.py", line 63, in <setcomp>
NameError: global name 'aid_map' is not defined

Revision history for this message
Juan Pedro Paredes (juampe) wrote :

Fixed dummy space in diff file, now works in windows too

Revision history for this message
Juan Pedro Paredes (juampe) wrote :

"BONUS PATCH"
I have a book repository with several releases along the time. The same book is released in several review proceses.
It uses version numbers in the title but I found more operational use mtime to dedide whitch one is the last one.
In order to maintain the last release of a book (in calibre library) and overwrite the older I use the following option for adding books.
"Multiple books per directory -> assumes every ebook file is a different book"
I create patch, for add sorted files by mtime to assure the last release book added is the book with higher mtime overwriting the rest.

Revision history for this message
Juan Pedro Paredes (juampe) wrote :

BONUS PATCH
calibre add directory sorted mtime

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

Some comments:

1) You dont seem to be updating language_map in update_data_for_find_identical_books

2) When checking for matching language, the algorithm needs to be more sophisticated:

  - You have to handle the case of undefined language -- if either the book being added or the matching books have undefined language, then the languages must match

  - You should check against all languages, not just the first. That is, use tuple(mi.languages or ())

In your bonus patch:
1) Never use chdir() the current working directory is a global variable and in a multi-threaded application changing global variables is a recipe for disaster.

2) You have to handle exceptions that can be raised by getmtime()

See https://github.com/kovidgoyal/calibre/commit/97d6c83525716cfcb424980ca7bd69b1c6774982

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

Oh yeah, and also use

languages = tuple(filter(None, map(canonicalize_lang, mi.languages)))

to make sure that language codes are canonicalized before comparing them.

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

no followup

Changed in calibre:
status: New → Invalid
Revision history for this message
Juan Pedro Paredes (juampe) wrote :

As requested, I create a pull request with the requirements
https://github.com/kovidgoyal/calibre/pull/774

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

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.