View Single Post
Old 03-03-2011, 01:24 PM   #1
gabor.legrady
Junior Member
gabor.legrady began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Mar 2011
Device: none
Getting title form file name and author from folder name

Hello!

I would like to write a plugin to get the book's title from the file name and the author from the folder name containing the file. (My old collection is sorted this way, mostly with txt files)

Alos, I would like to replace the "_" characters with simple space, but I have no experience with python

I have a non-working skeleton, if someone could help me out, that would mean a lot.

Code:
import textwrap
import os
import glob
from calibre.customize import FileTypePlugin, MetadataReaderPlugin, MetadataWriterPlugin
from calibre.constants import numeric_version
from calibre.ebooks.metadata.archive import ArchiveExtract, get_cbz_metadata

class FileDirMetadataReader(MetadataReaderPlugin):

    name = 'Read comic metadata'
    file_types = set(['pdf', 'doc', 'txt', 'htm', 'rtf'])
    description = _('Extract author and book name from folder/filename')

    def get_metadata(self, stream, ftype):
        from calibre.ebooks.metadata import MetaInformation
        path = stream.name
        author = os.path.splitext(path)[1][1:] ????
        title = os.path.splitext(path)[1][1:] ????
        author = author.replace("_"," ")
        title = title.replace("_"," ")
        return MetaInformation(title, author)
gabor.legrady is offline   Reply With Quote