clear all cached sizes
This commit is contained in:
parent
d0e2fe0340
commit
b899768130
4 changed files with 39 additions and 22 deletions
|
@ -82,6 +82,15 @@ class Icons(dict):
|
|||
c.close()
|
||||
conn.close()
|
||||
|
||||
def clear(self, prefix):
|
||||
sql = 'DELETE FROM icon WHERE id LIKE ?'
|
||||
conn = self.connect()
|
||||
c = conn.cursor()
|
||||
c.execute(sql, (prefix + '%', ))
|
||||
conn.commit()
|
||||
c.close()
|
||||
conn.close()
|
||||
|
||||
icons = Icons(icons_db_path)
|
||||
|
||||
@run_async
|
||||
|
@ -122,9 +131,7 @@ def get_icon(id, type_, size, callback):
|
|||
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]
|
||||
icons.clear('default:cover:')
|
||||
|
||||
@run_async
|
||||
def get_icon_app(id, type_, size, callback):
|
||||
|
|
|
@ -21,7 +21,7 @@ from .icons import icons
|
|||
from .person import get_sort_name, Person
|
||||
from queryparser import Parser
|
||||
from settings import config
|
||||
from utils import remove_empty_folders
|
||||
from utils import remove_empty_folders, get_ratio
|
||||
from websocket import trigger_event
|
||||
import db
|
||||
import media
|
||||
|
@ -310,13 +310,7 @@ class Item(db.Model):
|
|||
if path:
|
||||
return getattr(media, self.info['extension']).cover(path)
|
||||
|
||||
def update_icons(self):
|
||||
def get_ratio(data):
|
||||
try:
|
||||
img = Image.open(BytesIO(data))
|
||||
return img.size[0]/img.size[1]
|
||||
except:
|
||||
return 1
|
||||
def update_cover(self):
|
||||
key = 'cover:%s'%self.id
|
||||
cover = None
|
||||
if 'cover' in self.meta and self.meta['cover']:
|
||||
|
@ -330,25 +324,35 @@ class Item(db.Model):
|
|||
self.info['coverRatio'] = get_ratio(cover)
|
||||
else:
|
||||
del icons[key]
|
||||
if not cover:
|
||||
if 'previewRatio' in self.info:
|
||||
self.info['coverRatio'] = self.info['previewRatio']
|
||||
elif 'coverRatio' in self.info:
|
||||
del self.info['coverRatio']
|
||||
icons.clear('cover:%s:'%self.id)
|
||||
|
||||
def update_preview(self):
|
||||
key = 'preview:%s'%self.id
|
||||
preview = self.extract_preview()
|
||||
if preview:
|
||||
icons[key] = preview
|
||||
self.info['previewRatio'] = get_ratio(preview)
|
||||
if not cover:
|
||||
if not 'coverRatio' in self.info:
|
||||
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:
|
||||
if not preview:
|
||||
if 'coverRatio' in self.info:
|
||||
self.info['previewRatio'] = self.info['coverRatio']
|
||||
for key in ('cover', 'preview'):
|
||||
key = '%s:%s' % (key, self.id)
|
||||
for resolution in (128, 256, 512):
|
||||
del icons['%s:%s' % (key, resolution)]
|
||||
elif 'previewRatio' in self.info:
|
||||
del self.info['previewRatio']
|
||||
icons.clear('preview:%s:'%self.id)
|
||||
|
||||
def update_icons(self):
|
||||
self.update_cover()
|
||||
self.update_preview()
|
||||
|
||||
def load_metadata(self):
|
||||
'''
|
||||
|
|
|
@ -384,8 +384,7 @@ class Node(Thread):
|
|||
content = fileobj.read()
|
||||
key = 'preview:' + item.id
|
||||
icons[key] = content
|
||||
for resolution in (128, 256, 512):
|
||||
del icons['preview:%s' % resolution]
|
||||
icons.clear('preview:%s:'%item.id)
|
||||
return True
|
||||
except:
|
||||
logger.debug('preview download failed %s', url, exc_info=1)
|
||||
|
|
|
@ -391,3 +391,10 @@ def _to_json(python_object):
|
|||
return '%d-%02d-%02dT%02d:%02d%02dZ' % tuple(list(tt)[:6])
|
||||
return python_object.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||
raise TypeError(u'%s %s is not JSON serializable' % (repr(python_object), type(python_object)))
|
||||
|
||||
def get_ratio(data):
|
||||
try:
|
||||
img = Image.open(BytesIO(data))
|
||||
return img.size[0]/img.size[1]
|
||||
except:
|
||||
return 1
|
||||
|
|
Loading…
Reference in a new issue