From bcfc7d978a7d83145e1d91fa187c2cf2ed11f26d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 10 Sep 2007 01:04:51 +0000 Subject: [PATCH] Fail on reading PDF metadata gracefully. version 0.3.108. --- src/libprs500/__init__.py | 2 +- src/libprs500/ebooks/metadata/pdf.py | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/libprs500/__init__.py b/src/libprs500/__init__.py index 379e91518d..338713fa41 100644 --- a/src/libprs500/__init__.py +++ b/src/libprs500/__init__.py @@ -13,7 +13,7 @@ ## with this program; if not, write to the Free Software Foundation, Inc., ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ''' E-book management software''' -__version__ = "0.3.107" +__version__ = "0.3.108" __docformat__ = "epytext" __author__ = "Kovid Goyal " __appname__ = 'libprs500' diff --git a/src/libprs500/ebooks/metadata/pdf.py b/src/libprs500/ebooks/metadata/pdf.py index 1b7880ce39..e961433bdd 100644 --- a/src/libprs500/ebooks/metadata/pdf.py +++ b/src/libprs500/ebooks/metadata/pdf.py @@ -27,18 +27,21 @@ def get_metadata(stream): title = 'Unknown' mi = MetaInformation(title, 'Unknown') stream.seek(0) - info = PdfFileReader(stream).getDocumentInfo() - if info.title: - mi.title = title - if info.author: - src = info.author.split('&') - authors = [] - for au in src: - authors += au.split(',') - mi.authors = authors - mi.author = info.author - if info.subject: - mi.category = info.subject + try: + info = PdfFileReader(stream).getDocumentInfo() + if info.title: + mi.title = title + if info.author: + src = info.author.split('&') + authors = [] + for au in src: + authors += au.split(',') + mi.authors = authors + mi.author = info.author + if info.subject: + mi.category = info.subject + except Exception, err: + print >>sys.stderr, 'Couldn\'t read metadata from pdf: % with error %s'%(mi.title, str(err)) return mi