Frontend notifier
This commit is contained in:
1 parent
970b400a0c
commit
bc5006c02e
2 files changed
+43
-43
No files matched your search
@@ -25,9 +25,7 @@ class CoreNotifier(Notification):
|
|||||||
def registerEvents(self):
|
def registerEvents(self):
|
||||||
|
|
||||||
# Library update, frontend refresh
|
# Library update, frontend refresh
|
||||||
def onLibraryUpdate(data):
|
addEvent('library.update_finish', lambda data: fireEvent('notify.frontend', type = 'library.update', data = data))
|
||||||
fireEvent('notify.frontend', type = 'library.update', data = data)
|
|
||||||
addEvent('library.update', onLibraryUpdate)
|
|
||||||
|
|
||||||
def notify(self, message = '', data = {}, type = None):
|
def notify(self, message = '', data = {}, type = None):
|
||||||
self.add(data = {
|
self.add(data = {
|
||||||
|
|||||||
@@ -49,57 +49,59 @@ class LibraryPlugin(Plugin):
|
|||||||
library = db.query(Library).filter_by(identifier = identifier).first()
|
library = db.query(Library).filter_by(identifier = identifier).first()
|
||||||
done_status = fireEvent('status.get', 'done', single = True)
|
done_status = fireEvent('status.get', 'done', single = True)
|
||||||
|
|
||||||
library_dict = library.to_dict({'titles': {}, 'files':{}})
|
library_dict = library.to_dict({'titles': {}, 'files':{}, 'info':{}})
|
||||||
|
do_update = True
|
||||||
|
|
||||||
if library.status_id == done_status.get('id') and not force:
|
if library.status_id == done_status.get('id') and not force:
|
||||||
return library_dict
|
do_update = False
|
||||||
|
else:
|
||||||
info = fireEvent('provider.movie.info', merge = True, identifier = identifier)
|
info = fireEvent('provider.movie.info', merge = True, identifier = identifier)
|
||||||
if not info or len(info) == 0:
|
if not info or len(info) == 0:
|
||||||
log.error('Could not update, no movie info to work with: %s' % identifier)
|
log.error('Could not update, no movie info to work with: %s' % identifier)
|
||||||
return library_dict
|
do_update = False
|
||||||
|
|
||||||
# Main info
|
# Main info
|
||||||
library.plot = info.get('plot', '')
|
if do_update:
|
||||||
library.tagline = info.get('tagline', '')
|
library.plot = info.get('plot', '')
|
||||||
library.year = info.get('year', 0)
|
library.tagline = info.get('tagline', '')
|
||||||
library.status_id = done_status.get('id')
|
library.year = info.get('year', 0)
|
||||||
db.commit()
|
library.status_id = done_status.get('id')
|
||||||
|
db.commit()
|
||||||
|
|
||||||
# Titles
|
# Titles
|
||||||
[db.delete(title) for title in library.titles]
|
[db.delete(title) for title in library.titles]
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
titles = info.get('titles', [])
|
titles = info.get('titles', [])
|
||||||
|
|
||||||
log.debug('Adding titles: %s' % titles)
|
log.debug('Adding titles: %s' % titles)
|
||||||
for title in titles:
|
for title in titles:
|
||||||
t = LibraryTitle(
|
t = LibraryTitle(
|
||||||
title = title,
|
title = title,
|
||||||
default = title.lower() == default_title.lower()
|
default = title.lower() == default_title.lower()
|
||||||
)
|
)
|
||||||
library.titles.append(t)
|
library.titles.append(t)
|
||||||
|
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
# Files
|
# Files
|
||||||
images = info.get('images', [])
|
images = info.get('images', [])
|
||||||
for type in images:
|
for type in images:
|
||||||
for image in images[type]:
|
for image in images[type]:
|
||||||
if not isinstance(image, str):
|
if not isinstance(image, str):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
file_path = fireEvent('file.download', url = image, single = True)
|
file_path = fireEvent('file.download', url = image, single = True)
|
||||||
file = fireEvent('file.add', path = file_path, type = ('image', type[:-1]), single = True)
|
file = fireEvent('file.add', path = file_path, type = ('image', type[:-1]), single = True)
|
||||||
try:
|
try:
|
||||||
file = db.query(File).filter_by(id = file.get('id')).one()
|
file = db.query(File).filter_by(id = file.get('id')).one()
|
||||||
library.files.append(file)
|
library.files.append(file)
|
||||||
db.commit()
|
db.commit()
|
||||||
except:
|
except:
|
||||||
log.debug('Failed to attach to library: %s' % traceback.format_exc())
|
log.debug('Failed to attach to library: %s' % traceback.format_exc())
|
||||||
|
|
||||||
library_dict = library.to_dict({'titles': {}, 'files':{}})
|
library_dict = library.to_dict({'titles': {}, 'files':{}, 'info':{}})
|
||||||
|
|
||||||
fireEvent('library.update', data = library_dict)
|
fireEvent('library.update_finish', data = library_dict)
|
||||||
|
|
||||||
return library_dict
|
return library_dict
|
||||||
Reference in new issue
Block a user