Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 01-19-2017, 02:25 PM   #1
mrowz
Member
mrowz began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Sep 2015
Device: iPad Mini/iPhone 6
Importing books via command line *in the background*?

Hello,

I've been using a shell script on OS X to import ebooks using the command line tool like this:

imp="$CALIBREDIR/calibre $BOOKDIR/$book"
eval "$imp"

This works, but Calibre jumps to its front to do the import process. When importing a number of books it renders the computer unusable until all the imports are done.

Is there any way to tell Calibre to do its import in the background so this all happens silently?
mrowz is offline   Reply With Quote
Advert
Old 01-19-2017, 04:46 PM   #2
BetterRed
null operator
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 9,274
Karma: 7809999
Join Date: Mar 2012
Location: Sydney Australia
Device: none
@mrowz - How about using the calibredb add command, see ==>> Command Line Interface

I am not a MAC user so I'm assuming the CL utilities work similar under OSX as they do on Linux and Windows - i.e. no GUI.

BR
BetterRed is offline   Reply With Quote
Old 01-19-2017, 07:50 PM   #3
mrowz
Member
mrowz began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Sep 2015
Device: iPad Mini/iPhone 6
Thanks for the reply... that command does add the book silently like I want, but the imported book doesn't have the cover for some reason.

When I add the book through the GUI or through the original command the cover shows up as expected.

calibredb add has an option -c for a cover file, but these books don't have external cover images.

Any idea how I can get this last part to work?
mrowz is offline   Reply With Quote
Old 01-19-2017, 10:07 PM   #4
BetterRed
null operator
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 9,274
Karma: 7809999
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by mrowz View Post
Any idea how I can get this last part to work?
After adding books, in the library manager select all books with 'cover:false', then use bulk metadata edit, in Basic metadata->Change cover press the Set from ebook file(s) radio button.

BR
BetterRed is offline   Reply With Quote
Old 01-20-2017, 02:37 PM   #5
mrowz
Member
mrowz began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Sep 2015
Device: iPad Mini/iPhone 6
Hmm... is there any way to do that programmatically?

There's the ebook-meta tool, but it doesn't seem to be able to do what you just described. It can set the cover from a file but not from the book itself according to the description:

https://manual.calibre-ebook.com/gen...book-meta.html
mrowz is offline   Reply With Quote
Old 01-20-2017, 04:38 PM   #6
mrowz
Member
mrowz began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Sep 2015
Device: iPad Mini/iPhone 6
Filed an enhancement request on the bug tracker.

From the command line there's only a way to add the cover from a file, but not a way to add the cover from the ebook itself. I tried using ebook-meta to save the cover from the ebook, but it said "no cover found" even though there is a cover that shows up just fine when imported through the GUI.

Ideally "calibredb add" would function just as well as adding through the GUI without me having to set any other options. Barring that, it would be nice to be able to set the cover from the ebook file via the command line.
mrowz is offline   Reply With Quote
Old 01-22-2017, 04:26 PM   #7
signum
Zealot
signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.
 
Posts: 117
Karma: 64428
Join Date: Aug 2011
Device: none
Quote:
Originally Posted by mrowz View Post
Hello,

I've been using a shell script on OS X to import ebooks using the command line tool like this:

imp="$CALIBREDIR/calibre $BOOKDIR/$book"
eval "$imp"

This works, but Calibre jumps to its front to do the import process. When importing a number of books it renders the computer unusable until all the imports are done.

Is there any way to tell Calibre to do its import in the background so this all happens silently?
At the command line, add a space and an ampersand at the end of the shell script name, then hit enter. This will cause it to run in background. You may also have to enter the command "bg". This works in most *nixes, but I haven't actually tried it in OSX, a Unix derivative.
signum is offline   Reply With Quote
Old 01-22-2017, 06:32 PM   #8
mrowz
Member
mrowz began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Sep 2015
Device: iPad Mini/iPhone 6
Quote:
Originally Posted by signum View Post
At the command line, add a space and an ampersand at the end of the shell script name, then hit enter. This will cause it to run in background. You may also have to enter the command "bg". This works in most *nixes, but I haven't actually tried it in OSX, a Unix derivative.
I wish that would work, but it only causes the command to run in the background of the terminal... but since this command actually invokes the Calibre app, the GUI still jumps to the front.
mrowz is offline   Reply With Quote
Old 01-22-2017, 06:34 PM   #9
mrowz
Member
mrowz began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Sep 2015
Device: iPad Mini/iPhone 6
And here's my reply from development:

