Last active
July 4, 2024 23:16
-
-
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 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 | |
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 | |
# 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