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

Go Back   MobileRead Forums > E-Book Readers > More E-Book Readers > iRex

Notices

Reply
 
Thread Tools Search this Thread
Old 07-11-2008, 06:21 AM   #1
Format C:
Guru
Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.
 
Posts: 753
Karma: 1496807
Join Date: Jul 2008
Location: The Third World
Device: iLiad + PRS-505 + Kindle 3
A script to make iLiad show mobi metadata.

It's my first message, so hello everybody.
I've read this forum for almost two years now, and today I think I may have something interesting to say...



I wrote a little python script to make the iLiad show metadata and covers in contentlister for mobipocket files.
Basically it simply creates one directory for each file, it puts the book into it and it creates a jpg and a manifest file (if the mobi book includes the cover...)

The script invokes "mobi2mobi.exe" to retrieve metadata information from the file, so if I am breaking some licence, please tell me.
Without mobi2mobi the manifest will show defaults for author and title (no filename parsing, sorry).

Usage is simple (mobi2dirs.py -h for help):
Just specify the path to the folder containing the mobipocket books (default: current) and give a name for the cover file (default ".c.jpg").
You can copy all the folders into the iLiad, and it will show covers, titles, and authors (it may not work in the default Mobipocket directory, so better to use another one).

Here it is:

Code:
import os, sys, shutil
from optparse import OptionParser

#error
class DirException(Exception):
	pass

# writes a log file
def logwrite(strings):
	logfile = open("log.txt", "a")
	logfile.write(strings)
	logfile.close()

# put a value between XML tags (no attributes)
def putintags(tag, value):
	return("<" + tag + ">" + value + "</" + tag + ">")

def createmanifest(fname, imgname):
	manifest = open("manifest.xml", "w")
	manifest.write('<?xml version="1.0" encoding="utf-8"?>')
	manifest.write("\n")
	title = "Titolo"
	author = "Autore"
	# dirty trick for to get metadata (author & Title)
	# Uses mobi2mobi.exe capturing the output
	xx=os.popen("mobi2mobi.exe --savethumb " + "\"" + imgname + "\"" + " \"" + fname + "\"", "r")
	#print xx
	for xline in xx:
		if xline.rfind("EXTH    item: 100 - Author") != -1:
			author = xline[34:len(xline)-1]
			#print xline
			print author
		if xline.rfind("LONGTITLE:") != -1:
			title = xline[11:len(xline)-1]
			#print xline
			print title
	xx.close()
	#DC Metadata (include title & author)
	dcmeta = putintags("Title", title) + putintags("Description", author) + putintags("Date", "2007-01-01T00:00:00")
	dcmeta = putintags("dc-metadata", dcmeta)
	#y-metadata
	ymeta = putintags("image", imgname) + putintags("startpage", fname) + putintags("version", "000") + putintags("ItemSize", "000")
	ymeta = putintags("y-metadata", ymeta)
	#the long row
	longrow = putintags("package", putintags("metadata", dcmeta + ymeta))
	manifest.write(longrow + "\n")
	manifest.close()

def createdirs(path, img):
	a = 0
	dirList=os.listdir(path)
	for fname in dirList:
		if fname.endswith(".prc") or fname.endswith(".mobi"):
			a = a + 1
			newname = str(a) + ".mobi"
			os.rename(fname, newname)
			logwrite("ren " + newname + " " + fname + "\n")
			os.mkdir(fname)
			dst = os.path.join(path, fname, fname)
			os.rename(newname, dst)
			shutil.copy("mobi2mobi.exe", os.path.join(path, fname, "mobi2mobi.exe"))
			os.chdir(os.path.join(path, fname))
			print os.getcwd()
			createmanifest(fname, img)
			os.remove("mobi2mobi.exe")
			os.chdir("..");

# Main Function
print "\nMobi2Dir v0.01. Copyright (c) 2008 Nicola Giani"
print "mobi2mobi is part of Mobiperl, by tompe - https://dev.mobileread.com/trac/mobiperl/wiki\n\n"
# parse della linea di comando
parser = OptionParser(usage="mobi2dirs -p <path> -i <image name>")
parser.add_option("-p", "--pathname", dest="pathname", help="Path where mobi files are", metavar="PATH")
parser.add_option("-i", "--imgname", dest="imgname", help="Name of the cover image file (the same for every book)", metavar="IMG")
parser.set_defaults(pathname=os.getcwd())
parser.set_defaults(imgname=".c.jpg")
(options, args) = parser.parse_args()

# controllo degli argomenti e indicazione dei default
p = options.pathname
j = options.imgname

if not os.path.exists(p):
	p = os.getcwd()

os.chdir(p)

createdirs(p, j)
It still need some polishing (and some comments, too, I think).
Since it uses mobi2mobi.exe it only works in DOS/Win boxes.

So it needs:

1. Platform independence
2. More metadata (like date, hardcoded for now)
3. More elegant scripting and error management
4. Some options for filename parsing
5. Other ideas?

