Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
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
Old 03-03-2011, 01:26 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 25,616
Karma: 4998447
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Use return MetaInformation(title, [author])

disable the other builtin metadata reader plugins and make sure the option to read metadata from file contents is checked
kovidgoyal is online now   Reply With Quote
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
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Author folder but not for books. It's possible? ElLoco Calibre 9 07-10-2010 08:14 AM
Recognition of author and title from html files/reading metadata from a seperate file Lethe Calibre 5 04-03-2010 08:35 AM
Creating a Library file w/Author, Title, Summary and tag info asktheeightball Calibre 2 01-18-2010 10:28 AM
Database File Hints at Title and Author Tagging Adam B. iRex 2 10-23-2008 10:12 AM
Changing from Title-Author to Author - Title Amalthia Calibre 15 09-22-2008 08:41 PM


All times are GMT -4. The time now is 12:50 AM.


MobileRead.com is a privately owned, operated and funded community.