Electronics and other geeky pursuits!


Calibre Leaving Old News on My Sony Reader — Delete It!

I haven’t had much use for book readers, but I saw a Sony PRS-300 in the Sony Outlet Store for only $40 so I bought it. No Linux software, but it does work well with Calibre, so I’ve been very happy with it. It is tiny and has amazing battery life and it is a great alternative to lugging my tablet around all the time.

Calibre has a great feature where it can grab things off the Web, make them into eBooks and put them on your device. They have lots of precreated feeds like the BBC, CNN, etc. There is an option to tell Calibre to remove the news after it is a certain number of days old.

I thought this wasn’t working because stuff was accumulating on my device. However, a little research showed that it is a quirk of Calibre. It removes the news from your library but not the Reader! Oops.

I decided I can run a little script to trim old news from the reader. I may change the Calibre shortcut to do this automatically before it runs Calibre in the future. Here’s the script in case you find it useful:

NOTE: DO NOT USE THIS CODE, use the code below!

#!/bin/bash
# Detele old news files from Sony Reader
# Usage: trimsony [days]
# Default is 5 days (delete things older than 5 days)
echo NO DON'T USE THIS!!!
exit 0

# Check this file to see that reader is connected
READERPRESENTFILE=/media/READER/metadata.calibre
# Directory that holds news
MEDIADIR=/media/READER/database/media/books/News

if [ ! -f $READERPRESENTFILE ]
then
echo Error: Reader not connected! 2>&1
exit 1
fi
DAYS=5
if [ "$1" != "" ]
then
DAYS=$1
fi
# All subscriptions are in /media/READER/database/media/books/News
find $MEDIADIR -type f -mtime +$DAYS -exec rm {} \;
exit 0

You can change the directories and the number of days used by default pretty easily if you like.

Enjoy!

UPDATE: I’m not so sure this is a good idea anymore. I have to run more tests. It does work, but I think deleting files off the Sony makes its media.xml database get out of sync and I can’t figure out what syncs it. Sometimes Calibre gets the dreaded media.xml is corrupt message and then getting it to stop doing that is a massive inconvenience. I’m still looking into it, but be warned!

Update 2: Ok I’m back to try again. I found Calibre has a poorly-documented ebook-device command that lets you do command line operations. I also used kdialog to give a progress bar because it is slow. That means you need kdialog, qdbus, and other stuff that you already have if you are running KDE. However, you could remove that or replace it with other things if you aren’t.


#!/bin/bash
# Detele old news files from Sony Reader
# Usage: trimsony [days]
# Default is 5 days (delete things older than 5 days)

# Mount directory (no trailing slash please)
MOUNT=/media/READER
# Check this file to see that reader is connected
READERPRESENTFILE=$MOUNT/metadata.calibre
# Directory that holds news
MEDIADIR=$MOUNT/database/media/books/News

if [ "$1" == '-' ]
then
dbusRef=$2
CT=`qdbus $dbusRef Get "" value`
CT=`expr $CT + 1`
qdbus $dbusRef Set "" value $CT
BASE=`basename "$3"`
qdbus $dbusRef setLabelText "Removing $BASE"
FILE="${3##$MOUNT}"
echo -n $FILE
ebook-device rm "$FILE"
exit 0
fi

if [ ! -f $READERPRESENTFILE ]
then
echo Error: Reader not connected! 2>&1
exit 1
fi
DAYS=5
if [ "$1" != "" ]
then
DAYS=$1
fi
# All subscriptions are in /media/READER/database/media/books/News
COUNT=`find $MEDIADIR -type f -mtime +$DAYS | wc -l`
if [ "$COUNT" != 0 ]
then
# this desyncs the database!
#find $MEDIADIR -type f -mtime +$DAYS -exec rm {} \;
dbusRef=`kdialog --progressbar "Deleting old news" $COUNT`
qdbus $dbusRef Set "" value 0
find $MEDIADIR -type f -mtime +$DAYS -exec $0 - "$dbusRef" "{}" \;
qdbus $dbusRef close
fi
exit 0

One Response to Calibre Leaving Old News on My Sony Reader — Delete It!

  1. This looks great, but a bit beyond my capabilities. Is it possible to create make this into a plugin for calibre?



©2014 Hotsolder Entries (RSS) and Comments (RSS)  Raindrops Theme