Entrepreneur, WordPress Enthusiast & Digital Marketing Strategist

Building a Twitch TrackID integration

A lot of people were really happy with my last post explaining how to set up a Twitch Team greeting bot so I’m back with another guide on setting up a TrackID bot for the current and previous Track being played. This one has some caveats as everyone has a different DJ setup so what I’ve got working for me here won’t necessarily work for you. Some things can be subbed out with other options but you may need to get fiddley to achieve it.

Let’s start with a quick overview of the tools this solution is using:

  • Now Playing – This grabs our actively playing track from Rekordbox, Pioneer DJ (via link) & Tracktor and allows you to display that info on screen along with saving that track information to a text file. In my use case I’m not outputting the track info on stream as I prefer the track ID tool as it gives some feedback on when viewers really dig a tune and want to know what it is.

    The developer behind Now Playing does have plans to add support for Denon Engine and Virtual DJ in the near future as well as potentially building his own twitch bot which should be simpler to integrate than this guide so if this guide goes over your head, don’t fret, you may have alternative options popping up sooner rather than later
  • Streamer.Bot – This is a really powerful and customizable Twitch Bot tool that’s not too difficult to get the hang off but has an incredibly high ceiling of potential functions with it’s wide range of software integrations and the ability to add in your own custom C# code to power custom funcitons. This is what’s going to take the text file of songs we’ve played from Now Playing and send the correct Track ID through to your Twitch Chat.

Now Playing Setup

There’s not too much to configure on the Now Playing side, just install the application, open it and connect to your DJ system of choice. Even if you don’t use the overlay you will still need to add the overlay URL to OBS to trigger Now Playing to start working. For me, I just have it as a hidden layer in OBS and hit the Refresh button before each stream after opening the Now Playing app to refresh the connection

In the Now Playing Settings you’ll need to ensure the “Save Tracklist” option is checked and take note of the directory as you’ll need that later when setting up Streamer.Bot. There are some additional options to hide certain Track IDs or parts of a track name that can be useful as well.

Streamer.Bot Setup

There’s a bit of setup required for Streamer.bot to connect all your accounts/applications so I won’t go over everything here. The Streamer.Bot Wiki has a bunch of information and Nutty has a great setup video that goes over the basics. For this guide all you need to connect is your broadcaster Twitch account & your Twitch Bot account (optional, if you want the track ID messages posted by your bot instead of by yourself) which can be done from the Settings -> Twitch Accounts screen. I’d also recommend setting up the OBS Websockets integration under the OBS tab as that unlocks a lot of fun tools such as connecting Twitch Channel Points through to triggering actions in OBS

With that done we need to get a quick understanding of how things flow through Streamer.Bot. Actions are the main “doing” step where you create one or many “sub-actions” to send messages to chat, change scenes/layers/filters in OBS and run other code. Then everything else (Channel Point Rewards, Commands, Voice Control, Hot Keys & Events) are all different ways to trigger those actions.

For our use case we need the following:

  • An action to get the current track ID from the Now Playing text file and post it to chat
  • An action to get the previous track ID from Now Playing text file and post it to chat
  • A command to trigger the current track Action when someone types !trackid
  • A command to trigger the previous track Action when someone types !previousid

Track ID Actions

We start with the actions first as we can’t connect our commands to an action that doesn’t exist yet. Start by right clicking in the Actions menu and creating a Track ID Action. You don’t need a group value for now but it can be handy to add later if you start adding lots of actions in Streamer.Bot

Now in the Sub-Actions window we need to add the commands to get our track ID from Now Playing and then send it to Twitch Chat. Start by right-clicking in Sub-Actions and going Add Action -> C# -> Execute C# Code. In the code window you’ll want to paste the following, replacing the directory on line 11 with the correct directory for your Now Playing Tracklists

using System;
using System.IO;
using System.Text.RegularExpressions;

public class CPHInline
{
    public bool Execute()
    {
        // your main code goes here
        string todaydate = DateTime.Today.ToString("yyyy-MM-dd");
        string trackpath = @"C:\Users\grant\OneDrive\Documents\OBS_Assets\";
        string searchstring = todaydate + "*";
        string[] trackfiles = Directory.GetFiles(trackpath, searchstring);
        string tracklistfilename = "";
        foreach (var item in trackfiles)
        {
            tracklistfilename = item;
        }

        CPH.SetArgument("tracklistfilename", tracklistfilename);
        string[] tracklist = File.ReadAllLines(tracklistfilename); //list of 
        int trackcount = tracklist.Length;
        int currenttrack = trackcount - 1;
        int previoustrack = trackcount - 2;
        string trackname = tracklist[currenttrack];
        string prevtrackname = tracklist[previoustrack];


	string pattern = @"\d*\. ";
	string replacement = "";
	Regex r = new Regex(pattern);
        trackname = r.Replace(trackname, replacement);
	prevtrackname = r.Replace(prevtrackname, replacement);


	pattern = @" \[.*\]";
	Regex r2 = new Regex(pattern);
		
        trackname = r2.Replace(trackname, replacement);
	prevtrackname = r2.Replace(prevtrackname, replacement);



        CPH.SetArgument("trackid", trackname);
        CPH.SetArgument("previoustrackid", prevtrackname);

        return true;
    }
}


This code uses the current date to find the correct text file in the Now Playing folder, then reads the file and grabs the last and second last line of the file (our now playing and previous track names). It then filters out the track number to leave just the Artist – Title text and lastly saves the two values into a variable we can use elsewhere in Streamer.Bot

