From 8a1d31be2a717e8661cb4024e697210833ebe4f3 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Fri, 5 Jun 2020 23:46:44 -0500 Subject: [PATCH] Fix OPDS feed wrong links --- scripts/generate-opds.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/scripts/generate-opds.php b/scripts/generate-opds.php index 818c0459..1dde4c7b 100755 --- a/scripts/generate-opds.php +++ b/scripts/generate-opds.php @@ -17,9 +17,10 @@ foreach($contentFiles as $path){ $xml->registerXPathNamespace('dc', 'http://purl.org/dc/elements/1.1/'); $updated = $xml->xpath('/package/metadata/meta[@property="dcterms:modified"]') ?: []; + $identifier = $xml->xpath('/package/metadata/dc:identifier') ?: []; - if($updated !== false && sizeof($updated) > 0){ - $sortedContentFiles[(string)$updated[0]] = $xml; + if(sizeof($identifier) > 0 && sizeof($updated) > 0){ + $sortedContentFiles[(string)$updated[0] . ' ' . $identifier[0]] = $xml; } } @@ -54,8 +55,9 @@ print("\n"); $authors = array(); $temp = $xml->xpath('/package/metadata/dc:identifier') ?: []; - $url = preg_replace('/^url:/ius', '', (string)array_shift($temp)) ?? ''; - $url = preg_replace('/^https:\/\/standardebooks.org/ius', $webUrl, $url) ?? ''; + $identifier = (string)array_shift($temp); + $url = preg_replace('/^url:/ius', '', $identifier) ?? ''; + $url = preg_replace('/^https:\/\/standardebooks\.org/ius', $webUrl, $url) ?? ''; $relativeUrl = preg_replace('/^' . preg_quote($webUrl, '/') . '/ius', '', $url) ?? ''; $temp = $xml->xpath('/package/metadata/dc:title') ?: []; @@ -84,9 +86,9 @@ print("\n"); $filesystemPath = preg_replace('/\/src\/epub\/content.opf$/ius', '', $path) ?? ''; $temp = glob($filesystemPath . '/dist/*.epub'); - $epubFilename = preg_replace('/(\|\.epub)/ius', '', preg_replace('/.+\//ius', '', array_shift($temp) ?? '') ?? '') ?? ''; - $temp = glob($filesystemPath . '/dist/*.azw3'); - $kindleFilename = preg_replace('/.+\//ius', '', array_shift($temp) ?? '') ?? ''; + $filename = preg_replace('/^url:https:\/\/standardebooks\.org\/ebooks\//ius', '', $identifier); + $epubFilename = str_replace('/', '_', $filename) . '.epub'; + $kindleFilename = str_replace('/', '_', $filename) . '.azw3'; ?>