mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
PML Metadata: Improve cover extraction.
This commit is contained in:
parent
113b4c8d09
commit
0a384ba93b
@ -1,9 +1,13 @@
|
||||
'''Read meta information from TXT files'''
|
||||
|
||||
from __future__ import with_statement
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
'''
|
||||
Read meta information from TXT files
|
||||
'''
|
||||
|
||||
|
||||
import os
|
||||
import glob
|
||||
@ -57,20 +61,15 @@ def get_metadata(stream, extract_cover=True):
|
||||
return mi
|
||||
|
||||
def get_cover(name, tdir, top_level=False):
|
||||
cover_path = []
|
||||
cover_path = ''
|
||||
cover_data = None
|
||||
|
||||
if top_level:
|
||||
cover_path = glob.glob(os.path.join(tdir, 'cover.png'))
|
||||
# Images not in top level try bookname_img directory because
|
||||
# that's where Dropbook likes to see them.
|
||||
cover_path = os.path.join(tdir, 'cover.png') if os.path.exists(os.path.join(tdir, 'cover.png')) else ''
|
||||
if not cover_path:
|
||||
cover_path = glob.glob(os.path.join(tdir, name + '_img', 'cover.png'))
|
||||
# No images in Dropbook location try generic images directory
|
||||
if not cover_path:
|
||||
cover_path = glob.glob(os.path.join(os.path.join(tdir, 'images'), 'cover.png'))
|
||||
cover_path = os.path.join(tdir, name + '_img', 'cover.png') if os.path.exists(os.path.join(tdir, name + '_img', 'cover.png')) else os.path.join(os.path.join(tdir, 'images'), 'cover.png') if os.path.exists(os.path.join(os.path.join(tdir, 'images'), 'cover.png')) else ''
|
||||
if cover_path:
|
||||
with open(cover_path[0], 'r+b') as cstream:
|
||||
with open(cover_path, 'r+b') as cstream:
|
||||
cover_data = cstream.read()
|
||||
|
||||
return ('png', cover_data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user