NightDev Community Forums

Music stream - Download command

Hi NightDev forum!

I’m a music producer looking to start up my own music livestream on my Youtube channel.

My tracks are all free to download and I’m curious if it’d be possible through NightBot to create a custom command in which when a certain track plays and a viewer types !download, NightBot would reply with a download link for that particular track.

As recommended I’ve searched the forums trying to find someone who has adressed this but couldn’t find anything.

Any help/tips would be much appreciated.

All the best.
x Ikson

Hey @Ikson!

Quick question, what do you use to play your songs, from which source are they played?

Hi @EmilyPerrimon ! I haven’t actually started my stream yet so that’s not decided, figured I’d ask here before I actually dedicate some time to starting it up; I’m open to using whatever source that could possibly enable this feature.

Well, I can see a solution, but your songs will have to be on Spotify.
If they’re not, I can recommend Distrokid, where you can publish all of your songs everywhere for only $20/year. I’m not sponsored, the link isn’t affiliated either, it’s just that after extensive research I chose to go with them to release my own songs once I’ll have some ready, haha!

The next step would be to create an account on Last.fm, then go to:
Settings > Applications > Spotify Scrobbling > Connect
And also make sure Hide recent listening information isn’t ticked in:
Settings > Privacy > Recent listening

Then head over to Pastebin, create an account so you can come back to add new songs later on. Create a new paste, make sure it’s set to never expire and that it’s unlisted.
Here’s how the paste should look like:

Title#1|DownloadLink#1|
Title#2|DownloadLink#2|
...
Title#n|DownloadLink#n

The songs titles must match the style of the titles on Spotify (capitalization, parenthesis, etc.)

And finally here’s the command:

$(eval a=`$(lastfm LASTFM_USERNAME "{{artist}}|{{title}}")`.split(`|`); d=`$(urlfetch json https://pastebin.com/raw/XXXXXXXX)`.split(`|`); if(a[0].toLowerCase()==`YOUR_ARTIST_NAME`.toLowerCase()){if(d.includes(a[1])){`Download ${a[1]} here: ${d[d.indexOf(a[1])+1]}`}else{`There is no link to download ${a[1]} yet.`}}else{`This song isn't from YOUR_ARTIST_NAME.`})

Make sure to replace the following fields:
LASTFM_USERNAME: your Last.fm username
XXXXXXXX: the paste ID
YOUR_ARTIST_NAME: must match your artist name style on Spotify (capitalization, spacing, etc.)

Awesome ! I’ve actually released all my music through a distributor called Amuse. They have a free app (and now on desktop as well) and you get to keep 100% royalty of your earning. I can definitely recommend them; they deliver to all major streaming services/stores.

I’m with you in the guide to the point where you are talking about the Title#1|DownloadLink#1| and the command. Would I paste that in somewhere on the NightBot website?

Is: Title#1|DownloadLink#1| / a reference for the command, so that when someone asks/writes !download in chat the command can look in the Paste to see what download link to send to the viewer who requested it?

Also if this works out I’ll be happy to give you a shoutout in the video description of the live stream, as this feature would be really beneficial to the experience

Oh yeah, I know about Amuse as well. Anyway, that’s great if you have your stuff on Spotify, that’s what we need!

For the command, you can add it via the dashboard or via the chat by typing:

!addcom !download $(eval a=`$(lastfm LASTFM_USERNAME "{{artist}}|{{title}}")`.split(`|`); d=`$(urlfetch json https://pastebin.com/raw/XXXXXXXX)`.split(`|`); if(a[0].toLowerCase()==`YOUR_ARTIST_NAME`.toLowerCase()){if(d.includes(a[1])){`Download ${a[1]} here: ${d[d.indexOf(a[1])+1]}`}else{`There is no link to download ${a[1]} yet.`}}else{`This song isn't from YOUR_ARTIST_NAME.`})

As for the paste, yes, it’s a reference Nightbot will look into, basically, the command looks if the artist playing is you, then it looks in the paste if it has a download link for the playing title, and gives the link if it does.

