예제 #1
0
def get_book_cover(cover_path):
    if ub.config.config_use_google_drive:
        try:
            if not web.is_gdrive_ready():
                return send_from_directory(
                    os.path.join(os.path.dirname(__file__), "static"),
                    "generic_cover.jpg")
            path = gd.get_cover_via_gdrive(cover_path)
            if path:
                return redirect(path)
            else:
                web.app.logger.error(cover_path +
                                     '/cover.jpg not found on Google Drive')
                return send_from_directory(
                    os.path.join(os.path.dirname(__file__), "static"),
                    "generic_cover.jpg")
        except Exception as e:
            web.app.logger.error("Error Message: " + e.message)
            web.app.logger.exception(e)
            # traceback.print_exc()
            return send_from_directory(
                os.path.join(os.path.dirname(__file__), "static"),
                "generic_cover.jpg")
    else:
        return send_from_directory(
            os.path.join(ub.config.config_calibre_dir, cover_path),
            "cover.jpg")
예제 #2
0
def get_book_cover(cover_path, resize_root):
    if ub.config.config_use_google_drive:
        try:
            if not web.is_gdrive_ready():
                return send_from_directory(
                    os.path.join(os.path.dirname(__file__), "static"),
                    "generic_cover.jpg")
            path = gd.get_cover_via_gdrive(cover_path)
            if path:
                return redirect(path)
            else:
                web.app.logger.error(cover_path +
                                     '/cover.jpg not found on Google Drive')
                return send_from_directory(
                    os.path.join(os.path.dirname(__file__), "static"),
                    "generic_cover.jpg")
        except Exception as e:
            web.app.logger.error("Error Message: " + e.message)
            web.app.logger.exception(e)
            # traceback.print_exc()
            return send_from_directory(
                os.path.join(os.path.dirname(__file__), "static"),
                "generic_cover.jpg")
    else:
        imgpath = os.path.join(ub.config.config_calibre_dir, cover_path,
                               'cover.jpg')
        resizedfile = hashlib.sha1(
            imgpath.encode('utf-8')).hexdigest() + '.jpg'
        if not os.path.isdir(resize_root):
            os.mkdir(resize_root)
        if not os.path.isfile(os.path.join(resize_root, resizedfile)):
            with Image(filename=imgpath) as img:
                #img.transform(resize='x500')
                img.sample(300, 450)
                img.compression_quality = 75
                img.format = 'jpeg'
                img.save(filename=os.path.join(resize_root, resizedfile))
        return send_from_directory(resize_root, resizedfile)