inital cbr support

This commit is contained in:
j 2015-03-14 13:05:15 +05:30
parent 60ab6a5244
commit 6d19dd5e81
6 changed files with 44 additions and 4 deletions

View File

@ -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'

View File

@ -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

View File

@ -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)

18
oml/media/cbr.py Normal file
View File

@ -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

View File

@ -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, {

13
static/html/cbr.html Normal file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="/static/oxjs/build/Ox.js" type="text/javascript"></script>
<script src="/static/cbr.js/cbr.js" type="text/javascript"></script>
<script src="/static/cbr.js/bitjs/archive.js" type="text/javascript"></script>
<script>
cbrjs.open(document.location.pathname.replace(/\/reader\//, '/cbr/'));
</script>
</head>
<body></body>
</html>