mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
TXTZ metadata reader.
This commit is contained in:
parent
0257fe4a02
commit
837bd4e548
@ -325,6 +325,17 @@ class TXTMetadataReader(MetadataReaderPlugin):
|
|||||||
from calibre.ebooks.metadata.txt import get_metadata
|
from calibre.ebooks.metadata.txt import get_metadata
|
||||||
return get_metadata(stream)
|
return get_metadata(stream)
|
||||||
|
|
||||||
|
class TXTZMetadataReader(MetadataReaderPlugin):
|
||||||
|
|
||||||
|
name = 'Read TXTZ metadata'
|
||||||
|
file_types = set(['txtz'])
|
||||||
|
description = _('Read metadata from %s files') % 'TXTZ'
|
||||||
|
author = 'John Schember'
|
||||||
|
|
||||||
|
def get_metadata(self, stream, ftype):
|
||||||
|
from calibre.ebooks.metadata.txtz import get_metadata
|
||||||
|
return get_metadata(stream)
|
||||||
|
|
||||||
class ZipMetadataReader(MetadataReaderPlugin):
|
class ZipMetadataReader(MetadataReaderPlugin):
|
||||||
|
|
||||||
name = 'Read ZIP metadata'
|
name = 'Read ZIP metadata'
|
||||||
|
@ -25,7 +25,7 @@ class DRMError(ValueError):
|
|||||||
class ParserError(ValueError):
|
class ParserError(ValueError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
BOOK_EXTENSIONS = ['lrf', 'rar', 'zip', 'rtf', 'lit', 'txt', 'htm', 'xhtm',
|
BOOK_EXTENSIONS = ['lrf', 'rar', 'zip', 'rtf', 'lit', 'txt', 'txtz', 'htm', 'xhtm',
|
||||||
'html', 'xhtml', 'pdf', 'pdb', 'pdr', 'prc', 'mobi', 'azw', 'doc',
|
'html', 'xhtml', 'pdf', 'pdb', 'pdr', 'prc', 'mobi', 'azw', 'doc',
|
||||||
'epub', 'fb2', 'djvu', 'lrx', 'cbr', 'cbz', 'cbc', 'oebzip',
|
'epub', 'fb2', 'djvu', 'lrx', 'cbr', 'cbz', 'cbc', 'oebzip',
|
||||||
'rb', 'imp', 'odt', 'chm', 'tpz', 'azw1', 'pml', 'mbp', 'tan', 'snb']
|
'rb', 'imp', 'odt', 'chm', 'tpz', 'azw1', 'pml', 'mbp', 'tan', 'snb']
|
||||||
|
@ -1,16 +1,20 @@
|
|||||||
'''Read meta information from TXT files'''
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from __future__ import with_statement
|
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||||
|
|
||||||
|
'''
|
||||||
|
Read meta information from TXT files
|
||||||
|
'''
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
|
|
||||||
def get_metadata(stream, extract_cover=True):
|
def get_metadata(stream, extract_cover=True):
|
||||||
""" Return metadata as a L{MetaInfo} object """
|
'''
|
||||||
|
Return metadata as a L{MetaInfo} object
|
||||||
|
'''
|
||||||
mi = MetaInformation(_('Unknown'), [_('Unknown')])
|
mi = MetaInformation(_('Unknown'), [_('Unknown')])
|
||||||
stream.seek(0)
|
stream.seek(0)
|
||||||
|
|
||||||
|
34
src/calibre/ebooks/metadata/txtz.py
Normal file
34
src/calibre/ebooks/metadata/txtz.py
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
__license__ = 'GPL v3'
|
||||||
|
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
|
||||||
|
|
||||||
|
'''
|
||||||
|
Read meta information from TXT files
|
||||||
|
'''
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
|
from calibre.utils.zipfile import ZipFile
|
||||||
|
|
||||||
|
def get_metadata(stream, extract_cover=True):
|
||||||
|
'''
|
||||||
|
Return metadata as a L{MetaInfo} object
|
||||||
|
'''
|
||||||
|
mi = MetaInformation(_('Unknown'), [_('Unknown')])
|
||||||
|
stream.seek(0)
|
||||||
|
|
||||||
|
with TemporaryDirectory('_untxtz_mdata') as tdir:
|
||||||
|
try:
|
||||||
|
zf = ZipFile(stream)
|
||||||
|
zf.extract('metadata.opf', tdir)
|
||||||
|
|
||||||
|
from calibre.ebooks.metadata.opf2 import OPF
|
||||||
|
with open(os.path.join(tdir, 'metadata.opf'), 'rb') as opff:
|
||||||
|
mi = OPF(opff).to_book_metadata()
|
||||||
|
except:
|
||||||
|
return mi
|
||||||
|
|
||||||
|
return mi
|
Loading…
x
Reference in New Issue
Block a user