How would I run a workflow when a new video has been uploaded to a YT channel?

Hi, Im using n8n desktop & would like to be able to send out automated messages to various social media accounts every time I upload a new video to YT or start a live stream.

So far Ive managed to get my published videos using the YouTube node:

Im guessing a solution would be to get all videos and then filter out videos uploaded after the last time the flow as run and then run the rest of the code once for every video that was found (which in my case would be send a few social media messages), but Im not really sure how to do that :sweat_smile:.

Any hints would be highly appreciated If its possible to create flows in 100% JavaScript and not use the UI at all, I would also be curious to see how that would look & would probably prefer that over something using the desktop UI

Hey @officernickwilde, welcome to the community!

Two approaches I can think of would be:

  • Implement a polling logic. In other words, store the Ids of the already processed videos in a database/Google Sheet etc., then run the workflow every 5 minutes fetching all videos and filter out those that have already been processed. This should be fairly resilient.
  • A simpler approach would be to simply run your workflow every 5 minutes and then search for videos published after whatever time it was 5 minutes ago. To achieve this you’d need an interval node (to have the workflow run every 5 minutes) and then set the published after value from your screenshot to an expression like {{ new Date(new Date().getTime() - 5 * 60 * 1000) }}. This example expression uses JavaScript’s new Date() to calculate the timestamp from 5 minutes ago.

Hope this helps! Give me a shout if you run into trouble with these suggestions