Add EPUB to LRF conversion/metadata support to the GUI

This commit is contained in:
Kovid Goyal 2008-01-07 20:48:22 +00:00
parent fc60de3d7d
commit 721b671922
5 changed files with 20 additions and 15 deletions

View File

@ -25,4 +25,4 @@ class UnknownFormatError(Exception):
pass
BOOK_EXTENSIONS = ['lrf', 'lrx', 'rar', 'zip', 'rtf', 'lit', 'txt', 'htm',
'html', 'xhtml', 'epub', 'pdf', 'prc', 'mobi', 'azw']
'html', 'xhtml', 'epub', 'pdf', 'prc', 'mobi', 'azw', 'epub']

View File

@ -24,6 +24,7 @@ from libprs500.ebooks.lrf.pdf.convert_from import process_file as pdf2lrf
from libprs500.ebooks.lrf.rtf.convert_from import process_file as rtf2lrf
from libprs500.ebooks.lrf.txt.convert_from import process_file as txt2lrf
from libprs500.ebooks.lrf.html.convert_from import process_file as html2lrf
from libprs500.ebooks.lrf.epub.convert_from import process_file as epub2lrf
def largest_file(files):
maxsize, file = 0, None
@ -60,7 +61,7 @@ def handle_archive(path):
files = []
cdir = traverse_subdirs(tdir)
file = None
for ext in ('lit', 'rtf', 'pdf', 'txt'):
for ext in ('lit', 'rtf', 'pdf', 'txt', 'epub'):
pat = os.path.join(cdir, '*.'+ext)
files.extend(glob.glob(pat))
file = largest_file(files)
@ -112,6 +113,8 @@ def process_file(path, options, logger=None):
convertor = rtf2lrf
elif 'txt' == ext:
convertor = txt2lrf
elif 'epub' == ext:
convertor = epub2lrf
if not convertor:
raise UnknownFormatError('Coverting from %s to LRF is not supported.')
convertor(path, options, logger)
@ -127,7 +130,7 @@ def main(args=sys.argv, logger=None):
any2lrf myfile
Convert any ebook format into LRF. Supported formats are:
LIT, RTF, TXT, HTML and PDF. any2lrf will also process a RAR or
LIT, RTF, TXT, HTML, EPUB and PDF. any2lrf will also process a RAR or
ZIP archive.
''')
options, args = parser.parse_args(args)

View File

@ -12,7 +12,7 @@
## You should have received a copy of the GNU General Public License along
## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
'''Read meta information from PDF files'''
'''Read meta information from epub files'''
from __future__ import with_statement
@ -22,8 +22,7 @@ from zipfile import ZipFile, BadZipfile
from cStringIO import StringIO
from contextlib import closing
from libprs500.ebooks.BeautifulSoup import BeautifulStoneSoup, BeautifulSoup
from libprs500.ebooks.metadata import MetaInformation
from libprs500.ebooks.BeautifulSoup import BeautifulStoneSoup
from libprs500.ebooks.metadata.opf import OPF, OPFReader
@ -108,8 +107,8 @@ def get_metadata(stream):
return OCFZipReader(stream).opf
def main(args=sys.argv):
if len(args) != 2 or '--help' in args or '-help' in args:
print >>sys.stderr, 'Usage: epub-meta FILE'
if len(args) != 2 or '--help' in args or '-h' in args:
print >>sys.stderr, 'Usage:', args[0], 'mybook.epub'
return 1
path = os.path.abspath(os.path.expanduser(args[1]))

View File

@ -17,6 +17,7 @@ from libprs500.ebooks.metadata.rtf import get_metadata as rtf_metadata
from libprs500.ebooks.lrf.meta import get_metadata as lrf_metadata
from libprs500.ebooks.metadata.pdf import get_metadata as pdf_metadata
from libprs500.ebooks.metadata.lit import get_metadata as lit_metadata
from libprs500.ebooks.metadata.epub import get_metadata as epub_metadata
from libprs500.ebooks.metadata.rtf import set_metadata as set_rtf_metadata
from libprs500.ebooks.lrf.meta import set_metadata as set_lrf_metadata
@ -32,6 +33,8 @@ def get_metadata(stream, stream_type='lrf'):
return pdf_metadata(stream)
if stream_type == 'lit':
return lit_metadata(stream)
if stream_type == 'epub':
return epub_metadata(stream)
return MetaInformation(None, None)
def set_metadata(stream, mi, stream_type='lrf'):

View File

@ -92,7 +92,7 @@ def setup_completion():
f.write(opts_and_exts('rtf2lrf', htmlop, ['rtf']))
f.write(opts_and_exts('pdf2lrf', htmlop, ['pdf']))
f.write(opts_and_exts('any2lrf', htmlop,
['htm', 'html', 'xhtml', 'xhtm', 'rar', 'zip', 'txt', 'lit', 'rtf', 'pdf']))
['epub', 'htm', 'html', 'xhtml', 'xhtm', 'rar', 'zip', 'txt', 'lit', 'rtf', 'pdf']))
f.write(opts_and_exts('lrf2lrs', lrf2lrsop, ['lrf']))
f.write(opts_and_exts('lrf-meta', metaop, ['lrf']))
f.write(opts_and_exts('rtf-meta', metaop, ['rtf']))