From a2ae9d1ae84cb708fe43863c330e477e360ad0b3 Mon Sep 17 00:00:00 2001 From: dtb Date: Mon, 7 Nov 2022 01:42:33 -0500 Subject: [PATCH] fix weirder arg stuff, make a bit faster --- rss/youtube | 73 ++++++++++++++++++++++------------------------------- 1 file changed, 30 insertions(+), 43 deletions(-) diff --git a/rss/youtube b/rss/youtube index 6c5e078..ebbc6b2 100755 --- a/rss/youtube +++ b/rss/youtube @@ -6,14 +6,11 @@ argv0="$0" PIGPEN="$(pig_pen)" -id(){ - youtube-dl --skip-download --print-json --playlist-items 1 "$1" \ - | jq '.channel_id' \ - | tr -d '"' -} - -feedurl(){ - printf "http://www.youtube.com/feeds/videos.xml?channel_id=%b\n" "$1" +latin(){ + case "$1" in + *json) jq '.feed.pig' <"$1" ;; + *xml) xq '.feed.pig' <"$1" ;; + esac } list_channels(){ @@ -35,16 +32,13 @@ list_channels(){ } list_videos(){ - file="$( \ - ls "$PIGPEN" \ - | grep "$( \ - list_channels \ - | sed "/$(printf '%b' "$1")/q" \ - | tail -n 1 \ - | cut -f 1 \ - | xargs pig_name - )" \ - )" + file="$(printf "$PIGPEN"/$( \ + list_channels \ + | sed "/$1/q" \ + | tail -n 1 \ + | cut -f 1 \ + | xargs pig_name \ + )*)" case "$file" in *json) jq \ @@ -69,14 +63,9 @@ list_videos(){ -e '$d' \ -e 's/\": \"/ /g' \ -e 's/^ \"//g' \ - -e 's/\"\,$//g' # this is really hacky -} + -e 's/\,$//g' \ + -e 's/\"$//g' # this is really hacky -latin(){ - case "$1" in - json) jq '.feed.pig' <"$1" ;; - xml) xq '.feed.pig' <"$1" ;; - esac } stow(){ @@ -109,12 +98,12 @@ usage(){ printf "\ Usage: %s list_channels - list_videos [channel name...] + list_videos [channel name] listen [video URL] refresh (channel name...) subscribe [channel URL...] - watch [video URL...] - watch_latest [channel name...] + watch [video URL] + watch_latest [channel name] " "$argv0" 1>&2 } @@ -125,12 +114,7 @@ list_channels) list_channels ;; list_videos) # do something with youtube-dl? - str isvalue "$2" \ - || usage - while str isvalue "$2" - do list_videos "$2" - shift - done + list_videos "$2" ;; listen) str isvalue "$2" \ @@ -166,7 +150,13 @@ subscribe) str isvalue "$2" \ || usage while str isvalue "$2" - do stow "http://www.youtube.com/feeds/videos.xml?channel_id=$(id "$2")" + do stow "http://www.youtube.com/feeds/videos.xml?channel_id=$( + youtube-dl \ + --get-filename \ + --playlist-items 1 \ + -o '%(channel_id)s' \ + "$2" \ + )" shift done ;; @@ -180,14 +170,11 @@ watch) # needs work watch_latest) str isvalue "$2" \ || usage - while str isvalue "$2" - do watch "$( \ - list_videos "$2" \ - | head -n 1 \ - | cut -f 1 \ - )" - shift - done + watch "$( \ + list_videos "$2" \ + | head -n 1 \ + | cut -f 1 \ + )" ;; *) usage ;; esac