How do I add the command via dashboard though, do I copy paste it into ‘Message’?

Also - Are the hashtags in the: Title#1|DownloadLink#1| important or can they be removed?

Yes, to add the command via the dashboard, you simply have to paste the code into Message (without the !addcom !download part).

The # are just to indicate “number”, so no, they’re not important. What’s important are the |.

Tried a fast stream tonight. The command didn’t seem to be working so something’s evidently off

When it looks like that, it’s because the command code has been cut if half, I didn’t know you were planning to stream on YouTube, where the chat has a lower character limit than Twitch’s chat (which is my default go to), therefore adding the command via the chat wasn’t the right option, however, you can add it from the dashboard, just copy and paste the following, I updated it with your information.

$(eval a=`$(lastfm IksonOfficial "{{artist}}|{{title}}")`.split(`|`); d=`$(urlfetch json https://pastebin.com/raw/K4eyYK2y)`.split(`|`); if(a[0].toLowerCase()==`Ikson`.toLowerCase()){if(d.includes(a[1])){`Download ${a[1]} here: ${d[d.indexOf(a[1])+1]}`}else{`There is no link to download ${a[1]} yet.`}}else{`This song isn't from Ikson.`})

Also, for the songs you don’t have a downloading link for yet, don’t add them into the paste, if the bot can’t find the song it’ll say: “There is no link to download SONG yet.”

Okay I see, happy mistake because that’s good to know actually; So just copy paste that new code into the Message section of the same custom command and that should make the track titles/download links show up correctly ones !download is written by viewers in chat ? Based on presumption that I have added the name/link to the Pastebin that is, which I have.

P.s I appreciate that you added that last message in, that was very thoughtful as it might take me some time to add in all of the links.

Yes, just copy the new code above in the Message field and it’ll work. And regarding the “no link yet” message, I had to think of every outcome possible, it’s simply error handling, so you can remove every songs that don’t have a download link yet, otherwise it’ll say: “Download SONG here: DownloadLink#1” instead, haha!

At the time I post this reply I just updated the code in every message I sent on this topic, turns out it had a major flaw, and I only noticed it now because I didn’t have time to test it before this evening, I found the error and fixed it.

It didn’t. I just pasted your last message in the into the message command of my Nightbot custom command, doesn’t display link in Live chat on Youtube. Might something be off about my Pastebin?

This isn’t the code from the previous message at the time we were talking, as you can see the LASTFM_USERNAME, XXXXXXXX, and YOUR_ARTIST_NAME fields aren’t filled in the command you have in your chat, plus there is !addcom !download at the front of it.
I can understand the confusion, there were quite a few commands shared during our conversation, I’ll repost your command here so you don’t do the same mistake again.
Copy this in the Message field:

$(eval a=`$(lastfm IksonOfficial "{{artist}}|{{title}}")`.split(`|`); d=`$(urlfetch json https://pastebin.com/raw/K4eyYK2y)`.split(`|`); if(a[0].toLowerCase()==`Ikson`.toLowerCase()){if(d.includes(a[1])){`Download ${a[1]} here: ${d[d.indexOf(a[1])+1]}`}else{`There is no link to download ${a[1]} yet.`}}else{`This song isn't from Ikson.`})

When you update the command, make sure the end of the command isn’t cut in half by editing the command a second time and having a look at the end of the Message field. If it is, check what you copied, it should end with }). If it does and the command in the Message field is still cut in half, this might be due to YouTube characters restrictions… It’s just a guess because YouTube isn’t my field of expertise at all, but in case you confirm this might be it, I think I have a fix.
Let me know how it goes.

I’m sure the command works, at least on Twitch, have a look at my tests:

Hey where do you test that?? :smiley: I’m currently starting up my live stream again and again to test…lol

Trying this rn! Thanks. Will let you know.

Custom command lenght should be similar in nightbot regardless of Streaming destination, or do you mean that because I’m connected to my Youtube channel it detects that and stops me from writing longer messages?