From fe7769a7bae7794598b9811860abd1491f01cad2 Mon Sep 17 00:00:00 2001 From: j Date: Tue, 8 Dec 2015 11:54:04 +0000 Subject: [PATCH] dont fail if reading metadata.opf fails --- oml/media/opf.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/oml/media/opf.py b/oml/media/opf.py index c7ad78d..9040bce 100644 --- a/oml/media/opf.py +++ b/oml/media/opf.py @@ -10,10 +10,17 @@ from utils import normalize_isbn from ox import strip_tags import ox.iso +import logging +logger = logging.getLogger(__name__) + def info(opf): data = {} - with open(opf) as fd: - opf = ET.fromstring(fd.read()) + try: + with open(opf, 'rb') as fd: + opf = ET.fromstring(fd.read().decode()) + except: + logger.debug('failed to load opf %s', opf, exc_info=1) + return data ns = '{http://www.idpf.org/2007/opf}' metadata = opf.findall(ns + 'metadata')[0] for e in metadata.getchildren():