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()
|
c.close()
|
||||||
conn.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)
|
icons = Icons(icons_db_path)
|
||||||
|
|
||||||
@run_async
|
@run_async
|
||||||
|
@ -122,9 +131,7 @@ def get_icon(id, type_, size, callback):
|
||||||
callback(data)
|
callback(data)
|
||||||
|
|
||||||
def clear_default_cover_cache():
|
def clear_default_cover_cache():
|
||||||
for resolution in (64, 128, 256, 512, 1024):
|
icons.clear('default:cover:')
|
||||||
key = '%s:%s:%s' % ('default', 'cover', resolution)
|
|
||||||
del icons[key]
|
|
||||||
|
|
||||||
@run_async
|
@run_async
|
||||||
def get_icon_app(id, type_, size, callback):
|
def get_icon_app(id, type_, size, callback):
|
||||||
|
|
|
@ -21,7 +21,7 @@ from .icons import icons
|
||||||
from .person import get_sort_name, Person
|
from .person import get_sort_name, Person
|
||||||
from queryparser import Parser
|
from queryparser import Parser
|
||||||
from settings import config
|
from settings import config
|
||||||
from utils import remove_empty_folders
|
from utils import remove_empty_folders, get_ratio
|
||||||
from websocket import trigger_event
|
from websocket import trigger_event
|
||||||
import db
|
import db
|
||||||
import media
|
import media
|
||||||
|
@ -310,13 +310,7 @@ class Item(db.Model):
|
||||||
if path:
|
if path:
|
||||||
return getattr(media, self.info['extension']).cover(path)
|
return getattr(media, self.info['extension']).cover(path)
|
||||||
|
|
||||||
def update_icons(self):
|
def update_cover(self):
|
||||||
def get_ratio(data):
|
|
||||||
try:
|
|
||||||
img = Image.open(BytesIO(data))
|
|
||||||
return img.size[0]/img.size[1]
|
|
||||||
except:
|
|
||||||
return 1
|
|
||||||
key = 'cover:%s'%self.id
|
key = 'cover:%s'%self.id
|
||||||
cover = None
|
cover = None
|
||||||
if 'cover' in self.meta and self.meta['cover']:
|
if 'cover' in self.meta and self.meta['cover']:
|
||||||
|
@ -330,25 +324,35 @@ class Item(db.Model):
|
||||||
self.info['coverRatio'] = get_ratio(cover)
|
self.info['coverRatio'] = get_ratio(cover)
|
||||||
else:
|
else:
|
||||||
del icons[key]
|
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
|
key = 'preview:%s'%self.id
|
||||||
preview = self.extract_preview()
|
preview = self.extract_preview()
|
||||||
if preview:
|
if preview:
|
||||||
icons[key] = preview
|
icons[key] = preview
|
||||||
self.info['previewRatio'] = get_ratio(preview)
|
self.info['previewRatio'] = get_ratio(preview)
|
||||||
if not cover:
|
if not 'coverRatio' in self.info:
|
||||||
self.info['coverRatio'] = self.info['previewRatio']
|
self.info['coverRatio'] = self.info['previewRatio']
|
||||||
else:
|
else:
|
||||||
del icons[key]
|
del icons[key]
|
||||||
if 'previewRatio' in self.info:
|
if 'previewRatio' in self.info:
|
||||||
del self.info['previewRatio']
|
del self.info['previewRatio']
|
||||||
if not cover and 'coverRatio' in self.info:
|
if not preview:
|
||||||
del self.info['coverRatio']
|
if 'coverRatio' in self.info:
|
||||||
if cover and not preview:
|
|
||||||
self.info['previewRatio'] = self.info['coverRatio']
|
self.info['previewRatio'] = self.info['coverRatio']
|
||||||
for key in ('cover', 'preview'):
|
elif 'previewRatio' in self.info:
|
||||||
key = '%s:%s' % (key, self.id)
|
del self.info['previewRatio']
|
||||||
for resolution in (128, 256, 512):
|
icons.clear('preview:%s:'%self.id)
|
||||||
del icons['%s:%s' % (key, resolution)]
|
|
||||||
|
def update_icons(self):
|
||||||
|
self.update_cover()
|
||||||
|
self.update_preview()
|
||||||
|
|
||||||
def load_metadata(self):
|
def load_metadata(self):
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -384,8 +384,7 @@ class Node(Thread):
|
||||||
content = fileobj.read()
|
content = fileobj.read()
|
||||||
key = 'preview:' + item.id
|
key = 'preview:' + item.id
|
||||||
icons[key] = content
|
icons[key] = content
|
||||||
for resolution in (128, 256, 512):
|
icons.clear('preview:%s:'%item.id)
|
||||||
del icons['preview:%s' % resolution]
|
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
logger.debug('preview download failed %s', url, exc_info=1)
|
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 '%d-%02d-%02dT%02d:%02d%02dZ' % tuple(list(tt)[:6])
|
||||||
return python_object.strftime('%Y-%m-%dT%H:%M:%SZ')
|
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)))
|
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