Spotify Now Playing

Integrate Spotify Now Playing To Use A New Command: !whatsplaying
Console For The API: My Dashboard | Spotify for Developers

First enable spotify scrobbline to last fm:

Then make use of this custom script:

Not Working

“Not working” isn’t helpful :slight_smile:

Please tell us, what is not working

Yeah going to need more information here.

Did you add the api key and user info to the script? you have to for it to work.

I know the script works because I still use it to this day.

everything seems to be working but i am trying to turn off the auto announce and it doesn’t seem to want to turn off

EDIT: i figured out the toggle its !lastfm announce disabled not !lastfm toggle auto

@dungi
@UsernamesSuck
@DrivenDemon
@Ender_Just_Dance

sign up!

popular scrobblers

save file inside

./commands

as

lastfmCommand.js

complete command info from

!song help

paste bin file

Github Pull for Phantom Bot

(function() {
	const db_title = "lastfm";
	const default_last_fm_api_key = "293111fdaf9f475bf1f5463a063ffa66";
	const api_url_basics = "https://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&format=json&limit=1";
	// variable
	var last_fm_api_key = default_last_fm_api_key;
	var last_fm_username = "";
	var artist = "";
	var name = "";
	var sender;
	
	function initVars() {
		last_fm_username = $.inidb.get(db_title, 'user_name');
		last_fm_api_key = $.inidb.get(db_title, "api_key");
	}
	
	function getTrackFromLastFm(index, repeater) {
		try {
			var jsonObj = JSON.parse($.customAPI.get(api_url_basics + "&page=" + index + "&user=" + last_fm_username + "&api_key=" + last_fm_api_key).content);
			var current_track = jsonObj.recenttracks.track[0];
			if (index > 1) {
				track = jsonObj.recenttracks.track[1];
				$.say($.whisperPrefix(sender) + " 🎶 " + track["name"] + " - " +  track["artist"]["#text"] + ", " + track["album"]["#text"]);
			} else if (index == 1) {
				var new_track = ((artist != current_track["artist"]["#text"]) || (name != current_track["name"]));
				artist = current_track["artist"]["#text"];
				name = current_track["name"];
				if (!repeater || new_track) {
					$.say((repeater ? "" : $.whisperPrefix(sender)) + " 🎶 " + current_track["name"] + " - " +  current_track["artist"]["#text"] + ", " + current_track["album"]["#text"]);
				}
			}
			return true;
		} catch (ex) {
			$.consoleLn(ex);
			$.consoleLn(ex.stack);				
		}
		return false;
	}

	$.bind('command', function(event) {

		sender = event.getSender(); // Grabs the person who used the command
		var command = event.getCommand(), // Grabs the command being used
			args = event.getArgs(), // arguments used for your commands like maybe 
			action = args[0], // the array of args received
			subAction = args[1];

		if (command.equalsIgnoreCase('song')) {
			initVars();
			if (action === undefined) {
				getTrackFromLastFm(1, false);
			} else if (action.equalsIgnoreCase("previous")) {
				getTrackFromLastFm(2, false);
			} else if (action.equalsIgnoreCase("index")) {
				getTrackFromLastFm(parseInt(subAction));
			} else if (action.equalsIgnoreCase("help")) {
				$.say($.whisperPrefix(sender) + " !song - get the current played song \\ !song on - enable \\ !song off - disable \\ !song previous - last played song \\ !song index * - last played song numerical 1 (newest) to max-oldest \\  !song key * - set the lastfm api key \\ !song user * - set the lastfm user name", $.whisperPrefix(sender));
			} else if (action.equalsIgnoreCase("user")) {
				if (!$.isBot(sender)) {
					return;
				}
				last_fm_username = subAction;
				if (getTrackFromLastFm(1, false)) {
					$.inidb.set(db_title, 'user_name', subAction);
					$.inidb.SaveAll(true);
					$.say($.whisperPrefix(sender) + " user name set to " + last_fm_username);
				} else {
					initVars();
					$.say($.whisperPrefix(sender) + " user name ignored keeping old username " + last_fm_username);
				}
			} else if (action.equalsIgnoreCase('key')) {
				if (!$.isBot(sender)) {
					return;
				}
				last_fm_api_key = subAction;
				if (getTrackFromLastFm(1, false)) {
					$.inidb.set(db_title, "api_key", subAction);
					$.inidb.SaveAll(true);
					$.say($.whisperPrefix(sender) + " api key set to" + last_fm_api_key);
				} else {
					initVars();
					$.say($.whisperPrefix(sender) + " api key ignored keeping old api key ");
				}
			} else if (action.equalsIgnoreCase('on')) {
				if (!$.isBot(sender)) {
					return;
				}
				$.inidb.set(db_title, 'enabled', true);
			} else if (action.equalsIgnoreCase('off')) {
				if (!$.isBot(sender)) {
					return;
				}
				$.inidb.set(db_title, 'enabled', false);
			}
			$.consoleLn("command completed");
		}
	});

	$.bind('initReady', function() {

		if (!$.inidb.exists(db_title, 'initial_push')) {
			setTimeout(function() {
				$.inidb.set(db_title, 'initial_push', true);
				$.inidb.set(db_title, 'enabled', true);
				$.inidb.set(db_title, 'user_name', 'rj');
				$.inidb.set(db_title, 'api_key', default_last_fm_api_key);
				$.inidb.SaveAll(true);
			}, 5 * 1000);
		};
		if ($.bot.isModuleEnabled('./commands/lastfmCommand.js')) {
			initVars();
			$.registerChatCommand('./commands/lastfmCommand.js', 'song');
			setInterval(function() {
				if ($.inidb.get(db_title, 'enabled') == 'true') {
					if (!getTrackFromLastFm(1, true)) {
						$.consoleLn("failed to get last.fm track info");
					}
				}
			}, 2.5 * 1000);
		}
	});

})();

Nice thing :slight_smile: I will try this out. Thanks

Cool thank you!

“!song key”, “!song user”, “!song on”, “!song off” dont change data in the database. Everything worked for me when I manually entered the database and inserted the correct data

@astrams
I’m sorry to here that.

It works for me.
Did you debug?

So, most of you are most likely aware of the recent adjustments that how to change spotify username has made with regard to opening up its platform for developers to build apps upon

how to change spotify username