Last active
March 21, 2025 14:09
-
-
Save henri/818fab7f983db7ead8e602bd109cad7f to your computer and use it in GitHub Desktop.
From a Youtube user / channel URL find the RSS feed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# About : This script allows you to pass in the URL to a youtube users page as argument one and | |
# this script will output the RSS feed for the channel / user (simiilar to notifications) | |
# | |
# Copyright Henri Shustak 2024 | |
# Licence : GNUGLP 3 later | |
# https://www.gnu.org/licenses/gpl.html | |
# | |
# | |
# version 1.0 - inital implimentation - you can retrive rss feeds by user name or channel id | |
# version 1.1 - added support for playlists - now you can retrive rss feeds for a playlist | |
# version 1.2 - added support for finding a user (with just @username as the passed in argument) | |
if [[ $# -ne 1 ]] ; then | |
echo "" | |
echo " usage : ./yt-rss.bash <youtube-username>" | |
echo " : ./yt-rss.bash <youtube-url-to-users-page>" | |
echo " : ./yt-rss.bash <youtube-url-to-playlist>" | |
echo "" | |
echo " example : ./yt-rss.bash \"https://www.youtube.com/@tested\"" | |
echo "" | |
fi | |
list_mode=false | |
CHANNEL_URL="${1}" | |
if [[ $(echo "${CHANNEL_URL}" | grep "list=" > /dev/null ; echo $?) == 0 ]] ; then | |
# find the list | |
CHANNEL_URL=$(echo "${CHANNEL_URL}" | awk -F "list=" '{print$2}') | |
list_mode=true | |
elif [[ $(echo "${CHANNEL_URL}" | grep "@" > /dev/null ; echo $?) == 0 ]] ; then | |
# the channel URL contains an @ symbol so we are going to try to find the channel ID rather than the username | |
if [[ $(echo "${CHANNEL_URL}" | egrep "^@" > /dev/null ; echo $?) == 0 ]] ; then | |
# we have been passed a username (without the http and youtube stuff at the start) so add it on and continue processing | |
CHANNEL_URL="http://youtube.com/${CHANNEL_URL}" | |
fi | |
# find the channel ID rather than the username | |
CHANNEL_URL=$(curl -L "${CHANNEL_URL}" 2>/dev/null| grep '"externalId":"' | awk -F '"externalId":"' '{print $2}' | awk -F '"' '{print $1}') | |
elif [[ $(echo "${CHANNEL_URL}" | grep "youtube.com/channel/" > /dev/null ; echo $?) == 0 ]] ; then | |
# extract the channel ID from the URL | |
CHANNEL_URL=$(echo "${CHANNEL_URL}" | awk -F "youtube.com/channel/" '{print$2}') | |
fi | |
if [[ "${CHANNEL_URL}" == "" ]] ; then | |
echo "ERROR! : Unable to extract the RSS Feed" | |
exit -1 | |
fi | |
if [[ "${list_mode}" == "true" ]] ; then | |
# return playlist rss url | |
echo "https://www.youtube.com/feeds/videos.xml?playlist_id=${CHANNEL_URL}" | |
else | |
# return channel id rss url | |
echo "https://www.youtube.com/feeds/videos.xml?channel_id=${CHANNEL_URL}" | |
fi | |
exit 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment