Fetching YouTube channel RSS feeds with Python
A bit of irony prompted me to look into RSS feeds from YouTube channels. Consequently, I wrote a quick Python script to fetch and display the feed URL for a given channel. Now I can easily add feed URLs for YouTube channels to my RSS feed reader, thus reducing the number of distracting push notifications and allowing me to say focused longer.

Image credits: Wikimedia Commons
Irony turns up in the strangest of places. I was reading an article by Cory Doctorow recently about how he turns off notifications to avoid distractions. While reading the article on my phone, “Plop!”, I got a notification from YouTube. The notification covered up the text I was reading and, of course, distracted and annoyed me.
The notification did have one positive effect: I wondered if one can get an RSS feed from YouTube. It turns out, yes, you can. Here’s how.
The IDs have it
The trick to getting all this to work is to know what the channel’s ID is.
This is not shown anywhere in the YouTube web app and it’s not that easy to
find. Also, one can’t can’t easily guess the ID because it’s a random
string of characters which uniquely identifies the channel within YouTube.
All one usually sees as a normal YouTube user is the channel handle which is
the channel username prefixed with an @
symbol.
As mentioned in the blog post RSS Feed für YouTube Channels (German), if one knows the channel ID, then the RSS feed is given by this URL:
https://www.youtube.com/feeds/videos.xml?channel_id=CHANNEL_ID
where CHANNEL_ID
is–you guessed it–the channel ID.
Finding a channel ID, the web browser way
But how to find the channel ID? One solution is to use the YouTube Channel ID Finder web service. Here, all one has to do is to enter the channel handle into the web form and it will return the channel ID. For instance, here is the result I got when looking up the Veritasium channel:
I had problems using this page with Firefox, so if you want to be sure
things work, you might have to change to another browser such as Chromium.
Note also that capitalisation doesn’t make a difference to the search. I’d
initially searched for @Veritasium
and still got a result, yet the
channel’s handle is actually all in lowercase: @veritasium
.
Now all you need to do is to take the channel ID that the YouTube Channel ID Finder returns and insert it into the generic URL I mentioned above. Thus, the RSS feed for Veritasium is this link:
https://www.youtube.com/feeds/videos.xml?channel_id=UCHnyfMqiRRG1u-2MsSQLbXA
Nice! You can now plug this URL into your RSS feed reader and thus proactively look for new videos when you choose to. This is better than YouTube pushing notifications at you when you’d rather be reading or doing something else.
Finding a channel ID, programmatically
Now, I’m not a fan of clicking around on web forms for repetitive tasks like this. There’s still a fair bit of work we have to do to get the URL in a form that we can enter into my RSS feed reader. We need to enter the channel’s handle into the YouTube Channel ID Finder form, wait for it to give a result and then create the RSS feed URL by hand. We can streamline this workflow with some serendipity and a bit of Python code.
What do I mean by serendipity? Well, I happened to notice that the HTML headers of YouTube channel home pages contain an RSS link. In other words, if you look at the HTML source for https://www.youtube.com/@veritasium, you’ll find this appear:
<link rel="alternate" type="application/rss+xml" title="RSS" href="https://www.youtube.com/feeds/videos.xml?channel_id=UCHnyfMqiRRG1u-2MsSQLbXA">
Such a link implies that an RSS feed reader should be able to automatically detect the RSS feed from the YouTube channel’s home page URL. However, in the feed readers I tested, they weren’t able to detect this link. Thus we have to extract it ourselves, and that’s where a bit of Python code comes in.
The plan here is to use the requests
library to fetch the content of
the YouTube channel home page of interest and then use the beautifulsoup4
library to extract
the URL of the RSS link that we now know exists in the HTML header.
Assuming that you’ve installed requests
and beautifulsoup4
(say with
pip install
or poetry add
or uv install
), you can whip a quick script
that looks like this:
import requests
from bs4 import BeautifulSoup
channel_name = "veritasium"
url = f"https://www.youtube.com/@{channel_name}"
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
rss_link = soup.find('link', title="RSS")
rss_url = rss_link.get('href')
print(
f"RSS URL for @{channel_name} is:\n"
f"{rss_url}"
)
Saving this to a file called (say) fetch_youtube_rss_feed.py
and running
it gives this output:
$ python fetch_youtube_rss_feed.py
RSS URL for @veritasium is:
https://www.youtube.com/feeds/videos.xml?channel_id=UCHnyfMqiRRG1u-2MsSQLbXA
This is the same result as what we got earlier, but with much less effort on our part and we can simply copy-paste the URL into our RSS feed reader. Cool!
Extending this example a bit further, we could use the argparse
module from the Python
standard library to specify the channel’s name on the command line. This
way we avoid hard-coding the channel name in the script. This is left as an
exercise for the reader.1
Now you can turn off notifications for this channel within YouTube and yet still find out when new videos are posted.
Wrapping up
Don’t let push notifications rob your attention! Take back some control of your mental focus by proactively looking for new videos from your YouTube subscriptions rather than being bombarded with push notifications. A quick Python script fetches a link that you can add to your RSS feed reader. This lets you discover new videos by refreshing RSS subscriptions on your schedule.
-
Or just grab the code from the GitHub repo. ↩
Support
If you liked this post and want to see more like this, please buy me a coffee!
