From c9e0910c550559c99842a7e6c680dc7d9cf05853 Mon Sep 17 00:00:00 2001 From: Ruud Date: Fri, 24 Jan 2014 15:29:24 +0100 Subject: [PATCH] Can't use len() on filter iterator. fix #2762 --- couchpotato/core/helpers/variable.py | 13 +++++++++++-- couchpotato/core/media/_base/searcher/main.py | 7 +++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/couchpotato/core/helpers/variable.py b/couchpotato/core/helpers/variable.py index 69067e8d..7e9d6ba6 100644 --- a/couchpotato/core/helpers/variable.py +++ b/couchpotato/core/helpers/variable.py @@ -9,7 +9,7 @@ import re import string import sys import six -from six.moves import map, zip +from six.moves import map, zip, filter log = CPLog(__name__) @@ -260,7 +260,16 @@ def randomString(size = 8, chars = string.ascii_uppercase + string.digits): def splitString(str, split_on = ',', clean = True): l = [x.strip() for x in str.split(split_on)] if str else [] - return [x for x in l if x] if clean else l + return removeEmpty(l) if clean else l + + +def removeEmpty(l): + return list(filter(None, l)) + + +def removeDuplicate(l): + seen = set() + return [x for x in l if x not in seen and not seen.add(x)] def dictIsSubset(a, b): diff --git a/couchpotato/core/media/_base/searcher/main.py b/couchpotato/core/media/_base/searcher/main.py index 17dc9b57..d05ef09c 100644 --- a/couchpotato/core/media/_base/searcher/main.py +++ b/couchpotato/core/media/_base/searcher/main.py @@ -1,12 +1,11 @@ from couchpotato.api import addApiView from couchpotato.core.event import addEvent, fireEvent from couchpotato.core.helpers.encoding import simplifyString -from couchpotato.core.helpers.variable import splitString +from couchpotato.core.helpers.variable import splitString, removeEmpty from couchpotato.core.logger import CPLog from couchpotato.core.media._base.searcher.base import SearcherBase import datetime import re -from six.moves import filter log = CPLog(__name__) @@ -155,8 +154,8 @@ class Searcher(SearcherBase): check_movie = fireEvent('scanner.name_year', check_name, single = True) try: - check_words = filter(None, re.split('\W+', check_movie.get('name', ''))) - movie_words = filter(None, re.split('\W+', simplifyString(movie_name))) + check_words = removeEmpty(re.split('\W+', check_movie.get('name', ''))) + movie_words = removeEmpty(re.split('\W+', simplifyString(movie_name))) if len(check_words) > 0 and len(movie_words) > 0 and len(list(set(check_words) - set(movie_words))) == 0: return True