Combine status calls
This commit is contained in:
1 parent
1d603e1ec2
commit
9ba19d27a6
6 files changed
+41
-46
No files matched your search
@@ -108,9 +108,8 @@ class MoviePlugin(Plugin):
|
|||||||
now = time.time()
|
now = time.time()
|
||||||
week = 262080
|
week = 262080
|
||||||
|
|
||||||
done_status = fireEvent('status.get', 'done', single = True)
|
done_status, available_status, snatched_status = \
|
||||||
available_status = fireEvent('status.get', 'available', single = True)
|
fireEvent('status.get', ['done', 'available', 'snatched'], single = True)
|
||||||
snatched_status = fireEvent('status.get', 'snatched', single = True)
|
|
||||||
|
|
||||||
db = get_session()
|
db = get_session()
|
||||||
|
|
||||||
@@ -367,11 +366,8 @@ class MoviePlugin(Plugin):
|
|||||||
library = fireEvent('library.add', single = True, attrs = params, update_after = update_library)
|
library = fireEvent('library.add', single = True, attrs = params, update_after = update_library)
|
||||||
|
|
||||||
# Status
|
# Status
|
||||||
status_active = fireEvent('status.add', 'active', single = True)
|
status_active, snatched_status, ignored_status, done_status, downloaded_status = \
|
||||||
snatched_status = fireEvent('status.add', 'snatched', single = True)
|
fireEvent('status.get', ['active', 'snatched', 'ignored', 'done', 'downloaded'], single = True)
|
||||||
ignored_status = fireEvent('status.add', 'ignored', single = True)
|
|
||||||
done_status = fireEvent('status.add', 'done', single = True)
|
|
||||||
downloaded_status = fireEvent('status.add', 'downloaded', single = True)
|
|
||||||
|
|
||||||
default_profile = fireEvent('profile.default', single = True)
|
default_profile = fireEvent('profile.default', single = True)
|
||||||
|
|
||||||
@@ -549,8 +545,7 @@ class MoviePlugin(Plugin):
|
|||||||
|
|
||||||
def restatus(self, movie_id):
|
def restatus(self, movie_id):
|
||||||
|
|
||||||
active_status = fireEvent('status.get', 'active', single = True)
|
active_status, done_status = fireEvent('status.get', ['active', 'done'], single = True)
|
||||||
done_status = fireEvent('status.get', 'done', single = True)
|
|
||||||
|
|
||||||
db = get_session()
|
db = get_session()
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,10 @@ class Release(Plugin):
|
|||||||
|
|
||||||
identifier = '%s.%s.%s' % (group['library']['identifier'], group['meta_data'].get('audio', 'unknown'), group['meta_data']['quality']['identifier'])
|
identifier = '%s.%s.%s' % (group['library']['identifier'], group['meta_data'].get('audio', 'unknown'), group['meta_data']['quality']['identifier'])
|
||||||
|
|
||||||
|
|
||||||
|
done_status, snatched_status = fireEvent('status.get', ['done', 'snatched'], single = True)
|
||||||
|
|
||||||
# Add movie
|
# Add movie
|
||||||
done_status = fireEvent('status.get', 'done', single = True)
|
|
||||||
movie = db.query(Movie).filter_by(library_id = group['library'].get('id')).first()
|
movie = db.query(Movie).filter_by(library_id = group['library'].get('id')).first()
|
||||||
if not movie:
|
if not movie:
|
||||||
movie = Movie(
|
movie = Movie(
|
||||||
@@ -59,7 +61,6 @@ class Release(Plugin):
|
|||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
# Add Release
|
# Add Release
|
||||||
snatched_status = fireEvent('status.get', 'snatched', single = True)
|
|
||||||
rel = db.query(Relea).filter(
|
rel = db.query(Relea).filter(
|
||||||
or_(
|
or_(
|
||||||
Relea.identifier == identifier,
|
Relea.identifier == identifier,
|
||||||
@@ -152,8 +153,7 @@ class Release(Plugin):
|
|||||||
|
|
||||||
rel = db.query(Relea).filter_by(id = id).first()
|
rel = db.query(Relea).filter_by(id = id).first()
|
||||||
if rel:
|
if rel:
|
||||||
ignored_status = fireEvent('status.get', 'ignored', single = True)
|
ignored_status, available_status = fireEvent('status.get', ['ignored', 'available'], single = True)
|
||||||
available_status = fireEvent('status.get', 'available', single = True)
|
|
||||||
rel.status_id = available_status.get('id') if rel.status_id is ignored_status.get('id') else ignored_status.get('id')
|
rel.status_id = available_status.get('id') if rel.status_id is ignored_status.get('id') else ignored_status.get('id')
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
@@ -166,8 +166,7 @@ class Release(Plugin):
|
|||||||
db = get_session()
|
db = get_session()
|
||||||
id = getParam('id')
|
id = getParam('id')
|
||||||
|
|
||||||
snatched_status = fireEvent('status.add', 'snatched', single = True)
|
snatched_status, done_status = fireEvent('status.get', ['snatched', 'done'], single = True)
|
||||||
done_status = fireEvent('status.get', 'done', single = True)
|
|
||||||
|
|
||||||
rel = db.query(Relea).filter_by(id = id).first()
|
rel = db.query(Relea).filter_by(id = id).first()
|
||||||
if rel:
|
if rel:
|
||||||
|
|||||||
@@ -131,10 +131,8 @@ class Renamer(Plugin):
|
|||||||
separator = self.conf('separator')
|
separator = self.conf('separator')
|
||||||
|
|
||||||
# Statusses
|
# Statusses
|
||||||
done_status = fireEvent('status.get', 'done', single = True)
|
done_status, active_status, downloaded_status, snatched_status = \
|
||||||
active_status = fireEvent('status.get', 'active', single = True)
|
fireEvent('status.get', ['done', 'active', 'downloaded', 'snatched'], single = True)
|
||||||
downloaded_status = fireEvent('status.get', 'downloaded', single = True)
|
|
||||||
snatched_status = fireEvent('status.get', 'snatched', single = True)
|
|
||||||
|
|
||||||
for group_identifier in groups:
|
for group_identifier in groups:
|
||||||
|
|
||||||
@@ -588,11 +586,8 @@ Remove it if you want it to be renamed (again, or at least let it try again)
|
|||||||
|
|
||||||
self.checking_snatched = True
|
self.checking_snatched = True
|
||||||
|
|
||||||
snatched_status = fireEvent('status.get', 'snatched', single = True)
|
snatched_status, ignored_status, failed_status, done_status = \
|
||||||
ignored_status = fireEvent('status.get', 'ignored', single = True)
|
fireEvent('status.get', ['snatched', 'ignored', 'failed', 'done'], single = True)
|
||||||
failed_status = fireEvent('status.get', 'failed', single = True)
|
|
||||||
|
|
||||||
done_status = fireEvent('status.get', 'done', single = True)
|
|
||||||
|
|
||||||
db = get_session()
|
db = get_session()
|
||||||
rels = db.query(Release).filter_by(status_id = snatched_status.get('id')).all()
|
rels = db.query(Release).filter_by(status_id = snatched_status.get('id')).all()
|
||||||
|
|||||||
@@ -146,8 +146,7 @@ class Searcher(Plugin):
|
|||||||
|
|
||||||
pre_releases = fireEvent('quality.pre_releases', single = True)
|
pre_releases = fireEvent('quality.pre_releases', single = True)
|
||||||
release_dates = fireEvent('library.update_release_date', identifier = movie['library']['identifier'], merge = True)
|
release_dates = fireEvent('library.update_release_date', identifier = movie['library']['identifier'], merge = True)
|
||||||
available_status = fireEvent('status.get', 'available', single = True)
|
available_status, ignored_status = fireEvent('status.get', ['available', 'ignored'], single = True)
|
||||||
ignored_status = fireEvent('status.get', 'ignored', single = True)
|
|
||||||
|
|
||||||
found_releases = []
|
found_releases = []
|
||||||
|
|
||||||
|
|||||||
@@ -28,12 +28,11 @@ class StatusPlugin(Plugin):
|
|||||||
status_cached = {}
|
status_cached = {}
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
addEvent('status.add', self.add)
|
addEvent('status.get', self.get)
|
||||||
addEvent('status.get', self.add) # Alias for .add
|
|
||||||
addEvent('status.get_by_id', self.getById)
|
addEvent('status.get_by_id', self.getById)
|
||||||
addEvent('status.all', self.all)
|
addEvent('status.all', self.all)
|
||||||
addEvent('app.initialize', self.fill)
|
addEvent('app.initialize', self.fill)
|
||||||
addEvent('app.load', self.all)
|
addEvent('app.load', self.all) # Cache all statuses
|
||||||
|
|
||||||
addApiView('status.list', self.list, docs = {
|
addApiView('status.list', self.list, docs = {
|
||||||
'desc': 'Check for available update',
|
'desc': 'Check for available update',
|
||||||
@@ -74,26 +73,35 @@ class StatusPlugin(Plugin):
|
|||||||
|
|
||||||
return temp
|
return temp
|
||||||
|
|
||||||
def add(self, identifier):
|
def get(self, identifiers):
|
||||||
|
|
||||||
if self.status_cached.get(identifier):
|
if not isinstance(identifiers, (list)):
|
||||||
return self.status_cached.get(identifier)
|
identifiers = [identifiers]
|
||||||
|
|
||||||
db = get_session()
|
db = get_session()
|
||||||
|
return_list = []
|
||||||
|
|
||||||
s = db.query(Status).filter_by(identifier = identifier).first()
|
for identifier in identifiers:
|
||||||
if not s:
|
|
||||||
s = Status(
|
|
||||||
identifier = identifier,
|
|
||||||
label = toUnicode(identifier.capitalize())
|
|
||||||
)
|
|
||||||
db.add(s)
|
|
||||||
db.commit()
|
|
||||||
|
|
||||||
status_dict = s.to_dict()
|
if self.status_cached.get(identifier):
|
||||||
|
return_list.append(self.status_cached.get(identifier))
|
||||||
|
continue
|
||||||
|
|
||||||
self.status_cached[identifier] = status_dict
|
s = db.query(Status).filter_by(identifier = identifier).first()
|
||||||
return status_dict
|
if not s:
|
||||||
|
s = Status(
|
||||||
|
identifier = identifier,
|
||||||
|
label = toUnicode(identifier.capitalize())
|
||||||
|
)
|
||||||
|
db.add(s)
|
||||||
|
db.commit()
|
||||||
|
|
||||||
|
status_dict = s.to_dict()
|
||||||
|
|
||||||
|
self.status_cached[identifier] = status_dict
|
||||||
|
return_list.append(status_dict)
|
||||||
|
|
||||||
|
return return_list if len(identifiers) > 1 else return_list[0]
|
||||||
|
|
||||||
def fill(self):
|
def fill(self):
|
||||||
|
|
||||||
|
|||||||
@@ -52,8 +52,7 @@ class MovieResultModifier(Plugin):
|
|||||||
if l:
|
if l:
|
||||||
|
|
||||||
# Statuses
|
# Statuses
|
||||||
active_status = fireEvent('status.get', 'active', single = True)
|
active_status, done_status = fireEvent('status.get', ['active', 'done'], single = True)
|
||||||
done_status = fireEvent('status.get', 'done', single = True)
|
|
||||||
|
|
||||||
for movie in l.movies:
|
for movie in l.movies:
|
||||||
if movie.status_id == active_status['id']:
|
if movie.status_id == active_status['id']:
|
||||||
|
|||||||
Reference in new issue
Block a user