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

fix(lyrics-plus/netease): check correctly for songs #3018

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dompling
Copy link

lyrics time matching logic(For example:给我一首歌的时间)lyrics content mismatch

…example:给我一首歌的时间)lyrics content mismatch
Copy link

graphite-app bot commented May 10, 2024

Graphite Automations

"Add `custom app` label on custom app(s) related changes" took an action on this PR • (05/10/24)

1 label was added to this PR based on ririxi's automation.

dompling added 2 commits May 10, 2024 15:39
1.汉化
2.增加第三方翻译,需在有歌词的情况下
1.汉化
2.增加第三方翻译,需在有歌词的情况下
Copy link
Member

@rxri rxri left a comment

Choose a reason for hiding this comment

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

Change your code to align with biome errors. Also run biome formatter on it too.

@rxri rxri changed the title fix(lyrics): apps lyrics-plus Netease fix(lyrics-plus/netease): check correctly for songs May 11, 2024
Comment on lines +22 to +31
let itemId = items.findIndex(val => Utils.normalize(val.album.name) === expectedAlbumName);

if (itemId === -1) {
itemId = items.findIndex(val => Math.abs(info.duration - val.duration) < 3000);
}

if (itemId === -1) {
itemId = items.findIndex(val => val.name === cleanTitle);
}

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let itemId = items.findIndex(val => Utils.normalize(val.album.name) === expectedAlbumName);
if (itemId === -1) {
itemId = items.findIndex(val => Math.abs(info.duration - val.duration) < 3000);
}
if (itemId === -1) {
itemId = items.findIndex(val => val.name === cleanTitle);
}
const itemId = items.findIndex(val =>
Utils.normalize(val.album.name) === expectedAlbumName ||
Math.abs(info.duration - val.duration) < 3000 ||
val.name === cleanTitle
);

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your reply, but there may be an album mismatch, and then there may be a market match for that data, but it's not actually the original lyrics, so it's more accurate to iterate over it

Copy link
Member

Choose a reason for hiding this comment

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

What you did, with these two ifs, can be shortened into the change I proposed. There's no difference - just better looking code

Copy link
Author

Choose a reason for hiding this comment

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

This piece of code does indeed have a more concise and elegant logic, but it only loops once. During this loop, if a condition is met, it terminates. There might be cases where the lyrics match the time condition but the album does not, causing premature termination of the loop. I encountered a situation where a song had a matching duration but mismatched lyrics. Therefore, the ideal scenario would be one condition per loop.

Copy link
Author

Choose a reason for hiding this comment

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

Sure, the translation of the provided code snippet would be:

(Utils.normalize(val.album.name) === expectedAlbumName ||
    Math.abs(info.duration - val.duration) < 3000 ) && val.name === cleanTitle

Copy link
Member

Choose a reason for hiding this comment

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

Then just do how you got it working, however do it inside the items.findIndex and not separate if statements

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for your help

@rxri
Copy link
Member

rxri commented May 23, 2024

Any update on this? I'm still waiting for implementing the changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants