View Single Post
Old 03-04-2011, 12:54 PM   #3
gabor.legrady
Junior Member
gabor.legrady began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Mar 2011
Device: none
Working version

Code:
import os.path
import textwrap
import os
import glob
from calibre.customize import FileTypePlugin, MetadataReaderPlugin, MetadataWriterPlugin
from calibre.constants import numeric_version

class FileDirMetadataReader(MetadataReaderPlugin):

    name = 'FileDir metadata'
    file_types = set(['pdf', 'doc', 'txt', 'htm', 'rtf', 'mobi', 'djvu', 'prc'])
    description = ('Extract author and book name from folder/filename')
    version = numeric_version

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