View Single Post
Old 08-29-2008, 10:38 AM   #6
ashkulz
Addict
ashkulz will become famous soon enoughashkulz will become famous soon enoughashkulz will become famous soon enoughashkulz will become famous soon enoughashkulz will become famous soon enoughashkulz will become famous soon enoughashkulz will become famous soon enough
 
ashkulz's Avatar
 
Posts: 350
Karma: 705
Join Date: Dec 2006
Location: Mumbai, India
Device: Kindle 1/REB 1200
Quote:
Originally Posted by derrell View Post
I do want to be able to use something like impfind --author Ringo and have it spew out a list of titles and paths to all of the files. I'm thinking it would be uesful to search on all the fields execpt the id. Shouldn't be too hard for me to do now that I can extract the info from the files. All that is left is just moving through the directory tree and generating the list on the right key.
Look at the first two functions I have written for impserve -- they'll do the job.

Code:
def get_ebook_info(name):
    """ get the details of the IMP book as a tuple """
    if not isfile(name):
        return None
    info = [name, getsize(name), getmtime(name)]
    f = open(name, 'rb')
    if f.read(10) != '\x00\x02BOOKDOUG':
        return None

    def cString(skip=0):
        result = ''
        while 1:
            data = f.read(1)
            if data == '\x00':
                if not skip: return result
                skip -= 1
                result, data = '', ''
            result += data

    f.read(38)
    info += [cString(), cString(), cString(1), cString(2)]
    f.close()
    return tuple(info)
ashkulz is offline   Reply With Quote