Quote:
I cannot reproduce,

calibredb add demo.epub

causes the cover to be added from the ebook file. The only case where it
will not work is if the epub file has no declared cover, which requires
rendering of the first page of the file as the cover. That is done using
an instance of WebKit, and WebKit in turn needs access to a GUI display
environment on OS X. Note that this limitation is not present on linux,
where calibre includes a headless QPA backend that allows running WebKit
without an X server, but I dont have the knowledge/intereset to
implement such a backend for OS X. Patches are welcome.

status invalid

** Changed in: calibre
Status: New => Invalid
This is exactly my problem, the epubs I need to import have no declared cover. Looks like I'm SOL unless there is some other command line tool that can render the cover on OS X before calibre imports
mrowz is offline   Reply With Quote
Old 01-23-2017, 02:10 PM   #10
signum
Zealot
signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.signum calls his or her ebook reader Vera.
 
Posts: 117
Karma: 64428
Join Date: Aug 2011
Device: none
Quote:
Originally Posted by mrowz View Post
I wish that would work, but it only causes the command to run in the background of the terminal... but since this command actually invokes the Calibre app, the GUI still jumps to the front.
Here's another thing to consider: Does OSX support multiple virtual terminals or multiple windows or multiple desktops or something like that? If so, start your shell script in one terminal/window/desktop/whatever and switch to another to do a different terminal session.
signum is offline   Reply With Quote
Old 04-20-2017, 01:33 PM   #11
sreknob
Junior Member
sreknob began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Jul 2011
Device: iPad
Have you considered adding ebook-meta $book --get-cover into your workflow? Would need to pipe the output cover file back into your script to import it though...
sreknob is offline   Reply With Quote
Old 05-22-2017, 08:30 PM   #12
mrowz
Member
mrowz began at the beginning.
 
Posts: 19
Karma: 10
Join Date: Sep 2015
Device: iPad Mini/iPhone 6
Yes, as covered in posts #6 and #9 of this thread.

Quote:
Originally Posted by sreknob View Post
Have you considered adding ebook-meta $book --get-cover into your workflow? Would need to pipe the output cover file back into your script to import it though...
mrowz is offline   Reply With Quote
Old 05-26-2017, 12:30 PM   #13
sreknob
Junior Member
sreknob began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Jul 2011
Device: iPad
Ahhhh, sorry, I didn't catch that. If the problem is that a cover isn't declared then perhaps you could have your script find it.

Here are some other options I can think of:

- convert the book to HTML using the ebook-convert commandline and then look in the /images directory for *cover*.jpg/png/gif or the first numbered image and use that image with ebook-meta

- unzip the book or unzip all images from the book into a temporary directory "unzip testbook.epub *.jpg *.png *.gif ...etc" into a temporary directory then parse and pipe back into ebook-meta

Depending on your book source, you might have to do some digging into the structure of the epubs to see what the covers are named and if they are in subfolders (cover/images/...) to get some reliable results.

You also might want to look at this python epub-thumbnailer script for some inspiration. If you look at the script source it shows some good options for finding the cover file.

Good luck!
sreknob is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
View books from command line nichtleiter Calibre 3 12-20-2013 04:05 PM
Adding custom fields when importing books via command line chemi Library Management 7 02-25-2013 11:16 PM
Adding books from command line chemi Library Management 3 02-25-2013 12:28 PM
How to use the command line to move books jorm Development 0 04-03-2012 03:22 PM
Checking and Importing from the Command Line markbond1007 Calibre 3 08-06-2009 01:46 PM


All times are GMT -4. The time now is 10:21 AM.


MobileRead.com is a privately owned, operated and funded community.