View Single Post
Old 12-03-2009, 04:20 AM   #7
macr0t0r
Connoisseur
macr0t0r doesn't littermacr0t0r doesn't litter
 
macr0t0r's Avatar
 
Posts: 91
Karma: 108
Join Date: Jan 2008
Device: Palm Treo 680, Sony Reader
Okay! This seems to be working for me. I can now extract the cover image from the PMLZ archive. I modified metadata/pml.py as follows:
Code:
def get_metadata(stream, extract_cover=True):
    """ Return metadata as a L{MetaInfo} object """
    mi = MetaInformation(_('Unknown'), [_('Unknown')])
    stream.seek(0)

    pml = ''
    if stream.name.endswith('.pmlz'):
        with TemporaryDirectory('_unpmlz') as tdir:
            zf = ZipFile(stream)
            zf.extractall(tdir)

            pmls = glob.glob(os.path.join(tdir, '*.pml'))
            for p in pmls:
                with open(p, 'r+b') as p_stream:
                    pml += p_stream.read()
            coverpath = glob.glob(os.path.join(tdir, 'cover.png'))
            if len(coverpath)==0:
                imagedir=os.path.join(tdir,'images')
                coverpath = glob.glob(os.path.join(imagedir, 'cover.png'))
            if len(coverpath)==0:
                imagedir=os.path.join(tdir,pmls[0] + '_img')
                coverpath = glob.glob(os.path.join(imagedir, 'cover.png'))
            if len(coverpath)>0:
                coverdata = open(coverpath, 'rb').read()
                if coverdata is not None:
                    mi.cover_data = ('png', coverdata)
    else:
Try it out and see if that works for you as well (I've only tested it on a Mac). If so, would you so kindly push that in?

- Jim
macr0t0r is offline   Reply With Quote