Skip to content

[fix] emby: strip year in search#2966

Merged
gazpachoking merged 5 commits intoFlexget:developfrom
soloam:emby_search_strip_year
May 6, 2021
Merged

[fix] emby: strip year in search#2966
gazpachoking merged 5 commits intoFlexget:developfrom
soloam:emby_search_strip_year

Conversation

@soloam
Copy link
Copy Markdown
Contributor

@soloam soloam commented May 6, 2021

Motivation for changes:

In emby all search should be preformed without the year

Detailed changes:

  • Strip year from the searches

if not isinstance(name, str):
return name

new_name = re.sub(r'^(.*) \(\d{4}\)(.*)', r'\1\2', new_name)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be cleaner to search and strip the year disregarding the wildcards before and after?
new_name = re.sub(r' ?\(\d{4}\)', '', new_name)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I changed to the tools

@gazpachoking
Copy link
Copy Markdown
Member

We have a utility to split out years, does it work for this purpose, or is yours more specific to this case?

def split_title_year(title: str) -> Tuple[str, Optional[int]]:
"""Splits title containing a year into a title, year pair."""
if not title:
return '', None
if not re.search(r'\d{4}', title):
return title, None
# We only recognize years from the 2nd and 3rd millennium, FlexGetters from the year 3000 be damned!
match = re.search(r'(.*?)\(?([12]\d{3})?\)?$', title)
if not match:
return title, None
title = match.group(1).strip()
year_match = match.group(2)
if year_match and not title:
# title looks like a year, '2020' for example
title = year_match
year = None
elif title and not year_match:
year = None
else:
year = int(year_match)
return title, year

@soloam
Copy link
Copy Markdown
Contributor Author

soloam commented May 6, 2021

That works for me... I'll change it... Tks

EmbyApi.set_common_search_arg(args)

args['SearchTerm'] = kwargs.get('title')
args['SearchTerm'] = EmbyApi.strip_year(kwargs.get('title'))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think you need a helper function to call the helper function. The existing split_title_year already does everything your helper does.

Suggested change
args['SearchTerm'] = EmbyApi.strip_year(kwargs.get('title'))
args['SearchTerm'], _ = split_title_year(kwargs.get('title')

or

Suggested change
args['SearchTerm'] = EmbyApi.strip_year(kwargs.get('title'))
args['SearchTerm'] = split_title_year(kwargs.get('title')[0]

Now that I've written that, I sorta want to change our helper to return a named tuple, so we could use .title rather than [0]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I made that tool return a namedtuple now, so you can call .title on the result

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I pushed a new change, to remove the declaration of the now unused method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I added the use of the named tuple

@soloam soloam requested a review from gazpachoking May 6, 2021 19:12
@gazpachoking gazpachoking merged commit 603853e into Flexget:develop May 6, 2021
@gazpachoking
Copy link
Copy Markdown
Member

Looks good, thanks!

@soloam soloam deleted the emby_search_strip_year branch May 25, 2021 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants