Skip to content

Instantly share code, notes, and snippets.

@anio
Last active June 16, 2023 18:19
Show Gist options
  • Save anio/6cc696ea375e879ba952d2c6b92f43f7 to your computer and use it in GitHub Desktop.
Save anio/6cc696ea375e879ba952d2c6b92f43f7 to your computer and use it in GitHub Desktop.
Youtube RSS feed URL generator

You can have it as a oneliner:

curl -s https://www.youtube.com/@CHANNEL | grep -Po '"canonical" href="https://www.youtube.com/channel/\K.*?(?=">)' | xargs -I@ echo 'https://www.youtube.com/feeds/videos.xml?channel_id=@'

Or as a bash function

youtube-rss-generator () {
    CHANNEL_URL="$1"

    if [[ -n "$CHANNEL_URL" ]]; then

        curl -s "$CHANNEL_URL" | \
            grep -Po '<link rel="canonical" href="https://www.youtube.com/channel/\K.*?(?=">)' | \
            xargs -I@ echo 'https://www.youtube.com/feeds/videos.xml?channel_id=@'
    else

        echo "Usage: youtube-rss-generator https://www.youtube.com/path/to/channel"

    fi
}

or as a command:

curl -s 'https://gist.githubusercontent.com/anio/6cc696ea375e879ba952d2c6b92f43f7/raw/b5d96349bbb9df7adb69315955b0b35f1284ee3a/youtube-rss-generator.sh' -o youtube-rss-generator.sh
chmod +x youtube-rss-generator.sh
sudo cp youtube-rss-generator.sh /usr/bin/youtube-rss-generator
#!/usr/bin/bash
youtube-rss-generator () {
CHANNEL_URL="$1"
if [[ -n "$CHANNEL_URL" ]]; then
curl -s "$CHANNEL_URL" | \
grep -Po '<link rel="canonical" href="https://www.youtube.com/channel/\K.*?(?=">)' | \
xargs -I@ echo 'https://www.youtube.com/feeds/videos.xml?channel_id=@'
else
echo "Usage: youtube-rss-generator https://www.youtube.com/path/to/channel"
fi
}
(
[[ -n $ZSH_VERSION && $ZSH_EVAL_CONTEXT =~ :file$ ]] ||
[[ -n $BASH_VERSION ]] && (return 0 2>/dev/null)
) && sourced=1 || sourced=0
if [[ $sourced -eq 0 ]]; then
youtube-rss-generator "$1"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment