From a264c75f8c13eb7aebb921b6f22b123534ff731c Mon Sep 17 00:00:00 2001 From: Ruud Date: Fri, 11 Jan 2013 22:31:19 +0100 Subject: [PATCH] Remove releases that aren't found in latest search --- couchpotato/core/plugins/searcher/main.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/couchpotato/core/plugins/searcher/main.py b/couchpotato/core/plugins/searcher/main.py index e18e0a5b..d5e1f672 100644 --- a/couchpotato/core/plugins/searcher/main.py +++ b/couchpotato/core/plugins/searcher/main.py @@ -130,6 +130,8 @@ class Searcher(Plugin): available_status = fireEvent('status.get', 'available', single = True) ignored_status = fireEvent('status.get', 'ignored', single = True) + found_releases = [] + default_title = getTitle(movie['library']) if not default_title: log.error('No proper info found for movie, removing it from library to cause it from having more issues.') @@ -174,10 +176,13 @@ class Searcher(Plugin): # Add them to this movie releases list for nzb in sorted_results: - rls = db.query(Release).filter_by(identifier = md5(nzb['url'])).first() + nzb_identifier = md5(nzb['url']) + found_releases.append(nzb_identifier) + + rls = db.query(Release).filter_by(identifier = nzb_identifier).first() if not rls: rls = Release( - identifier = md5(nzb['url']), + identifier = nzb_identifier, movie_id = movie.get('id'), quality_id = quality_type.get('quality_id'), status_id = available_status.get('id') @@ -234,6 +239,11 @@ class Searcher(Plugin): if self.shuttingDown() or ret: break + # Remove releases that aren't found anymore + for release in movie.get('releases', []): + if release.get('identifier') not in found_releases: + fireEvent('release.delete', release.get('id'), single = True) + fireEvent('notify.frontend', type = 'searcher.ended.%s' % movie['id'], data = True) return ret