Skip to content

Instantly share code, notes, and snippets.

@bsquidwrd
Last active October 20, 2022 11:36
Show Gist options
  • Save bsquidwrd/7fdff9dcd39a3e24670c321d05780ba2 to your computer and use it in GitHub Desktop.
Save bsquidwrd/7fdff9dcd39a3e24670c321d05780ba2 to your computer and use it in GitHub Desktop.
PhantomBot !song command setup

In order to get Spotify now playing you must first enable Last.fm scrobbling inside your Spotify settings and sync it with your last.fm account.

Make sure to fill in the user and api key which you can get from here.

You must place the file inside your /var/www/html directory and name it something such as currentsong.php or song.php

Then, from Twitch chat, you can add a command like this:

!addcom !currentsong Current Song: (customapi thentypeyourwebsiteIPordomainnamehere)

Edit by IllusionaryOne

As of version 2.3.5.2 you can do this all through a customapijson command and no longer need an external script, there has been an enhancement made to JSON parsing that allows for this:

!addcom command_name_you_want (customapijson http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=USER_ID&api_key=API_KEY&limit=1&format=json recenttracks.track.0.name { by } recenttracks.track.0.artist.#text)
<?php
$json = file_get_contents('http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&user=[typelast.fmname]&api_key=[typeAPIkeyhere]&limit=1&format=json');
$obj = json_decode($json);
$songName = (string)$obj->recenttracks->track[0]->name;
$artist = (string)$obj->recenttracks->track[0]->artist->{"#text"};
echo $songName . " by " . $artist;
?>
{
"recenttracks": {
"track": [{
"artist": {
"#text": "Jackal",
"mbid": "cba76057-c7d0-4ab9-a104-eb2ba4a6ecca"
},
"name": "Anonymous (feat. Mister Blonde)",
"streamable": "0",
"mbid": "",
"album": {
"#text": "Anonymous (feat. Mister Blonde)",
"mbid": ""
},
"url": "https://www.last.fm/music/Jackal/_/Anonymous+(feat.+Mister+Blonde)",
"image": [{
"#text": "",
"size": "small"
}, {
"#text": "",
"size": "medium"
}, {
"#text": "",
"size": "large"
}, {
"#text": "",
"size": "extralarge"
}],
"@attr": {
"nowplaying": "true"
}
}],
"@attr": {
"user": "bsquidwrd",
"page": "1",
"perPage": "1",
"totalPages": "0",
"total": "0"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment