mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-20 14:42:05 +00:00
added extra comments and corrected existing ones
This commit is contained in:
@ -27,7 +27,7 @@ const cleanupArtistName = (config, artist) => {
|
||||
return artist
|
||||
}
|
||||
|
||||
const createFormData = (params) => {
|
||||
const createFormData = params => {
|
||||
// creates the body for in the post request
|
||||
let formData = new URLSearchParams();
|
||||
for (key in params) {
|
||||
@ -64,7 +64,7 @@ const createApiSig = (params, secret) => {
|
||||
}
|
||||
|
||||
const createToken = async ({ api_key, api_root, secret }) => {
|
||||
// creates an auth token
|
||||
// creates and stores the auth token
|
||||
data = {
|
||||
method: 'auth.gettoken',
|
||||
api_key: api_key,
|
||||
@ -76,16 +76,16 @@ const createToken = async ({api_key, api_root, secret}) => {
|
||||
return response?.token;
|
||||
}
|
||||
|
||||
const authenticate = async (config) => {
|
||||
// asks user for authentication
|
||||
const authenticate = async config => {
|
||||
// asks the user for authentication
|
||||
config.token = await createToken(config);
|
||||
setOptions('last-fm', config);
|
||||
open(`https://www.last.fm/api/auth/?api_key=${config.api_key}&token=${config.token}`);
|
||||
return config;
|
||||
}
|
||||
|
||||
const getAndSetSessionKey = async (config) => {
|
||||
// get and set the session key
|
||||
const getAndSetSessionKey = async config => {
|
||||
// get and store the session key
|
||||
data = {
|
||||
api_key: config.api_key,
|
||||
format: 'json',
|
||||
@ -104,7 +104,7 @@ const getAndSetSessionKey = async (config) => {
|
||||
|
||||
|
||||
const addScrobble = async (songInfo, config) => {
|
||||
// this adds one scrobbled song
|
||||
// this adds one scrobbled song to last.fm
|
||||
if (!config.session_key)
|
||||
await getAndSetSessionKey(config);
|
||||
data = {
|
||||
@ -121,7 +121,7 @@ const addScrobble = async (songInfo, config) => {
|
||||
axios.post('https://ws.audioscrobbler.com/2.0/', createFormData(data))
|
||||
.catch(res => {
|
||||
if (res.response.data.error == 9) {
|
||||
// session key is invalid
|
||||
// session key is invalid, so remove it from the config and reauthenticate
|
||||
config.session_key = undefined;
|
||||
setOptions('last-fm', config);
|
||||
authenticate(config);
|
||||
@ -130,7 +130,7 @@ const addScrobble = async (songInfo, config) => {
|
||||
}
|
||||
|
||||
const setNowPlaying = async (songInfo, config) => {
|
||||
// this adds one scrobbled song
|
||||
// this sets the now playing status in last.fm
|
||||
if (!config.session_key)
|
||||
await getAndSetSessionKey(config);
|
||||
data = {
|
||||
@ -146,7 +146,7 @@ const setNowPlaying = async (songInfo, config) => {
|
||||
axios.post('https://ws.audioscrobbler.com/2.0/', createFormData(data))
|
||||
.catch(res => {
|
||||
if (res.response.data.error == 9) {
|
||||
// session key is invalid
|
||||
// session key is invalid, so remove it from the config and reauthenticate
|
||||
config.session_key = undefined;
|
||||
setOptions('last-fm', config);
|
||||
authenticate(config);
|
||||
@ -173,7 +173,9 @@ const lastfm = async (win, config) => {
|
||||
}
|
||||
|
||||
registerCallback( songInfo => {
|
||||
// set remove the old scrobble timer
|
||||
clearTimeout(scrobbleTimer);
|
||||
// make the artist name a bit cleaner
|
||||
songInfo.artist = cleanupArtistName(config, songInfo.artist);
|
||||
if (!songInfo.isPaused) {
|
||||
setNowPlaying(songInfo, config);
|
||||
|
||||
Reference in New Issue
Block a user