From 6d4bc9cceb9a180acb811d409745ce5dd3732e1d Mon Sep 17 00:00:00 2001 From: btkoch Date: Sat, 25 Nov 2023 18:28:00 -0500 Subject: Complete rewrite and rename --- README.md | 31 +++++++++++++++++++++-- UCld68syR8Wi-GY_n4CaoJGA | 35 ++++++++++++++++++++++++++ yt-feed | 13 ---------- ytuh | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 15 deletions(-) create mode 100644 UCld68syR8Wi-GY_n4CaoJGA delete mode 100755 yt-feed create mode 100755 ytuh diff --git a/README.md b/README.md index 804b3ec..36e1e39 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,29 @@ -# yt-feed -Simple bash script that takes a YouTube channel name as input and outputs either the RSS feed URL or, with the `-i` option, the channel ID. +# ytuh +## (YouTube URL Helper) + +A bash script designed to help with handling YouTube URLs + +## Usage +By default, the script takes YouTube channel name (without the @) as input and returns the channel ID. + +``` +$ ytuh jawed +UC4QobU6STFB0P71PMvOGN5A +``` + +The `-r` (reverse) option reverses this behavior: the user inputs a channel ID and the script prints the corresponding channel name. + +``` +$ ytuh UC4QobU6STFB0P71PMvOGN5A +jawed +``` + +The `-f` (feed) option will cause the script to output the RSS feed for the channel provided. + +``` +$ ytuh -f jawed +https://youtube.com/feeds/videos.xml?channel_id=UC4QobU6STFB0P71PMvOGN5A +``` + +It should be noted that `-rf` does work as expected, retrieving a feed URL from a channel ID. +While this may seem useless, and it probably is, I saw no reason why I shouldn't make it work on the off-chance that it might improve someone's workflow, somehow. diff --git a/UCld68syR8Wi-GY_n4CaoJGA b/UCld68syR8Wi-GY_n4CaoJGA new file mode 100644 index 0000000..dbe1450 --- /dev/null +++ b/UCld68syR8Wi-GY_n4CaoJGA @@ -0,0 +1,35 @@ +
AboutPressCopyrightContact usCreatorsAdvertiseDevelopersTermsPrivacyPolicy & SafetyHow YouTube worksTest new featuresNFL Sunday Ticket
Brodie Robertson - YouTube \ No newline at end of file diff --git a/yt-feed b/yt-feed deleted file mode 100755 index 98b19e2..0000000 --- a/yt-feed +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -if [ -z "$1" ]; then - echo "Usage: $0 [-i] " - exit -elif [[ $1 != -i ]]; then - url=$(curl -s "https://validator.w3.org/feed/check.cgi?url=https://youtube.com/@$1" | grep "Validator Results" | sed -n 's/.*Results: \(.*\)<\/title>.*/\1/p') - echo $url -else [ $1 == -i ]; - url=$(curl -s "https://validator.w3.org/feed/check.cgi?url=https://youtube.com/@$2" | grep "Validator Results" | sed -n 's/.*id=\(.*\)<\/title>.*/\1/p') - echo $url -fi - - diff --git a/ytuh b/ytuh new file mode 100755 index 0000000..b2023d1 --- /dev/null +++ b/ytuh @@ -0,0 +1,64 @@ +#!/bin/bash + +usage(){ + echo "Usage: ytuh [-rf] " + echo "options:" + echo " Default: Returns channel ID" + echo "r Reverse: Returns channel name when a channel ID is given (can be used with -f)" + echo "f Feed: Returns RSS feed URL" + exit +} + +# Print usage info if no arguments/options +if [ $# == 0 ]; then + usage +fi + +r="0" +f="0" + +# Get ID from name (still called when -r specified, will clean this up later) +function getId(){ + if [[ $r == "0" ]]; then + id=$(curl -s "https://validator.w3.org/feed/check.cgi?url=https://youtube.com/@$1" | grep "Validator Results" | sed -n 's/.*id=\(.*\)<\/title>.*/\1/p') + fi +} + +# Get name from ID (-r specified) +function reverse() { + name="$(curl -Ls https://youtube.com/channel/$1 | grep "canonicalBaseUrl" | sed 's/.*canonicalBaseUrl":"\/@\([^"]*\)".*/\1/')" +} + +# Get feed url (-f specified) +feed(){ + feedUrl="https://youtube.com/feeds/videos.xml?channel_id=$id" +} + +while getopts 'r:f:' OPTION; do + case "$OPTION" in + r) + r="1" + id="$2" + reverse "$id" + ;; + f) + f="1" + getId "$OPTARG" + feed "$id" + ;; + *) + usage + ;; + esac +done + +if [ $r == "1" ] && [ $f == "0" ]; then + output="$name" +elif [ $r == "0" ] && [ $f == "0" ]; then + getId "$1" + output="$id" +else + output="$feedUrl" +fi + +echo $output -- cgit v1.2.3