My workflow covers two essential libraries. "Top Calibre" contains all the hand-tagged and curated books I actually read (or intend to read). The other "Calibre Trunk" is a staging library for everything I download from various sources. All books go to the trunk library where they are scanned for eligible placement into Top Calibre.
I tried to use Calibre's built-in auto-add feature, but it threw two snags.
First, Calibre must be running for it to work. This is a problem for me as I don't even use a GUI on this laptop which has only 2G RAM. Launching Calibre is a resource intensive task for me, especially when the first thing it tries to do is import a hundred books at once.
Second, there is no option to select which library one would like the books added to. Actually, when the feature was enabled, the books were added to whichever library I was using at the time. No good.
Here is a simple script to automate this via a simple cron job which runs every 20 minutes (on my system).
Code:
#!/bin/bash
# This script adds books downloaded by autodl-irssi into a
# secondary Calibre Library then cleans up after itself.
# Meant to be run as a cron replacement to Calibre's import/delete functionality.
# Note-- the files in the target directories are copies of what is still seeding.
# Do not run this script against seeding files if you care about ratio.
# First we define our download directories
MAM=~/torrents/rtorrent/complete/MAM-Books
IPT=~/torrents/rtorrent/complete/IPT-Books
TD=~/torrents/rtorrent/complete/TD-Books
TL=~/torrents/rtorrent/complete/TL-Books
AR=~/torrents/rtorrent/complete/AR-Books
# We check to see if Calibre is running and abort if it is.
if pgrep -f "calibre" > /dev/null
then
:
else
# We import and delete our books
find $MAM $IPT $TD $AR $TL -regextype posix-extended -regex \
'.*\.(epub|epub3|mobi|azw|azw3|azw4|pdf|chm|djvu|lrf|fb2|lit|pdb)$' \
-exec calibredb --library-path=~/Books/CalibreTrunk add --duplicates {} \; \
-exec rm -rf {} \; &&
# We take out the trash
find $MAM $IPT $TD $AR $TL -regextype posix-extended -regex \
'.*\.(txt|kfx|jpg|jpeg|opf|cbz|cbr|rar|zip|png)$' \
-exec rm -rf {} \; &&
# We clean up after ourselves
find $MAM $IPT $TD $AR $TL -mindepth 1 -type d -empty -delete
fi
exit
Improve and/or enjoy.