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

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 01-19-2015, 09:20 PM   #1
danjcla
Junior Member
danjcla began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Jan 2015
Device: Kindle Paperwhite
Directory tree in-place "author" -> "folder + author" script (where folder=category)

Couldn't find a way to do this with the GUI, so here's a script using Calibre's "ebook-meta" command that, for each .mobi file in a directory tree, changes the author metadata in the file to be:

..directory the file is in..original author..

Where the name of the directory the file is in is something you are using as a category, e.g. "stuff for my x class" or "learning about kiwi fruit".

I choose .. as it's fast to type on the Kindle PaperWhite 2 virtual keyboard when you do searches.

You can run in as many times as you want, nothing will change unless you move files around, at which point the author metadata will change to reflect that.

I did look into - and get helpful pointers regarding - doing this from the GUI, but in the end this seems faster and a whole lot simpler for my current needs.

Of course would be happy to know if others have already done this in a more robust fashion.

Code:
#!/bin/bash

EBOOKMETA="/Applications/calibre.app/Contents/MacOS/ebook-meta"
KINDLEROOT="/Volumes/Kindle"

# --

if [ ! -x $EBOOKMETA ]; then
  echo "ERROR: $EBOOKMETA doesn't exist"
  exit 200
fi

if [ ! -d $KINDLEROOT ]; then
  echo "ERROR: $KINDLEROOT doesn't exist"
  exit 200
fi

# --

find $KINDLEROOT -type f -name '[a-zA-Z0-9]*.mobi' -print0 | while read -d $'\0' FILE
do

  AUTHOR="$(/Applications/calibre.app/Contents/MacOS/ebook-meta "$FILE" --to-opf=/dev/null | grep ^Author | sed 's/Author(s)           : //g')"
  FOLDER="$(basename $(dirname "$FILE"))"

  if [[ $AUTHOR == *".."* ]]; then
    METAAUTHOR="$(echo $AUTHOR | awk -F '\\..' '{print $3}')"
    $EBOOKMETA "$FILE" -a "..${FOLDER}..${METAAUTHOR}.."
  else
    $EBOOKMETA "$FILE" -a "..${FOLDER}..${AUTHOR}.."
  fi

done
This is alpha - use at your own risk!

Last edited by danjcla; 01-19-2015 at 09:28 PM.
danjcla is offline   Reply With Quote
Old 02-01-2015, 10:28 PM   #2
LadyKate
Fanatic
LadyKate ought to be getting tired of karma fortunes by now.LadyKate ought to be getting tired of karma fortunes by now.LadyKate ought to be getting tired of karma fortunes by now.LadyKate ought to be getting tired of karma fortunes by now.LadyKate ought to be getting tired of karma fortunes by now.LadyKate ought to be getting tired of karma fortunes by now.LadyKate ought to be getting tired of karma fortunes by now.LadyKate ought to be getting tired of karma fortunes by now.LadyKate ought to be getting tired of karma fortunes by now.LadyKate ought to be getting tired of karma fortunes by now.LadyKate ought to be getting tired of karma fortunes by now.
 
Posts: 511
Karma: 1470724
Join Date: Jul 2013
Location: Quebec CA
Device: android 4 (samsung tablet and asus tablet)
Ummm, I'm trying to figure out what the purpose of this script is. How is it used and why?
LadyKate is offline   Reply With Quote
Advert
Old 02-01-2015, 11:23 PM   #3
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,363
Karma: 83238367
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
It is used to change the author field of ebooks depending on the folder structure. The purpose: to avoid having to use calibre's library management capabilities just to get plugboards.
eschwartz 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
Swaping "titles" versus "author" duytrung Library Management 11 12-08-2014 10:53 PM
Apple Mac now have a file extension ".iba" for the program "iBooks Author." brucehobson Calibre 3 09-15-2014 07:46 PM
"open containing folder" gives no such directory under Linux exachillus Calibre 1 01-30-2014 01:02 AM
"Send to Main Memory" greyed out after "Connect to folder" myce Calibre 16 01-15-2014 04:03 PM
A warning for Linux users: slow "Add Books", "Unknown" title and Author rolgiati Library Management 8 07-24-2013 04:36 PM


All times are GMT -4. The time now is 02:39 AM.


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