Feature request: The command line interface should allow to override author and some other metadata

Bug #951063 reported by Tomáš Pěnička
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
calibre
Fix Released
Undecided
Unassigned

Bug Description

The command line interface should allow to override author of the book and possible some other metadata.

Current state:
User can create an empty book and specify title, author and ISBN of the book.
If user specifies a file to import, all the metadata (at least author, I didn't check the others) are derived from the file contents or from the file name (depends on settings of Calibre). Consider for example the folowing command

calibredb add -a "Some cool author" -t "Excellent book" "dirname/some name - some title.txt"

It creates a book with author "some name" and title "some title". The arguments of -a -and -t are silently ignored.

Proposed bahaviour:
When the options -a, -t or -i are used, their arguments should override the values which calibre tries to guess from the filename or from the file contents. So the command above should create a book with author "Some cool author" and title "Excellent book".

What's the point
Some people have quite well structured collection on their harddisk, where they have a separate directory for each author and the books inside, but the (book) filename does not contain the author name, or the author name is somehow mangled, truncated etc. Since the standard Calibre cannot read the author name from the directory name, this solution is a workaround for people who need it. It is quite simple to write a command which imports the whole directory of books and give them the same author name.

Implementation should be straightforward. The functionality is implemented in file /src/calibre/library/cli.py. It is needed to add several parameters to function do_add on line 207, compare to function do_add_empty on line 313. Line numbers are from http://bazaar.launchpad.net/~kovid/calibre/trunk/view/head:/src/calibre/library/cli.py revision 11646.

Related branches

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

This isn't worth the effort to me. You can use ebook-meta to set the metadata
in the files before importing, or use calibredb show_metadata--as-opf and
calibredb set_metadata to change the emtadata after importing. If you really
want this functionality, submit a patch, I will merge it.

 status wontfix

Changed in calibre:
status: New → Won't Fix
Revision history for this message
Tomáš Pěnička (tom-penicka) wrote :

Hello,
  here is the patch. I altered only the file cli.py, mainly because I have no possibiity to test the changes in other files. It is the patch against 0.8.43

The patch allows to set author, title and isbn for books added from a file (i.e. not using the possibility to add a whole directory at once). The patch for the whole directory functionality would require to change also other files, which I cannot test.

Notice for users who need this patch if it is still not merged into official release:

It is possible to alter the command line interface without changing the official release. You need this patch and original source of the file cli.py corresponding to the version of calibre you are using. Here are the steps:

1. Get the source file cli.py matching your version of calibre. It seems that the file is not changed very often, so some version which is "near" should suffice. Either download the source code and from the tar ball get the file calibre/src/calibre/library/cli.py or download it from the bazaar (the link is in my previous comment).

2. Patch the file cli.py with the attached path. The patch is very simple, so it is possible to do it manually. Let's call the patched fie mycli.py

3. Use the command calibre-debug and run the patched file. The command line should look like
calibre-debug -e mycli.py [arguments for calibredb]
for example on Windows I used

C:\calibre_instal_dir\calibre-debug -e mycli.py add -a "Cool Author" -t "Title of the book" -i 1234567890 path_to_file

Cheers,

Tomas

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

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

 status fixreleased

Changed in calibre:
status: Won't Fix → Fix Released
Changed in calibre:
status: Fix Released → Incomplete
Revision history for this message
Tomáš Pěnička (tom-penicka) wrote :

Hello Kovid,
  thank you for releasing the change, but it still doesn't work. There are 2 reasons:
1. There is a typo
2. Authors should be filled as an array into the function do_add.
Changes needed (file src/calibre/library/cli.py):

Ad 1:
The lines (function do_add, somewhere around line 238)
            for x in ('title', 'authors', 'isbn', 'tags', 'series'):
                val = locals()['o'+x]
                if val: setattr(mi, x[1:], val)
            if oseries:
                mi.series_index = oseries_index

Should be

            for x in ('title', 'authors', 'isbn', 'tags', 'series', 'series_index'):
                val = locals()['o'+x]
                if val: setattr(mi, x, val)
(notice the added series_index on the first line and change x[1:] to x on the last line)

Ad 2:
The lines (function command_add, somewhere around line 359)

    do_add(get_db(dbpath, opts), args[1:], opts.one_book_per_directory,
            opts.recurse, opts.duplicates, opts.title, opts.authors, opts.isbn,
            tags, opts.series, opts.series_index)

Should be

    do_add(get_db(dbpath, opts), args[1:], opts.one_book_per_directory,
            opts.recurse, opts.duplicates, opts.title, aut, opts.isbn,
            tags, opts.series, opts.series_index)
(change opts.authors to aut)

(Today I had a day of the Great On-Turning, when I launched the import of rather bigger number of ebooks, so I realised that the import doesn't work as I need. The workaround is the same as I mentioned earlier)

Cheers,

Tomas

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

Both those typos were fixed a while ago.

 status fixreleased

Changed in calibre:
status: Incomplete → 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.