Skip to content

BryanCuneo/yt-to-discord

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

yt-to-discord

Utilize Discord's webhooks to receive new video notifications via YouTube's PubSubHubbub push notifications.

How It Works

YouTube offers push notifications in the form of a PubSubHubbub server-to-server interface, though the documentation is fairly lacking. This small Flask server implements the required callback URL on the /feed route and parses out the URL for the video in the notification. An unfortunate limitation is that a push notification is sent out for both a new video upload and an edit to the description/title of an existing video. The XML content seems to be the same for each type of notification, so there's no easy way to differentiate.

The other half of the equation is Discord's webhooks. Once this server receives a push notification from YouTube and parses out the video URL, a message containing that URL is sent to a webhook to be posted in the associated Discord text channel.

How to Use

Step One - The Normal Stuff:

Clone the repo, make a virtual environment, and install the dependencies. Ex:

git clone https://github.com/BryanCuneo/yt-to-discord.git
cd yt-to-discord
python3 -m venv venv
pip install -r .\requirements.txt

Step Two - Update config.yaml:

webhook_url: Once you create a webhook (see the 'Making a Webhook' section here), you'll see a button labeled 'Copy Webhook URL.'

Picture of the 'Copy Webhook URL' button

Click that and paste the resulting link here in config.yaml.

channel_ids[]: A comma sparated list of channel IDs from which your server should accept notifications. If left as an empty list, [], it will accept notifications from any channel.

message_prefix: A string to be included in the message with the video URL.

Step Three - Serve the Server

For easy testing purposes, you can run the Flask dev server on your local machine then expose it to the web with something like ngrok. Ex:

flask run --host=0.0.0.0

Then in another terminal:

ngrok http 5000

You'll get something like the following. Copy the first forwarding URL for step four.

ngrok startup

Step Four - Subscribe

Navigate to the Google PubSubHubbub subscription page:

YouTube push notification subscription interface

In the 'Subscribe/Unsibscribe' mode, fill out the first four boxes:

  • Callback URL - the URL you copied in step 3, followed by /feed. Ex: http://1829c24236ed.ngrok.io/feed
  • Topic URL - https://www.youtube.com/xml/feeds/videos.xml?channel_id=CHANNEL_ID where CHANNEL_ID is the YouTube channel ID for the channel you'd like to subscribe to.
  • Verify type - Asynchronous
  • Mode - Subscribe Press the 'Do It!' button. Within a few minutes, you should see a GET request to /feed on your ngrok interface and a response code of 200.

ngrok subscription confirmation request

Step Five - Waiting and Beyond

From here, you'll have to wait until there is activity on the channel you subscribed to. For testing purposes you can simply subscribe to your own personal YouTube channel and upload a short video. You can then edit the description repeatedly every time you wish to generate a new notification. Each notification should show up as a POST to /feed with a response code of 204.

ngrok push notification received

Once you're satisfied with the functionality you'll want a proper hosting solution rather than Flask's dev server. There are infinite possibilities here including some free options.

About

Utilize Discord's webhooks to receive new video notifications via YouTube's PubSubHubbub push notifications.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages