def fetchData(self): if self.data == 'OK': logger.fdebug('Recieved OPDS command: ' + self.cmd) methodToCall = getattr(self, "_" + self.cmd) result = methodToCall(**self.kwargs) if self.img: return serve_file(path=self.img, content_type='image/jpeg') if self.file and self.filename: if self.issue_id: try: readinglist.Readinglist( IssueID=self.issue_id).markasRead() except: logger.fdebug('No reading list found to update.') return serve_download(path=self.file, name=self.filename) if isinstance(self.data, basestring): return self.data else: cherrypy.response.headers['Content-Type'] = "text/xml" return serve_template(templatename="opds.html", title=self.data['title'], opds=self.data) else: return self.data
def fetchData(self): if self.data == 'OK': logger.fdebug('Recieved OPDS command: ' + self.cmd) methodToCall = getattr(self, "_" + self.cmd) result = methodToCall(**self.kwargs) if self.img: if type(self.img) == tuple: iformat, idata = self.img return serve_fileobj(BytesIO(idata), content_type='image/' + iformat) else: return serve_file(path=self.img, content_type='image/jpeg') if self.file and self.filename: if self.issue_id: try: logger.fdebug('OPDS is attempting to markasRead filename %s aka issue_id %s' % (self.filename, self.issue_id)) readinglist.Readinglist().markasRead(IssueID=self.issue_id) except: logger.fdebug('No reading list found to update.') return serve_download(path=self.file, name=self.filename) if isinstance(self.data, str): return self.data else: cherrypy.response.headers['Content-Type'] = "text/xml" return serve_template(templatename="opds.html", title=self.data['title'], opds=self.data) else: return self.data
def get_loginform(self, username, msg="Enter login information", from_page="/"): from mylar.webserve import serve_template return serve_template(templatename="login.html", username=escape(username, True), title="Login", from_page=from_page)
def fetchData(self): if self.data == 'OK': logger.fdebug('Recieved OPDS command: ' + self.cmd) methodToCall = getattr(self, "_" + self.cmd) result = methodToCall(**self.kwargs) if self.img: return serve_file(path=self.img, content_type='image/jpeg') if self.file and self.filename: return serve_download(path=self.file, name=self.filename) if isinstance(self.data, basestring): return self.data else: cherrypy.response.headers['Content-Type'] = "text/xml" return serve_template(templatename="opds.html", title=self.data['title'], opds=self.data) else: return self.data
def get_loginform(self, username, msg="Enter login information", from_page="/"): from mylar.webserve import serve_template return serve_template(templatename="login.html", username=escape(username, True), title="Login", from_page=from_page)
def read_comic(self, ish_id = None, page_num = None, size = None): logger.debug("WebReader Requested, looking for ish_id %s and page_num %s" % (ish_id, page_num)) if size == None: user_size_pref = 'wide' else: user_size_pref = size try: ish_id except: logger.warn("WebReader: ish_id not set!") myDB = db.DBConnection() comic = myDB.selectone('select comics.ComicLocation, issues.Location from comics, issues where comics.comicid = issues.comicid and issues.issueid = ?' , [ish_id]).fetchone() if comic is None: logger.warn("WebReader: ish_id %s requested but not in the database!" % ish_id) raise cherrypy.HTTPRedirect("home") # cherrypy.config.update() comic_path = os.path.join(comic['ComicLocation'], comic['Location']) logger.debug("WebReader found ish_id %s at %s" % (ish_id, comic_path)) # cherrypy.session['ish_id'].load() # if 'sizepref' not in cherrypy.session: # cherrypy.session['sizepref'] = user_size_pref # user_size_pref = cherrypy.session['sizepref'] # logger.debug("WebReader setting user_size_pref to %s" % user_size_pref) scanner = ComicScanner() image_list = scanner.reading_images(ish_id) logger.debug("Image list contains %s pages" % (len(image_list))) if len(image_list) == 0: logger.debug("Unpacking ish_id %s from comic_path %s" % (ish_id, comic_path)) scanner.user_unpack_comic(ish_id, comic_path) else: logger.debug("ish_id %s already unpacked." % ish_id) num_pages = len(image_list) logger.debug("Found %s pages for ish_id %s from comic_path %s" % (num_pages, ish_id, comic_path)) if num_pages == 0: image_list = ['images/skipped_icon.png'] cookie_comic = re.sub(r'\W+', '', comic_path) cookie_comic = "wv_" + cookie_comic logger.debug("about to drop a cookie for " + cookie_comic + " which represents " + comic_path) cookie_check = cherrypy.request.cookie if cookie_comic not in cookie_check: logger.debug("Cookie Creation") cookie_path = '/' cookie_maxage = '2419200' cookie_set = cherrypy.response.cookie cookie_set['cookie_comic'] = 0 cookie_set['cookie_comic']['path'] = cookie_path cookie_set['cookie_comic']['max-age'] = cookie_maxage next_page = page_num + 1 prev_page = page_num - 1 else: logger.debug("Cookie Read") page_num = int(cherrypy.request.cookie['cookie_comic'].value) logger.debug("Cookie Set To %d" % page_num) next_page = page_num + 1 prev_page = page_num - 1 logger.info("Reader Served") logger.debug("Serving comic " + comic['Location'] + " page number " + str(page_num)) return serve_template(templatename="read.html", pages=image_list, current_page=page_num, np=next_page, pp=prev_page, nop=num_pages, size=user_size_pref, cc=cookie_comic, comicpath=comic_path, ish_id=ish_id)
import os import re import cherrypy import stat import zipfile from lib.rarfile import rarfile import mylar try: from PIL import Image except ImportError: logger.debug("WebReader Requested, but PIL or pillow libraries must be installed. Please execute 'pip install pillow', then restart Mylar.") return serve_template(templatename="index.html", title="Home", comics=comics, alphaindex=mylar.CONFIG.ALPHAINDEX) from mylar import logger, db, importer, mb, search, filechecker, helpers, updater, parseit, weeklypull, librarysync, moveit, Failed, readinglist, config from mylar.webserve import serve_template class WebViewer(object): def __init__(self): self.ish_id = None self.page_num = None self.kwargs = None self.data = None if not os.path.exists(os.path.join(mylar.DATA_DIR, 'sessions')): os.makedirs(os.path.abspath(os.path.join(mylar.DATA_DIR, 'sessions'))) updatecherrypyconf = { 'tools.gzip.on': True,