Next we add another sub-action using Add Action -> Twitch -> Send Message to Channel and pass it the variable from our other sub-action:

With that our track ID action is complete and now we just need a way to trigger it. You can copy these steps again for the Previous Track ID, replacing the %trackid% variable and message for the %previoustrackid% variable (ex. Previous Song – %previoustrackid%) or use the import option below

Import Option

Streamer.Bot also has an import option to copy in actions quickly. To take this approach you can copy the code below and right-click in Actions -> Import and paste the text. This will give you the Track ID Action with both sub-actions (You’ll still need to edit the C# code to specify the correct folder) which you can then duplicate and change the message variable for the previous ID Action

TlM0RR+LCAAAAAAABACtV1tv4sgSfl/p/Ico0r4tkS+QjFfaB3DAmBAmmBgbH+bB3W1sh/ZlsA2Y0f73rW7jBEyY1Z6zkSyHrq7qr766tOvHf365ubndepssTOLb32/E3/hC7EYe/Lp93bh4rT/eVqsuzmFXBoL/st83Nz+qF4hCwravVq4re+ihJbuy3GpLykNLUdz71goJqzZyieu1HypbXOl74RXsmLig9GPVi11EPWYv3xTex/qnmLjE3yRF+rnIpTu3zIyC+bZyaXZib+PGJIm63KdLKU5iXGw2Xpxfyi54OOOCb8m9PVO8nSS7mxfqlmHs37Rufs0ZwJD8+oGQ70433sqDw0gX46TgRwrnOyp+v8gKEdx7xiryWu3OF7elEA+32itBRveIfJFRp2F654V+wA3eNUzmZcr4FBvLNZlnQakwxMTbM42P1T9/u0ZAHS3Ny3lUaJjlg5B6DXjEy/AmTI8xuG1I156Xdmm49S5iUEWQsebF2GuEggvV35dLCyAnu2y5fA7xJsmSVX436b8ul4MNoNslm/VyuW3fCXeyIIvKchllONnQEN0RSs+R/G/2ZmWWe9HdK+TCneH5BXU3/T3EOmPFlv3LpzBrp8a+nXOFytxTE8JjQuxJiiLsmzI9EG2ef90JT8218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6H+RBLwMd4IflHsfF7UHPgf4lbklkQt4MxAX0UrjLqh5rT9ndVIAvBelyDhsx0X0eB7onNXdHDnz89re8jNTpWc0187R8DjuzGvfTGXc7H9f+Vn2J9xiGr+k7wwlY/h9+6j5YOH2RfScEjmQmDf1oYe0PzuxULznng+Wa1qGk7M0ci1BPDd65BP1qra/siEa3KH4uZhYpEOTzVBrUdkeqKcIdOUl0TeD8jNfV73Nu6r2khD6z0zVep/A9VP3GYra3j7nU5MkpOyYS6/rz0+pbCGzZP4vl7rgWvOChwb+h4NsrRuxeNCcBlsw6NjmPRdiZgN9wX17Goc5xp2RcCYUhj6Av9Q7WYUB+Ft/PcEM/+D7eHfuCMJnO1M4r1NH61ZofsDSIL+pNcwI0nBwxcL8/6rZ/1LeNHo6IWOWIHx5xpI6qZ/plDP5W/6L3SnTN7tHLGj/m1WmPj+YCYXUI5xLLfD9vBTW1mv7xx+WEhpMoZQPMp6MI8WDIm+Xu5nJcrGYnPr8prkCwAAOb94DY1KaglitISuteUrAsCCIWhfY/nd8U9vf5CNccp+oBTjgZ4Op/vzXHW40Z4YPVt9OpmFI3zTxyIq2E3FC1s5rra+GffwEWQowsYxAAAA==

Adding the Commands

Under the Commands tab we need to add commands for our track id bot. Right click and add a new command then set the following options:

  • Location – Exact
  • Commands – “!id” (You could use !trackid or any other command you want to trigger it)
  • Action – Select the Track ID action you created
  • Global Cooldown – Optionally you can set a small cooldown to prevent multiple people from triggering it in quick succession, I’ve set a 10s cooldown
  • Everything else you can leave as defaults

Repeat this again with your “!previousid” command and connect that to the corresponding action

Testing and Final Notes

With that you should be all good to go, with Now Playing & Rekordbox running and Streamer.Bot open and connected to your Twitch accounts you should be able to type you !id command in chat and have it come back with your Track ID

GForce_Bot: Now Playing - Harry Potar - Dark Technology

If the bot comes back with nothing, check the Command trigger in Streamer.Bot is setup and your Twitch account is connected under Settings -> Twitch Accounts. If the bot responds with a message like “Now Playing – %trackid%” then check and make sure the folder in the C# code step is correct as the bot is unable to read the tracklist file.

Again this process is not going to work for everyone as not everyone has a setup compatible with Now Playing. Some other options for track IDs/Overlay tools that you might be able to use and potentially integrate with Streamer.Bot include:

  • Prolink.Tools – This works with Pioneer Gear where you’re playing off USB but have the gear connected to your local network. It also works with Rekordbox connected in Export mode, but requires Prolink.Tools to be running on a different computer to Rekordbox
  • Kuvo-OBS – I haven’t personally tested this one but it allows you to have Rekordbox post your track info to Kuvo which you can then pull down into OBS.

Categories: Uncategorized

Comments

Your email address will not be published. Required fields are marked *