use new default poster, remove black posters from icon cache
This commit is contained in:
parent
fbf06a1545
commit
59a3709f84
6 changed files with 61 additions and 32 deletions
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"iconRatio": 0.75,
|
||||
"iconRatio": 0.625,
|
||||
"itemKeys": [
|
||||
{
|
||||
"id": "*",
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
|
||||
|
||||
from io import BytesIO
|
||||
from PIL import Image
|
||||
import os
|
||||
import sqlite3
|
||||
|
||||
import tornado.concurrent
|
||||
|
@ -12,10 +10,11 @@ import tornado.ioloop
|
|||
import tornado.web
|
||||
|
||||
from oxtornado import run_async
|
||||
from settings import icons_db_path
|
||||
from settings import icons_db_path, static_path
|
||||
from utils import resize_image
|
||||
import db
|
||||
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -46,12 +45,9 @@ class Icons(dict):
|
|||
def set_setting(self, c, key, value):
|
||||
c.execute('INSERT OR REPLACE INTO setting values (?, ?)', (key, str(value)))
|
||||
|
||||
def black(self):
|
||||
img = Image.new('RGB', (80, 128))
|
||||
o = BytesIO()
|
||||
img.save(o, format='jpeg')
|
||||
data = o.getvalue()
|
||||
o.close()
|
||||
def default_cover(self):
|
||||
with open(os.path.join(static_path, 'png', 'cover.png'), 'rb') as f:
|
||||
data = f.read()
|
||||
return data
|
||||
|
||||
def __getitem__(self, id, default=None):
|
||||
|
@ -110,13 +106,26 @@ def get_icon(id, type_, size, callback):
|
|||
if not data:
|
||||
data = icons[key]
|
||||
if not data:
|
||||
data = icons.black()
|
||||
skey = '%s:%s:%s' % ('default', 'cover', size)
|
||||
if size:
|
||||
data = icons[skey]
|
||||
if data:
|
||||
size = None
|
||||
if not data:
|
||||
data = icons.default_cover()
|
||||
if size:
|
||||
data = icons[skey] = resize_image(data, size=size)
|
||||
size = None
|
||||
if size:
|
||||
data = icons[skey] = resize_image(data, size=size)
|
||||
data = bytes(data) or ''
|
||||
callback(data)
|
||||
|
||||
def clear_default_cover_cache():
|
||||
for resolution in (64, 128, 256, 512, 1024):
|
||||
key = '%s:%s:%s' % ('default', 'cover', resolution)
|
||||
del icons[key]
|
||||
|
||||
@run_async
|
||||
def get_icon_app(id, type_, size, callback):
|
||||
with db.session():
|
||||
|
@ -140,7 +149,7 @@ def get_icon_app(id, type_, size, callback):
|
|||
if not data:
|
||||
data = icons[key]
|
||||
if not data:
|
||||
data = icons.black()
|
||||
data = icons.default_cover()
|
||||
size = None
|
||||
if size:
|
||||
data = icons[skey] = resize_image(data, size=size)
|
||||
|
|
|
@ -362,18 +362,21 @@ class Item(db.Model):
|
|||
icons[key] = cover
|
||||
self.info['coverRatio'] = get_ratio(cover)
|
||||
else:
|
||||
if icons[key]:
|
||||
del icons[key]
|
||||
path = self.get_path()
|
||||
del icons[key]
|
||||
key = 'preview:%s'%self.id
|
||||
if path:
|
||||
preview = self.extract_preview()
|
||||
if preview:
|
||||
icons[key] = preview
|
||||
self.info['previewRatio'] = get_ratio(preview)
|
||||
if not cover:
|
||||
self.info['coverRatio'] = self.info['previewRatio']
|
||||
elif cover:
|
||||
preview = self.extract_preview()
|
||||
if preview:
|
||||
icons[key] = preview
|
||||
self.info['previewRatio'] = get_ratio(preview)
|
||||
if not cover:
|
||||
self.info['coverRatio'] = self.info['previewRatio']
|
||||
else:
|
||||
del icons[key]
|
||||
if 'previewRatio' in self.info:
|
||||
del self.info['previewRatio']
|
||||
if not cover and 'coverRatio' in self.info:
|
||||
del self.info['coverRatio']
|
||||
if cover and not preview:
|
||||
self.info['previewRatio'] = self.info['coverRatio']
|
||||
for key in ('cover', 'preview'):
|
||||
key = '%s:%s' % (key, self.id)
|
||||
|
|
|
@ -9,7 +9,6 @@ from io import BytesIO
|
|||
import re
|
||||
from urllib.parse import unquote
|
||||
|
||||
from PIL import Image
|
||||
import stdnum.isbn
|
||||
from ox import strip_tags, decode_html
|
||||
|
||||
|
@ -82,12 +81,6 @@ def cover(path):
|
|||
img = os.path.normpath(os.path.join(os.path.dirname(filename), img))
|
||||
if img in files:
|
||||
return use(img)
|
||||
# fallback return black cover
|
||||
img = Image.new('RGB', (80, 128))
|
||||
o = BytesIO()
|
||||
img.save(o, format='jpeg')
|
||||
data = o.getvalue()
|
||||
o.close()
|
||||
return data
|
||||
|
||||
def info(epub):
|
||||
|
|
24
oml/setup.py
24
oml/setup.py
|
@ -207,6 +207,30 @@ def upgrade_db(old, new=None):
|
|||
if sys.platform.startswith('linux'):
|
||||
import integration
|
||||
integration.install_xdg()
|
||||
if old <= '20160110-581-e08780a' and new > '20160110-581-e08780a':
|
||||
with db.session():
|
||||
import item.models
|
||||
from item.icons import icons
|
||||
for f in item.models.File.query:
|
||||
if f.info['extension'] == 'epub':
|
||||
i = f.item
|
||||
key = 'cover:%s'%i.id
|
||||
cover = icons[key]
|
||||
key = 'preview:%s'%i.id
|
||||
preview = i.extract_preview()
|
||||
update_item = False
|
||||
if not preview:
|
||||
del icons[key]
|
||||
for resolution in (128, 256, 512):
|
||||
del icons['%s:%s' % (key, resolution)]
|
||||
if 'previewRatio' in i.info:
|
||||
del i.info['previewRatio']
|
||||
update_item = True
|
||||
if not cover and 'coverRatio' in i.info:
|
||||
del i.info['coverRatio']
|
||||
update_item = True
|
||||
if update_item:
|
||||
i.save()
|
||||
|
||||
if old <= '20140527-120-3cb9819':
|
||||
run_sql('CREATE INDEX ix_find_findvalue ON find (findvalue)')
|
||||
|
|
|
@ -58,7 +58,7 @@ oml.ui.previewDialog = function() {
|
|||
keys: ['coverRatio', 'id', 'modified', 'title']
|
||||
}, function(result) {
|
||||
var item = result.data,
|
||||
coverRatio = item.coverRatio,
|
||||
coverRatio = item.coverRatio || oml.config.iconRatio,
|
||||
size = getSize(coverRatio),
|
||||
title = Ox.encodeHTMLEntities(item.title);
|
||||
$image = $('<img>')
|
||||
|
|
Loading…
Reference in a new issue