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

Issue2205: search for lyrics using part of song title preceding ':' #2206

Merged
merged 6 commits into from Sep 25, 2016

Conversation

Kraymer
Copy link
Collaborator

@Kraymer Kraymer commented Sep 23, 2016

No description provided.

@ghost
Copy link

ghost commented Sep 23, 2016

Can you add a changelog entry too?

for title in list(titles):
titles.add(strip_part(title, pattern))

# Remove part of the title string after colon ':'
Copy link
Member

Choose a reason for hiding this comment

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

This comment could use a tiny bit more detail: in particular, that this helps with songs with subtitles.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@sampsyo
Copy link
Member

sampsyo commented Sep 23, 2016

Nice! That was fast! This looks great to me. And I like the refactoring too.

Rather than using an unordered set for storing pairs, append to a list
and build an OrderedDict from it to filter duplicated strings while
keeping order.
title, artist = item.title, item.artist
titles = [title]
artists = [artist]
titles = set([title])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

rather than using set that does not keep order (original title & artist should be yielded first), we should append to a list and remove duplicates at the end.

title, artist = item.title, item.artist
titles = [title]
artists = [artist]
titles = set([title])
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Add a unit test that checks that original artist and title are yielded first.

@Kraymer
Copy link
Collaborator Author

Kraymer commented Sep 25, 2016

I've changed the implementation slightly, do you mind having another look on it ?


# Yield artist and title obtained from item first
titles = list(OrderedDict.fromkeys([title] + titles))
artists = list(OrderedDict.fromkeys([artist] + artists))
Copy link
Member

Choose a reason for hiding this comment

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

Is the idea with the OrderedDict to remove duplicates while preserving the order? That makes sense, but a couple of improvements come to mind:

  • First, the original title and artist are already first in the list (from the initialization, above).
  • We could also just avoid inserting duplicates in the first place. Specifically, strip_part could return None instead of the original string when the pattern doesn't match, and we could avoid appending that to the list (or just filter out Nones from the list).

Copy link
Collaborator Author

@Kraymer Kraymer Sep 25, 2016

Choose a reason for hiding this comment

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

Right. New commit : I moved the burden to update the alternatives lists to the function that performs the re.search and think it works better that way : it avoids the return None+filter processing and makes caller code simpler.

Copy link
Member

Choose a reason for hiding this comment

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

Nice! This is even better. Using a list of patterns makes this declarative, which avoids repetition and a whole vector of potential bugs. ✨

Thanks! I say merge when ready.

Delegate the update of titles and artists lists to the helper
generate_alternatives() function.
@Kraymer Kraymer merged commit 0140f2f into beetbox:master Sep 25, 2016
@Kraymer Kraymer deleted the issue2205 branch January 29, 2018 19:50
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.

None yet

2 participants