Return to Blog Home

Twitch User-Markers to YouTube Timestamps

 

Twitch User-Markers to YouTube Timestamps

Why write YouTube comment messages yourself when automation exists?

What prompted this was someone pointing out that I had forgotten to add the Break/Timer timestamps to my messages, and could not for the life of me remember which ones I had forgotten, so off to generate a YouTube-comment generating script I went!

Now I already had quite a bit of code managing my #100Devs Asset Manager CLI, and decided to create a 2nd script in the same project so I could reuse most of my existing functions.

So after filtering down my SecondsMap down to just the markers that go into the YouTube comments - slides and break/timer start/ends - all I needed to do was prefix each line with the HH:MM:SS timestamp, and tack on my copy-and-paste preamble before the actual timestamps.

All that was missing was the automatic syncing of my comments to these generated text comments...which was not something I was interested in doing just yet, though if I had to do another mass-edit I might consider it.

Basic Numbers

While I was in the codebase, I decided to prefix the class slugs - which were currently YYYY-MM-DD - with a short piece of text indication the type of class, and the number of that - so when reading one could discern that it was the nth Class for example.

Thankfully it was quite easy to tack on a number field to my ClassInfo type, and assign them while counting them in order, making my slugs now look like T-00 YYYY-MM-DD, for example C-01 2022-01-11.

Videos

As the #100Devs office hours are not reuploaded to YouTube, this means after they're gone from Twitch, they're gone forever! In order to avoid this loss, I've download them with yt-dlp, which means this is yet another asset - though for only a third of the streams - that I'd need to keep track of. Thankfully there's no need to actually process or parse the videos themselves - not yet at least - so only the existence of a .mp4 within the directory would satisfy my check.

Offsets

One of the #100Devs videos reuploaded to YouTube had it's intro shortened, which was great for YouTube, not so great for my recently created script. Fortunately it was easy enough to fix, of which the first step was to manually determine how many seconds all the timestamps need to be negatively offset. After that manual math, I added another inquirer question to ask for the offset, and eventually passed that to my generateYoutubeComment() function, and my work was done!