diff --git a/README.md b/README.md index 5eee95f..11bb468 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The first method gives you the latest, greatest and potentially buggiest version files_opds ---------- -The OPDS catalog app enables Owncloud users to publish a sub-tree of their personal filesystem as an OPDS feed. Since Owncloud currently has limited to no support for metadata, the OPDS entries are rather sparse for now: only title (as in 'filename'), file size, cover image (where available), modification time and content links are provided. +The OPDS catalog app enables Owncloud users to publish a sub-tree of their personal filesystem as an OPDS feed. Since Owncloud currently has limited to no support for metadata, these are for now stored in a separate table. As of v0.3 OPDS catalog can extract all relevant metadata from EPUB documents; other document types will appear with sparse entries for now: only title (as in 'filename'), file size, cover image (where available), modification time and content links are provided. The root feed links to a hierarchical navigation feed mirroring the directory structure as well as a 'personal bookshelf' containing all downloaded books in order (most recent download first). This 'personal bookshelf' will be empty (0 books) at first. Use the 'Browse catalog' link to download a book and it'll appear on the 'personal bookshelf'. Download another, and it will appear above the one you previously downloaded. This makes it possible to get at books you are in the process of reading from different devices, or to easily re-visit a book you downloaded earlier. @@ -44,6 +44,7 @@ The feed has been tested on these clients: - KyBook on iOS: OK - Marvin on iOS: OK - eBook Search on iOS: browsing works, downloading does not (401 error, 'Unauthorised') + - Gecko-based browsers: OK, feed can be browsed and books can be downloaded without additional software. diff --git a/dist/files_opds-0.3.tar.gz b/dist/files_opds-0.3.tar.gz new file mode 100644 index 0000000..2100775 Binary files /dev/null and b/dist/files_opds-0.3.tar.gz differ diff --git a/files_opds/appinfo/database.xml b/files_opds/appinfo/database.xml new file mode 100644 index 0000000..fda2e97 --- /dev/null +++ b/files_opds/appinfo/database.xml @@ -0,0 +1,110 @@ + + + *dbname* + true + false + utf8 + + + *dbprefix*opds_metadata + + + + id + integer + 0 + true + 11 + + + + + updated + timestamp + 1970-01-01 00:00:00 + false + + + + + date + text + + true + 32 + + + + + author + text + + true + 256 + + + + + title + text + + true + 256 + + + + + language + text + + true + 64 + + + + + publisher + text + + true + 64 + + + + + isbn + text + + true + 16 + + + + + copyright + text + + true + 128 + + + + + description + text + + true + 2048 + + + + + subjects + text + + true + 1024 + + +
+
diff --git a/files_opds/appinfo/info.xml b/files_opds/appinfo/info.xml index c82b8d8..334bae9 100644 --- a/files_opds/appinfo/info.xml +++ b/files_opds/appinfo/info.xml @@ -4,7 +4,7 @@ OPDS catalog Personal OPDS catalog AGPL - 0.2 + 0.3 Frank de Lange 7.0 true diff --git a/files_opds/lib/epub.php b/files_opds/lib/epub.php index afb099b..bf96bab 100644 --- a/files_opds/lib/epub.php +++ b/files_opds/lib/epub.php @@ -21,7 +21,7 @@ use \DOMDocument; * based on https://github.com/splitbrain/php-epub-meta */ class Epub { - protected $xml; + public $xml; protected $xpath; protected $file; protected $meta; @@ -75,7 +75,7 @@ class Epub { * @brief file name getter * @return string filename */ - public static function file() { + public function file() { return $this->file; } @@ -84,7 +84,7 @@ class Epub { * * @return array $authors */ - public static function Authors() { + public function Authors() { // read current data $rolefix = false; $authors = array(); @@ -127,6 +127,15 @@ class Epub { return $this->get('dc:language'); } + /** + * @brief get date + * + * @param string $date + */ + public function Date(){ + return $this->get('dc:date'); + } + /** * @brief get publisher info * diff --git a/files_opds/lib/files.php b/files_opds/lib/files.php index cfa57ff..64caf4b 100644 --- a/files_opds/lib/files.php +++ b/files_opds/lib/files.php @@ -35,6 +35,7 @@ class Files extends \OCA\Files\Helper $entry['preview'] = self::getPreview($i); $entry['thumbnail'] = self::getThumbnail($i); $entry['humansize'] = \OC_Helper::humanFileSize($i['size']); + $entry['meta'] = Util::getMeta($i['fileid']); } else { $entry['icon'] = self::determineIcon($i); } diff --git a/files_opds/lib/util.php b/files_opds/lib/util.php index 1c1cfb9..2159bf1 100644 --- a/files_opds/lib/util.php +++ b/files_opds/lib/util.php @@ -148,4 +148,76 @@ class Util public static function logWarn($msg) { \OCP\Util::writeLog('files_opds', $msg, \OCP\Util::WARN); } + + /** + * @brief get metadata for fileid + * + * Long function, to be split later + * + * @param int $id fileid + * @return array of metadata + */ + public static function getMeta($id) { + $sql = 'SELECT * FROM `*PREFIX*opds_metadata` WHERE id = ?'; + $args = array($id); + $query = \OCP\DB::prepare($sql); + $result = $query->execute($args); + if ($row = $result->fetchRow()) { + return $row; + } else { + /* start with empty values, except for id. This way, files only get + * scanned once, even if they don't contain valid metadate. + */ + $meta = array(); + $meta['id'] = $id; + $meta['updated'] = date("Y-m-d\TH:i:sP"); + $meta['date'] = ''; + $meta['author'] = ''; + $meta['title'] = ''; + $meta['language'] = ''; + $meta['publisher'] = ''; + $meta['isbn'] = ''; + $meta['copyright'] = ''; + $meta['description'] = ''; + $meta['subjects'] = ''; + + $path = \OC\Files\Filesystem::getLocalFile(\OC\Files\Filesystem::getPath($id)); + switch (strtolower(substr(strrchr($path, "."), 1))) { + case 'epub': + $epub = new Epub($path); + $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'] = $epub->Subjects(); + break; + default: + // set title to filename minus extension + $info = pathinfo($path); + $meta['title'] = basename($path,'.'.$info['extension']); + break; + } + $sql = "INSERT INTO *PREFIX*opds_metadata (`id`, `updated`, `date`, `author`, `title`, `language`, `publisher`, `isbn`, `copyright`, `description`, `subjects`) VALUES (?,?,?,?,?,?,?,?,?,?,?)"; + $args = array( + $meta['id'], + $meta['updated'], + $meta['date'], + $meta['author'], + $meta['title'], + $meta['language'], + $meta['publisher'], + $meta['isbn'], + $meta['copyright'], + $meta['description'], + $meta['subjects'] + ); + $query = \OCP\DB::prepare($sql); + $result = $query->execute($args); + return $meta; + } + } } diff --git a/files_opds/templates/feed.php b/files_opds/templates/feed.php index 265619f..8878dcf 100644 --- a/files_opds/templates/feed.php +++ b/files_opds/templates/feed.php @@ -59,10 +59,19 @@ echo ''; - <?php p($file['name']); ?> - + <?php p($file['meta']['title']); ?> + id: + + + + + + urn:isbn: + + + @@ -75,7 +84,8 @@ echo ''; - + + @@ -95,10 +105,19 @@ echo ''; - <?php p($file['name']); ?> - + <?php p($file['meta']['title']); ?> + id: + + + + + + urn:isbn: + + + @@ -111,7 +130,8 @@ echo ''; - + +