Fail on reading PDF metadata gracefully. version 0.3.108.

This commit is contained in:
Kovid Goyal 2007-09-10 01:04:51 +00:00
parent b8a1906aa3
commit bcfc7d978a
2 changed files with 16 additions and 13 deletions

View File

@ -13,7 +13,7 @@
## with this program; if not, write to the Free Software Foundation, Inc., ## with this program; if not, write to the Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
''' E-book management software''' ''' E-book management software'''
__version__ = "0.3.107" __version__ = "0.3.108"
__docformat__ = "epytext" __docformat__ = "epytext"
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>" __author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
__appname__ = 'libprs500' __appname__ = 'libprs500'

View File

@ -27,18 +27,21 @@ def get_metadata(stream):
title = 'Unknown' title = 'Unknown'
mi = MetaInformation(title, 'Unknown') mi = MetaInformation(title, 'Unknown')
stream.seek(0) stream.seek(0)
info = PdfFileReader(stream).getDocumentInfo() try:
if info.title: info = PdfFileReader(stream).getDocumentInfo()
mi.title = title if info.title:
if info.author: mi.title = title
src = info.author.split('&') if info.author:
authors = [] src = info.author.split('&')
for au in src: authors = []
authors += au.split(',') for au in src:
mi.authors = authors authors += au.split(',')
mi.author = info.author mi.authors = authors
if info.subject: mi.author = info.author
mi.category = info.subject 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 return mi