Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ‘required words’ that start with a '+' an absolute requirement #8791

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sickchill/gui/slick/views/config_search.mako
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@
</div>
<div class="row">
<div class="col-md-12">
<label for="require_words">${_('''results with no word from this list will be ignored<br>separate words with a comma, e.g. "word1,word2,word3"''')}</label>
<label for="require_words">${_('''results with no word from this list will be ignored<br>separate words with a comma, e.g. "word1,word2,word3"<br>words starting with a plus sign must always be present''')}</label>
</div>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions sickchill/gui/slick/views/editShow.mako
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@
<div class="row">
<div class="col-md-12">
<label>${_('search results with no words from this list will be ignored.')}</label>
<label>${_('words starting with a plus sign must always be present.')}</label>
<label><b>${_('note')}:</b> ${_('this option overrides the globally required words, and globally ignored words!')}</label>
</div>
</div>
Expand Down
38 changes: 36 additions & 2 deletions sickchill/oldbeard/show_name_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,28 @@ def containsAtLeastOneWord(name, words):
return False


def contains_all_words(name, words):
"""
Filters out results based on filter_words

name: name to check
words : string of words separated by a ',' or list of words

Returns: True if all words from the list are present in name, or the first word from the list not found in name.
"""
if isinstance(words, str):
words = words.split(",")

words = {word.strip() for word in words if word.strip()}
if not any(words):
return True

for word, regexp in {word: re.compile(r"(^|[\W_]){0}($|[\W_])".format(re.escape(word)), re.I) for word in words}.items():
if not regexp.search(name):
return word
return True


def filter_bad_releases(name, parse=True, show=None):
"""
Filters out non-english and just all-around stupid releases by comparing them
Expand All @@ -59,14 +81,17 @@ def filter_bad_releases(name, parse=True, show=None):

def clean_set(words):
return {x.strip() for x in set((words or "").lower().split(",")) if x.strip()}

def remove_plus_sign(words):
return {s[1:] if s.startswith('+') else s for s in words}

# if any of the bad strings are in the name then say no
ignore_words = resultFilters
ignore_words = ignore_words.union(clean_set(show and show.rls_ignore_words or "")) # Show specific ignored words
ignore_words = ignore_words.union(clean_set(settings.IGNORE_WORDS)) # Plus Global ignored words
ignore_words = ignore_words.difference(clean_set(show and show.rls_require_words or "")) # Minus show specific required words
ignore_words = ignore_words.difference(remove_plus_sign(clean_set(show and show.rls_require_words or ""))) # Minus show specific required words
if settings.REQUIRE_WORDS and not (show and show.rls_ignore_words): # Only remove global require words from the list if we arent using show ignore words
ignore_words = ignore_words.difference(clean_set(settings.REQUIRE_WORDS))
ignore_words = ignore_words.difference(remove_plus_sign(clean_set(settings.REQUIRE_WORDS)))

word = containsAtLeastOneWord(name, ignore_words)
if word:
Expand All @@ -77,10 +102,19 @@ def clean_set(words):
require_words = set()
require_words = require_words.union(clean_set(show and show.rls_require_words or "")) # Show specific required words
require_words = require_words.union(clean_set(settings.REQUIRE_WORDS)) # Plus Global required words
require_words_absolute = {s[1:] for s in require_words if s.startswith('+')} # Check for words starting with '+' which are an absolute requirement
require_words = remove_plus_sign(require_words) # Clean require_words (remove leading '+')
require_words = require_words.difference(clean_set(show and show.rls_ignore_words or "")) # Minus show specific ignored words
if settings.IGNORE_WORDS and not (show and show.rls_require_words): # Only remove global ignore words from the list if we arent using show require words
require_words = require_words.difference(clean_set(settings.IGNORE_WORDS))

# First check for the words which are an absolute requirement
if require_words_absolute:
word = contains_all_words(name, require_words_absolute)
if isinstance(word, str):
logger.info(f"Release: {name} doesn't contain required word {word}, ignoring it")
return False

if require_words and not containsAtLeastOneWord(name, require_words):
logger.info("Release: " + name + " doesn't contain any of " + ", ".join(set(require_words)) + ", ignoring it")
return False
Expand Down
Loading