diff --git a/files_opds/lib/epub.php b/files_opds/lib/epub.php index bf96bab..f4be4d9 100644 --- a/files_opds/lib/epub.php +++ b/files_opds/lib/epub.php @@ -37,15 +37,12 @@ class Epub { $this->file = $file; $zip = new \ZipArchive(); if(!($zip->open($this->file))){ - \OC_Log::write('epub', "Failed to read epub file", \OC_Log::ERROR); - return false; + throw new \Exception("Failed to read epub file"); } // read container data - $data = $zip->getFromName('META-INF/container.xml'); - if($data == false){ - \OC_Log::write('epub', "Failed to access epub container data", \OC_Log::ERROR); - return false; + if(!($data = $zip->getFromName('META-INF/container.xml'))) { + throw new \Exception("Failed to access epub container data"); } $xml = new DOMDocument(); @@ -56,17 +53,17 @@ class Epub { $this->meta = $nodes->item(0)->attr('full-path'); // load metadata - $data = $zip->getFromName($this->meta); - if(!$data){ - \OC_Log::write('epub', 'Failed to access epub metadata', \OC_Log::ERROR); - return false; + if(!($data = $zip->getFromName($this->meta))) { + throw new \Exception("Failed to access epub metadata"); } $this->xml = new \DOMDocument(); $this->xml->registerNodeClass('DOMElement','\OCA\Files_Opds\EPubDOMElement'); $this->xml->loadXML($data); $this->xml->formatOutput = true; - $this->xpath = new EPubDOMXPath($this->xml); + if(!($this->xpath = new EPubDOMXPath($this->xml))) { + throw new \Exception("Failed to instantiate xpath"); + } $zip->close(); } diff --git a/files_opds/lib/meta.php b/files_opds/lib/meta.php index e28f176..540972e 100644 --- a/files_opds/lib/meta.php +++ b/files_opds/lib/meta.php @@ -30,7 +30,7 @@ class Meta * scanned once, even if they don't contain valid metadate. */ $meta['id'] = $id; - $meta['updated'] = date("Y-m-d\TH:i:sP"); + $meta['updated'] = date("Y-m-d H:i:s"); $meta['date'] = ''; $meta['author'] = ''; $meta['title'] = ''; @@ -189,19 +189,23 @@ class Meta */ public static function epub($path,&$meta) { $success = false; - $epub = new Epub($path); - /* first try ISBN */ - if(!(($isbn = $epub->ISBN()) && (Isbn::get($isbn, $meta)))) { - /* use EPUB internal metadata instead */ - $meta['author'] = json_encode($epub->Authors()); - $meta['title'] = $epub->Title(); - $meta['date'] = $epub->Date(); - $meta['publisher'] = $epub->Publisher(); - $meta['copyright'] = $epub->Copyright(); - $meta['language'] = $epub->Language(); - $meta['description'] = strip_tags($epub->Description()); - $meta['isbn'] = $epub->ISBN(); - $meta['subjects'] = json_encode($epub->Subjects()); + try { + $epub = new Epub($path); + /* first try ISBN */ + if(!(($isbn = $epub->ISBN()) && (Isbn::get($isbn, $meta)))) { + /* use EPUB internal metadata instead */ + $meta['author'] = json_encode($epub->Authors()); + $meta['title'] = $epub->Title(); + $meta['date'] = $epub->Date(); + $meta['publisher'] = $epub->Publisher(); + $meta['copyright'] = $epub->Copyright(); + $meta['language'] = $epub->Language(); + $meta['description'] = strip_tags($epub->Description()); + $meta['isbn'] = $epub->ISBN(); + $meta['subjects'] = json_encode($epub->Subjects()); + } + } catch (\Exception $e) { + \OC_Log::write(get_class(), $e->getMessage(), \OC_LOG::ERROR); } }