![]() |
#1 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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) 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. ![]() Last edited by Format C:; 07-11-2008 at 09:35 AM. Reason: Added script as attachment |
![]() |
![]() |
![]() |
#2 |
reader
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 6,977
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. |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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... ![]() |
![]() |
![]() |
![]() |
#4 |
Member
![]() 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 |
![]() |
![]() |
![]() |
#5 | |
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 753
Karma: 1496807
Join Date: Jul 2008
Location: The Third World
Device: iLiad + PRS-505 + Kindle 3
|
Quote:
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! ![]() |
|
![]() |
![]() |
Advert | |
|
![]() |
|
![]() |
||||
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 |