View Single Post
Old 03-11-2008, 10:24 AM   #1
gwynevans
Wizzard
gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.gwynevans ought to be getting tired of karma fortunes by now.
 
gwynevans's Avatar
 
Posts: 1,402
Karma: 2000000
Join Date: Nov 2007
Location: UK
Device: iPad 2, iPhone 6s, Kindle Voyage & Kindle PaperWhite
Python script to create collections

Just in case this might be useful to someone else...

I've attatched a Python script that I've created that reads the internal metadata DB on the 505 and creates collections based on the filenames of the books found there. It's nothing particularly new, as there's a Perl script to do something similar, as well as kovid's code in libprs500, but I wanted a minimal implementation.

It's only going to be directly useful if you use the same format filenames as I do, but if not, it should be easy enough to modify. I use a "<author> - [<series> - ]<title>.<ext>" format, e.g. "Brenner, Meyer Alan - The Dance of Gods 1 - Catastrophe&apos;s Spell.lrf", so the script can pick out that it's part of a "The Dance of Gods" series and create & populate a collection of the same name.

I've not tried to create the 'book' entries from scratch, so I currently just parse the books the reader's already entered there, which means that when adding books, you need to let the reader sync (after the USB disconnect) before resyncing to get at the 'new' media.xml file. My Python's still very basic (and linear), so I'm sure there's a lot that could be done to tidy it up too!

Anyway, you pass the filespec of the 'media.xml' file (e.g. lrfCategorize.py a:\database\cache\media.xml) and it'll save the old one to media.xml.sav and create a new media.xml with the new categories. Categories that don't match ones found from filespecs are left alone, while any files not in a category are put into an '_Other' category.
Attached Files
File Type: zip lrfCategorize.zip (1.5 KB, 665 views)
gwynevans is offline   Reply With Quote