|
|
#1 |
|
Junior Member
![]() 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)
|
|
|
|
|
|
#2 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,609
Karma: 28549044
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 |
|
|
|
| Advert | |
|
|
|
|
#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] )
|
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Changing from Title-Author to Author - Title | Amalthia | Calibre | 17 | 01-23-2017 12:20 AM |
| Author folder but not for books. It's possible? | ElLoco | Calibre | 9 | 07-10-2010 09:14 AM |
| Recognition of author and title from html files/reading metadata from a seperate file | Lethe | Calibre | 5 | 04-03-2010 09:35 AM |
| Creating a Library file w/Author, Title, Summary and tag info | asktheeightball | Calibre | 2 | 01-18-2010 11:28 AM |
| Database File Hints at Title and Author Tagging | Adam B. | iRex | 2 | 10-23-2008 11:12 AM |