Feel free to use it, change it, and, of course, improve it.
And if you have comments and suggestions, they are welcome.

PS: I tested the script on two Windows XP machines and two iliads. It works, but I cannot give warranties of any form.
So it's better to backup mobi files before usage.
And remember: don't write my nickname in the .bat file you use to invoke it.

PPS: it's easy to extend it to work with pdf also. I don't know why I didn't, but i will.

Attached Files
File Type: zip mobi2dris.py.V0.01.zip (1.4 KB, 418 views)

Last edited by Format C:; 07-11-2008 at 09:35 AM. Reason: Added script as attachment
Format C: is offline   Reply With Quote
Old 07-11-2008, 09:13 AM   #2
wallcraft
reader
wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.wallcraft ought to be getting tired of karma fortunes by now.
 
wallcraft's Avatar
 
Posts: 6,975
Karma: 5183568
Join Date: Mar 2006
Location: Mississippi, USA
Device: Kindle 3, Kobo Glo HD
This sounds very useful. Please include the progam as an attachment (e.g. in a .zip since .py isn't allowed). This will also allow you to keep the most recent version in the 1st post.

Note that mobi2oeb.py from Calibre is a python script that does some of what you are using mobi2mobi for. I'm not sure it is useful in its current form (since it explodes the entire mobi, and you just need the metadata and the cover image), but you might be able to extract out the bits you need. I assume it is also possible to invoke mobi2mobi.pl on other machine types from Python, but at a minimum that requires Perl.

Has anyone tried creating subdirectories inside the Mobipocket directory under Windows and on the iLiad? I always assumed that the reason the iLiad treated the Mobipocket directory differently to all other directories (i.e. not creating one subdirectory per ebook) is that Windows Desktop Reader can't handle subdirectories. But perhaps if subdirectories exist they are ok (it is just that MobiPocket won't create them). My point here is that perhaps this tool can be used in the Windows Mobipocket directory, but this needs confirmation one way or the other.
wallcraft is offline   Reply With Quote
Advert
Old 07-11-2008, 09:32 AM   #3
Format C:
Guru
Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.
 
Posts: 753
Karma: 1496807
Join Date: Jul 2008
Location: The Third World
Device: iLiad + PRS-505 + Kindle 3
Afaik, Mobipocket Desktop does not read subdirectories.
And with the last version, I can't even change the default directory to store books into (it resets at every start-up of the software).

I'd like to import my books keeping them in different subdirectories, but I can't. But that's another problem...

With this script I keep my books organized with Total Commander, and I use that same tool to synchronize the iLiad...

Format C: is offline   Reply With Quote
Old 09-18-2008, 04:28 PM   #4
Ragnala
Member
Ragnala began at the beginning.
 
Posts: 20
Karma: 10
Join Date: Sep 2008
Location: Lambsheim
Device: Irex Iliad; PB603
Hi,

I am not very happy with how the Iliad shows the info about the books in my mobipocket folder. It's either the filename or with bought books only the title. Would your script help me with my problems, and if yes ... I am a total noob. I already have shell access, what do I have to do, so that it works?

Thanks,
Babsi
Ragnala is offline   Reply With Quote
Old 09-23-2008, 10:45 AM   #5
Format C:
Guru
Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.Format C: ought to be getting tired of karma fortunes by now.
 
Posts: 753
Karma: 1496807
Join Date: Jul 2008
Location: The Third World
Device: iLiad + PRS-505 + Kindle 3
Quote:
Originally Posted by Ragnala View Post
Hi,

I am not very happy with how the Iliad shows the info about the books in my mobipocket folder. It's either the filename or with bought books only the title. Would your script help me with my problems, and if yes ... I am a total noob. I already have shell access, what do I have to do, so that it works?

Thanks,
Babsi
The script runs on your computer, not on the iLiad.
You need to install a software called "Python" (google for the right version for your computer).
You can follow the instruction provided by python itself for the installation.

After that you can create a directory on your PC, put your books in it, and run the script (open a shell window and run the command line).
It does not work with DRM protected books, so you have to unprotect them to make iLiad show covers and metadata (look in the Mobipocket forum: you'll find another python script to remove protection).

After the run of the script you'll find a set of folders, one per book. Just copy them to your iLiad via USB and enjoy!

Format C: is offline   Reply With Quote
Advert
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to make Igor's script work sunshine6855 Kindle Developer's Corner 160 03-12-2009 09:54 AM
iLiad How to make iliad into a SSH server and connect with iLiad tudou331100 iRex Developer's Corner 21 02-06-2009 05:35 AM
Could you make a script for changing button shortcut for me? harpum iRex 42 07-13-2008 02:00 AM
How can I make a automated script to put a converted lrf to reader?(Sync problem) harpum Sony Reader 4 07-17-2007 12:38 PM
Anyone willing to show off thier Iliad? skestes iRex 4 07-29-2006 05:59 AM


All times are GMT -4. The time now is 05:31 PM.


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