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

Support list of names passed to search in tvdb.py #8758

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
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
62 changes: 33 additions & 29 deletions sickchill/show/indexers/tvdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,38 +108,42 @@ def search(self, name, language=None, exact=False, indexer_id=False):
if not name:
return result

if re.match(r"^t?t?\d{7,8}$", name) or re.match(r"^\d{6}$", name):
try:
if re.match(r"^t?t?\d{7,8}$", name):
result = self._search(imdbId=f'tt{name.strip("t")}', language=language)
elif re.match(r"^\d{6}$", name):
series = self._series(name, language=language)
if series:
result = [series.info(language)]
except (requests.exceptions.RequestException, requests.exceptions.HTTPError, Exception):
logger.debug(traceback.format_exc())
else:
# Name as provided (usually from nfo)
names = [name]
if not exact:
# Name without year and separator
test = re.match(r"^(.+?)[. -]+\(\d{4}\)?$", name)
if test:
names.append(test.group(1).strip())
# Name with spaces
if re.match(r"[. -_]", name):
names.append(re.sub(r"[. -_]", " ", name).strip())
if test:
# Name with spaces and without year
names.append(re.sub(r"[. -_]", " ", test.group(1)).strip())

for attempt in set(n for n in names if n.strip()):
if isinstance(name, str):
Copy link
Contributor

@miigotu miigotu May 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this join the list like the other guessit fixes instead of just checking if it's a string?

On line 1 add:

try:
    from collections import Iterable
except (ModuleNotFoundError, ImportError):
    # Iterable moved in python3.10
    from collections.abc import Iterable

After line 106 add:

if isinstance(name, Iterable) and not isinstance(name, (str, bytes);
    name = " ".join(name)

Then remove the rest of the changes here (we know it's a string then)

if re.match(r"^t?t?\d{7,8}$", name) or re.match(r"^\d{6}$", name):
try:
result = self._search(attempt, language=language)
if result:
break
if re.match(r"^t?t?\d{7,8}$", name):
result = self._search(imdbId=f'tt{name.strip("t")}', language=language)
elif re.match(r"^\d{6}$", name):
series = self._series(name, language=language)
if series:
result = [series.info(language)]
except (requests.exceptions.RequestException, requests.exceptions.HTTPError, Exception):
logger.debug(traceback.format_exc())
else:
# Name as provided (usually from nfo)
names = [name]
if not exact:
# Name without year and separator
test = re.match(r"^(.+?)[. -]+\(\d{4}\)?$", name)
if test:
names.append(test.group(1).strip())
# Name with spaces
if re.match(r"[. -_]", name):
names.append(re.sub(r"[. -_]", " ", name).strip())
if test:
# Name with spaces and without year
names.append(re.sub(r"[. -_]", " ", test.group(1)).strip())

for attempt in set(n for n in names if n.strip()):
try:
result = self._search(attempt, language=language)
if result:
break
except (requests.exceptions.RequestException, requests.exceptions.HTTPError, Exception):
logger.debug(traceback.format_exc())
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this else needs removed. We don't want to search for ["fast", "&", "furious"] each individually, we want to join that list and search for the full string.

for n in name:
result.extend(self.search(n, language, exact, indexer_id))
Comment on lines +145 to +146
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recursive call for list handling might lead to performance issues.

Consider using a loop to handle each item in the list within the same method instance to avoid the overhead of recursive calls. This approach can also make the method easier to debug and maintain.


return result

Expand Down
Loading