|
|
#1 |
|
Junior Member
![]() Posts: 2
Karma: 10
Join Date: Mar 2011
Device: none
|
Getting title form file name and author from folder name
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)
|
|
|
|
|
|
#2 |
|
Creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 22,495
Karma: 2944574
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
__________________
Get calibre Notice to all: I can not provide assistance with DRM removal, for legal reasons, so please do not contact me about it. |
|
|
|
|
Enthusiast
|
|
|
|
#3 |
|
Junior Member
![]() 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] )
|
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
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 |