mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-01 05:49:58 +00:00
Bugfixes pdf xmp parsing
This commit is contained in:
parent
fcaa232967
commit
9c842f1895
@ -22,7 +22,7 @@ import hashlib
|
|||||||
from tempfile import gettempdir
|
from tempfile import gettempdir
|
||||||
from flask_babel import gettext as _
|
from flask_babel import gettext as _
|
||||||
|
|
||||||
from . import logger, comic, isoLanguages, get_locale
|
from . import logger, comic, isoLanguages
|
||||||
from .constants import BookMeta
|
from .constants import BookMeta
|
||||||
from .helper import split_authors
|
from .helper import split_authors
|
||||||
|
|
||||||
@ -53,7 +53,7 @@ except ImportError as ex:
|
|||||||
from PyPDF2 import __version__ as PyPdfVersion
|
from PyPDF2 import __version__ as PyPdfVersion
|
||||||
use_pdf_meta = True
|
use_pdf_meta = True
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
log.debug('Cannot import PyPDF3/PyPDF2, extracting pdf metadata will not work: %s / %s', e)
|
log.debug('Cannot import PyPDF3/PyPDF2, extracting pdf metadata will not work: %s / %s', ex, e)
|
||||||
use_pdf_meta = False
|
use_pdf_meta = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -118,7 +118,7 @@ def parse_xmp(pdf_file):
|
|||||||
try:
|
try:
|
||||||
xmp_info = pdf_file.getXmpMetadata()
|
xmp_info = pdf_file.getXmpMetadata()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.debug('Can not read XMP metadata', e)
|
log.debug('Can not read XMP metadata %e', e)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if xmp_info:
|
if xmp_info:
|
||||||
@ -142,7 +142,7 @@ def parse_xmp(pdf_file):
|
|||||||
for i in xmp_info.dc_language:
|
for i in xmp_info.dc_language:
|
||||||
#calibre-web currently only takes one language.
|
#calibre-web currently only takes one language.
|
||||||
languages.append(isoLanguages.get_lang3(i))
|
languages.append(isoLanguages.get_lang3(i))
|
||||||
except:
|
except AttributeError:
|
||||||
languages.append('')
|
languages.append('')
|
||||||
|
|
||||||
xmp_tags = ', '.join(xmp_info.dc_subject)
|
xmp_tags = ', '.join(xmp_info.dc_subject)
|
||||||
@ -156,51 +156,6 @@ def parse_xmp(pdf_file):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def parse_xmp(pdf_file):
|
|
||||||
"""
|
|
||||||
Parse XMP Metadata and prepare for BookMeta object
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
xmp_info = pdf_file.getXmpMetadata()
|
|
||||||
except Exception as e:
|
|
||||||
log.debug('Can not read XMP metadata', e)
|
|
||||||
return None
|
|
||||||
|
|
||||||
if xmp_info:
|
|
||||||
try:
|
|
||||||
xmp_author = xmp_info.dc_creator # list
|
|
||||||
except:
|
|
||||||
xmp_author = ['']
|
|
||||||
|
|
||||||
if xmp_info.dc_title:
|
|
||||||
xmp_title = xmp_info.dc_title['x-default']
|
|
||||||
else:
|
|
||||||
xmp_title = ''
|
|
||||||
|
|
||||||
if xmp_info.dc_description:
|
|
||||||
xmp_description = xmp_info.dc_description['x-default']
|
|
||||||
else:
|
|
||||||
xmp_description = ''
|
|
||||||
|
|
||||||
languages = []
|
|
||||||
try:
|
|
||||||
for i in xmp_info.dc_language:
|
|
||||||
languages.append(isoLanguages.get_lang3(i))
|
|
||||||
except AttributeError:
|
|
||||||
languages= [""]
|
|
||||||
|
|
||||||
xmp_tags = ', '.join(xmp_info.dc_subject)
|
|
||||||
xmp_publisher = ', '.join(xmp_info.dc_publisher)
|
|
||||||
|
|
||||||
return {'author': xmp_author,
|
|
||||||
'title': xmp_title,
|
|
||||||
'subject': xmp_description,
|
|
||||||
'tags': xmp_tags,
|
|
||||||
'languages': languages,
|
|
||||||
'publisher': xmp_publisher
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def parse_xmp(pdf_file):
|
def parse_xmp(pdf_file):
|
||||||
"""
|
"""
|
||||||
Parse XMP Metadata and prepare for BookMeta object
|
Parse XMP Metadata and prepare for BookMeta object
|
||||||
|
Loading…
Reference in New Issue
Block a user