Edit – February 22nd 2016: If you’re getting the invalid variable error, please take a look at the command edit for Nightbot beta before you comment.
Nightbot – Song Request by Search
Nightbot’s song request/AutoDJ allows you to request YouTube songs (and Soundcloud, but YouTube is the most common one) while the streamer uses those requests and plays them during the stream. However, Moobot’s song request functions also allows you to request using a search query (e.g. by searching for the video title). This is a feature I missed with Nightbot, so I setup a little “tool” that allows you request songs (video ID’s/links work too, but currently not properly tested) by using a search query.
The search query basically does a normal YouTube search and then it picks the first video after relevance (and thus popularity).
The usage of the command utilizes the alias, customapi and query chat variables of Nightbot. Which means it basically uses the query after the command (what the viewer says), puts that into the custom API GET link of my “tool”. The tool returns the video ID when passed a valid search query, this video ID is used by Nightbot together with !songrequest. This will request the song in the viewers name, and song requests are still limited to 2 songs per viewer at a time.
Update July 1st 2015: A recent change in Nightbot means that the $(query) variable replaces links with the username of who used the command. This means that you can’t use direct YouTube links or else it will request the wrong song. If you wish to use a specific video, only use the video ID or stick to only using search.
How to use: Create a command using the normal way (this cannot be “!songrequest” or else it overrides the original command and it won’t work), and put this into the “response”: $(alias !songrequest $(customapi https://decapi.me/youtube/videoid?search=$(query)))
How viewers will use this: Let’s say you created a command called “!sq”, the viewers will basically just say “!sq search query”, obviously replacing “search query” with the video/song title or whatever. It should automatically request the first video/song that the YouTube search API returns, which is sorted by relevance/popularity.
Please keep in mind this may have issues as it isn’t fully tested in all “environments” and should be treated as “experimental”. If only valid search queries and YouTube video links/IDs are used, then there are things is place to detect that. However, they might not work due to several reasons. Feel free to report with information regarding this.
Important note: Nightbot waits a bit (5 seconds) before it sends a song request through, but there’s also a ~1-2 second delay (usually less) for the data (video ID) to be passed to Nightbot. This means that it takes a few seconds before the command goes through.
Not only that, but custom commands have a cooldown between uses and that unfortunately affects this tool. However, it is possible to create multiple commands with the same response and that should help if the viewers use all of them.
Update December 26th 2015: The new Nightbot beta already has a similar built-in function directly in the !songrequest command. If you still wish to use this for some reason, then you will have to modify your command a bit. After the command name (for example: !sq), you have to put:
-a=!songrequest $(urlfetch https://decapi.me/youtube/videoid?search=$(querystring))
Adding an example command would look something like this:
!commands add !examplesq -a=!songrequest $(urlfetch https://decapi.me/youtube/videoid?search=$(querystring))
Update February 4th 2016: Ankhbot has a new feature part of version 18.104.22.168 (and newer) called “Localization”. This means you can modify how the song request command works in Ankhbot, and utilize this custom API.
What you have to do, is the following: In the main Ankhbot window, click on “Extra” in the top-right, then “Localization”.
A new window should pop up. Click on “Song Request” to the left and scroll all the way to the bottom. Replace whatever is under the SongRequest Functionality box, and put this instead:
It should now look something like this:
Close the window to save your settings.