From 6d19dd5e812d9449be0ba837570dfea93cfd4efe Mon Sep 17 00:00:00 2001 From: j Date: Sat, 14 Mar 2015 13:05:15 +0530 Subject: [PATCH] inital cbr support --- oml/item/handlers.py | 6 +++++- oml/item/scan.py | 2 +- oml/media/__init__.py | 7 +++++-- oml/media/cbr.py | 18 ++++++++++++++++++ oml/server.py | 2 ++ static/html/cbr.html | 13 +++++++++++++ 6 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 oml/media/cbr.py create mode 100644 static/html/cbr.html diff --git a/oml/item/handlers.py b/oml/item/handlers.py index 41a4e63..6357bda 100644 --- a/oml/item/handlers.py +++ b/oml/item/handlers.py @@ -84,6 +84,8 @@ class FileHandler(OMLHandler): self.set_status(404) return mimetype = { + 'cbr': 'application/x-cbr', + 'cbz': 'application/x-cbz', 'epub': 'application/epub+zip', 'pdf': 'application/pdf', 'txt': 'text/plain', @@ -108,7 +110,9 @@ class ReaderHandler(OMLHandler): if not item: self.set_status(404) return - if item.info['extension'] == 'epub': + if item.info['extension'] in ('cbr', 'cbz'): + html = 'html/cbr.html' + elif item.info['extension'] == 'epub': html = 'html/epub.html' elif item.info['extension'] == 'pdf': html = 'html/pdf.html' diff --git a/oml/item/scan.py b/oml/item/scan.py index cefe8ab..9bcefba 100644 --- a/oml/item/scan.py +++ b/oml/item/scan.py @@ -22,7 +22,7 @@ import state import logging logger = logging.getLogger('oml.item.scan') -extensions = ['epub', 'pdf', 'txt'] +extensions = ['epub', 'pdf', 'txt', 'cbr', 'cbz'] def remove_missing(): dirty = False diff --git a/oml/media/__init__.py b/oml/media/__init__.py index ce8952d..86b104d 100644 --- a/oml/media/__init__.py +++ b/oml/media/__init__.py @@ -10,6 +10,7 @@ import codecs import ox from . import pdf +from . import cbr from . import epub from . import txt from . import opf @@ -27,10 +28,12 @@ def metadata(f, from_=None): data['extension'] = ext data['size'] = os.stat(f).st_size - if ext == 'pdf': - info = pdf.info(f) + if ext == 'cbr': + info = cbr.info(f) elif ext == 'epub': info = epub.info(f) + elif ext == 'pdf': + info = pdf.info(f) elif ext == 'txt': info = txt.info(f) diff --git a/oml/media/cbr.py b/oml/media/cbr.py new file mode 100644 index 0000000..9f72a71 --- /dev/null +++ b/oml/media/cbr.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# vi:si:et:sw=4:sts=4:ts=4 + + +import os + + +def cover(path): + data = None + #open rar file and extract first page here + return data + +def info(path): + data = {} + data['title'] = os.path.splitext(os.path.basename(path))[0] + #data['pages'] = fixme read rar to count pages + return data + diff --git a/oml/server.py b/oml/server.py index 8f23884..b5c9682 100644 --- a/oml/server.py +++ b/oml/server.py @@ -58,12 +58,14 @@ def run(): handlers = [ (r'/(favicon.ico)', StaticFileHandler, {'path': settings.static_path}), (r'/static/oxjs/(.*)', StaticFileHandler, {'path': os.path.join(settings.base_dir, '..', 'oxjs')}), + (r'/static/cbr.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.base_dir, '..', 'reader', 'cbr.js')}), (r'/static/epub.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.base_dir, '..', 'reader', 'epub.js')}), (r'/static/pdf.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.base_dir, '..', 'reader', 'pdf.js')}), (r'/static/txt.js/(.*)', StaticFileHandler, {'path': os.path.join(settings.base_dir, '..', 'reader', 'txt.js')}), (r'/static/(.*)', StaticFileHandler, {'path': settings.static_path}), (r'/(.*)/epub/(.*)', EpubHandler), (r'/(.*?)/reader/', ReaderHandler), + (r'/(.*?)/cbr/', FileHandler), (r'/(.*?)/pdf/', FileHandler), (r'/(.*?)/txt/', FileHandler), (r'/(.*?)/get/', FileHandler, { diff --git a/static/html/cbr.html b/static/html/cbr.html new file mode 100644 index 0000000..ec512e5 --- /dev/null +++ b/static/html/cbr.html @@ -0,0 +1,13 @@ + + + + + + + + + + +