View Single Post
Old 07-22-2014, 05:12 PM   #1
Ackis
Member
Ackis began at the beginning.
 
Posts: 21
Karma: 10
Join Date: Sep 2013
Location: Canada
Device: Galaxy Tab 2 10.1, iPad 2
ebook-convert doesn't add converted version to library?

I decided to write a quick bash script to convert my ebook formats into epub which Marvin can read (bloody wife is using the Android so I can't use moonreader). When I converted a few files, they weren't automatically added to the Calibre library. Is that intended behaviour, and if so what's the best way to work around it?

As an aside, should I run ebook-polish on newly converted files (e.g. remove unused CSS)?

Code:
#! /bin/bash

fullfilename=${0##*/}
filename="${fullfilename%.*}"
logfile="/var/log/scripts/$filename.log"
convertpath="/tmp/ebookconvert"

echo "Script output will be logged to $logfile"

#exec > "$logfile" 2>&1

/opt/scripts/scriptheader.sh "eBook Convert"

test -e "$convertpath" || mkdir "$convertpath"

if ! [[ -f "/usr/bin/ebook-convert" ]]; then
        echo "ebook-convert not found. Aborting."
        exit 1
fi

if [[ -z $1 ]]; then
        echo "No argument supplied.  Please enter the path you which to convert."
        exit 1
elif ! [[ -d "$1" ]]; then
        echo "Argument passed is not a directory."
        exit 1
fi

echo "Scanning $1 for ebooks files..."

# List the types of files in the directory
echo "eBook file types detected:"
find "$1" -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u

# Find the media types that will be converted.
# Useful for verifying after the fact.
echo "Files will be copied to '$convertpath' before conversion."

find "$1" -type f -name "*.mobi" -o -type f -name "*.lit" -o -type f -name "*.pdf" > "$convertpath/ebooklist.txt"

echo "Converting MOBI Files."

find "$1" -type f -name "*.mobi" | while read line; do
        # Check to see if we already have the format.
        if ! [[ -f "${line%.mobi}.epub" ]]; then
                /usr/bin/ebook-convert "$line" "${line%.mobi}.epub";
                if [ $? -ne 0 ]; then
                        echo "Error converting $line.";
                fi
        else
                echo "ePub for $line exists already, no conversion needed.";
        fi
done
Ackis is offline   Reply With Quote