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

Last.fm support #196

Merged
merged 10 commits into from
Apr 28, 2021
Merged

Last.fm support #196

merged 10 commits into from
Apr 28, 2021

Conversation

semvis123
Copy link
Contributor

@semvis123 semvis123 commented Mar 19, 2021

This adds a last.fm plugin with the following features,

  • Scrobble support, adds scrobbles to your last.fm account.
  • Now playing support, also known as currently scrobbling.

When the plugin is enabled for the first time, it should ask the user to authenticate with last.fm and give permissions to YouTube music.

currently only played songs are added
@semvis123 semvis123 changed the title Lastfm support [DRAFT] Lastfm support Mar 19, 2021
@semvis123 semvis123 changed the title [DRAFT] Lastfm support Lastfm support Mar 19, 2021
@semvis123 semvis123 marked this pull request as draft March 19, 2021 20:38
@semvis123 semvis123 marked this pull request as ready for review March 19, 2021 21:00
@semvis123 semvis123 changed the title Lastfm support Last.fm support Mar 19, 2021
Copy link
Owner

@th-ch th-ch left a comment

Choose a reason for hiding this comment

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

Looks good, thanks for the contribution! Left a few minor comments, feel free to address them, otherwise I'm ok to merge and do a follow up! (note: recent merges have created conflicts)

plugins/last-fm/back.js Outdated Show resolved Hide resolved
const queryData = [];
params.api_sig = api_sig;
for (key in params) {
queryData.push(`${key}=${params[key]}`);
Copy link
Owner

Choose a reason for hiding this comment

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

To avoid issues:

Suggested change
queryData.push(`${key}=${params[key]}`);
queryData.push(`${encodeURIComponent(key)}=${encodeURIComponent (params[key])}`);

const cleanupArtistName = (config, artist) => {
// removes the suffixes of the artist name for more recognition by last.fm
let { suffixesToRemove } = config;
if (suffixesToRemove === undefined) {
Copy link
Owner

Choose a reason for hiding this comment

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

nit: it does not seem necessary to override the suffixes if not defined, we can just return early:

Suggested change
if (suffixesToRemove === undefined) {
if (suffixesToRemove === undefined) {
return artist;
}

duration: songInfo.songDuration,
};
data.api_sig = createApiSig(data, config.secret);
axios.post('https://ws.audioscrobbler.com/2.0/', createFormData(data))
Copy link
Owner

Choose a reason for hiding this comment

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

nit: node-fetch is already there and could be used (but axios is well-known and widely used so no big deal and no need to change it)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, didn't know you could post data with node-fetch, removed axios, because there is no need for an extra dependency :)

duration: songInfo.songDuration,
};
data.api_sig = createApiSig(data, config.secret);
axios.post('https://ws.audioscrobbler.com/2.0/', createFormData(data))
Copy link
Owner

Choose a reason for hiding this comment

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

Code looks mostly the same as addScrobble so it could probably be refactored with a util function.

@semvis123
Copy link
Contributor Author

Thanks for your feedback, I have done some additional refactoring and solved the merge conflicts.

Copy link
Owner

@th-ch th-ch left a comment

Choose a reason for hiding this comment

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

Code looks good, thanks for the contribution! Merging so that it can ship in the next version, will also update the yarn.lock file!

@@ -1708,6 +1708,13 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==

axios@^0.21.1:
Copy link
Owner

Choose a reason for hiding this comment

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

Not a big deal but it seems the lock file is not up-to-date (axios is not used anymore), yarn will need to be run on the project to update it!

@th-ch th-ch merged commit 5312b36 into th-ch:master Apr 28, 2021
@VanGeko
Copy link

VanGeko commented Jan 27, 2022

any chance to see the lastfm plugin, in the ytm App?
there is a lot of wrong titles and i want to correct them.

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