Fix square brackets in ignore/require words causing false positive matches

This commit is contained in:
Adam 2015-11-28 23:18:58 +08:00
parent e01303242f
commit 97d306b866
3 changed files with 32 additions and 9 deletions

View file

@ -80,6 +80,7 @@
* Change to move JS code out of home template and into dedicated file
* Change to remove branch from window title
* Change to move JS code out of inc_top template and into dedicated file
* Fix square brackets in ignore/require words causing false positive matches
[develop changelog]
* Enable Alpha Ratio again now that the secure login page over https is fixed

View file

@ -190,10 +190,10 @@ def filter_release_name(name, filter_words):
Returns: False if the release name is OK, True if it contains one of the filter_words
"""
if filter_words:
filters = [re.compile('.*%s.*' % filter.strip(), re.I) for filter in filter_words.split(',')]
filters = [filter.strip() for filter in filter_words.split(',')]
for regfilter in filters:
if regfilter.search(name):
logger.log(u"" + name + " contains pattern: " + regfilter.pattern, logger.DEBUG)
if regfilter in name:
logger.log(u"" + name + " contains pattern: " + regfilter, logger.DEBUG)
return True
return False
@ -205,7 +205,7 @@ def pickBestResult(results, show, quality_list=None):
# find the best result for the current episode
bestResult = None
for cur_result in results:
logger.log("Quality of " + cur_result.name + " is " + Quality.qualityStrings[cur_result.quality])
if show.is_anime:
@ -438,7 +438,7 @@ def searchForNeededEpisodes(episodes):
bestResult.content = bestResult.provider.get_url(bestResult.url)
if not bestResult.content:
continue
foundResults[curEp] = bestResult
threading.currentThread().name = origThreadName
@ -549,10 +549,10 @@ def searchProviders(show, episodes, manual_search=False):
seasonQual], logger.DEBUG)
myDB = db.DBConnection()
allEps = [int(x["episode"])
for x in myDB.select("SELECT episode FROM tv_episodes WHERE showid = ? AND ( season IN ( " + ','.join(searchedSeasons) + " ) )",
allEps = [int(x["episode"])
for x in myDB.select("SELECT episode FROM tv_episodes WHERE showid = ? AND ( season IN ( " + ','.join(searchedSeasons) + " ) )",
[show.indexerid])]
logger.log(u"Executed query: [SELECT episode FROM tv_episodes WHERE showid = %s AND season in %s]" % (show.indexerid, ','.join(searchedSeasons)))
logger.log(u"Episode list: " + str(allEps), logger.DEBUG)
@ -706,7 +706,7 @@ def searchProviders(show, episodes, manual_search=False):
bestResult.content = bestResult.provider.get_url(bestResult.url)
if not bestResult.content:
continue
# add result if its not a duplicate and
found = False
for i, result in enumerate(finalResults):

22
tests/search_tests.py Normal file
View file

@ -0,0 +1,22 @@
import unittest
import sys
import os.path
from sickbeard.search import filter_release_name
sys.path.insert(1, os.path.abspath('..'))
class TestCase(unittest.TestCase):
def test_filter_release_name(self):
test_cases = [
('[HorribleSubs].Heavy.Object.-.08.[480p]', '[480p]', True),
('[HorribleSubs].Heavy.Object.-.08.[480p]', '480p', True),
('[HorribleSubs].Heavy.Object.-.08.[480p]', '[720p]', False),
('[HorribleSubs].Heavy.Object.-.08.[480p]', '720p', False),
('[HorribleSubs].Heavy.Object.-.08.[480p]', '', False),
]
for name, filter_words, expected_result in test_cases:
self.assertEqual(expected_result, filter_release_name(name, filter_words))
if __name__ == '__main__':
unittest.main()