1
0
This commit is contained in:
dtb 2022-11-03 20:02:49 -04:00
parent 0405a96e74
commit 00821b83ab

View File

@ -2,6 +2,8 @@
set -e set -e
argv0="$0"
id(){ id(){
youtube-dl --skip-download --print-json --playlist-items 1 "$1" \ youtube-dl --skip-download --print-json --playlist-items 1 "$1" \
| jq '.channel_id' \ | jq '.channel_id' \
@ -9,15 +11,85 @@ id(){
} }
feedurl(){ feedurl(){
printf "https://www.youtube.com/feeds/videos.xml?channel_id=%b" "$1" printf "https://www.youtube.com/feeds/videos.xml?channel_id=%b\n" "$1"
}
list_channels(){
for file in "$(pig_pen)"/*
do printf "%s\t%s\n" "$(xq '.feed.title' <"$file")" "$file"
done
}
usage(){
printf "\
Usage: %s
list_channels
list_videos [channel name]
listen [video URL]
refresh (channel name...)
subscribe [channel URL]
watch [video URL]
" "$argv0" 1>&2
} }
case "$1" in case "$1" in
subscribe) list_channels)
pig_stow "$(feedurl "$(id "$2")")" ! str isvalue "$2" \
|| usage
list_channels | sort
;;
list_videos) # do something with youtube-dl?
str isvalue "$2" \
|| usage
list_channels \
| grep "$2" \
| cut -f 2 \
| xargs xq \
'reduce .feed.entry[] as $item (
{};
. + { ($item.link."@href"): $item.title }
)'
;;
listen)
str isvalue "$2" \
|| usage
while str isvalue "$2"
do youtube-dl "$2" -f bestaudio -o - \
| mpv -
shift
done
;; ;;
refresh) refresh)
pig_feed if ! str isvalue "$2"
then pig_feed # does this in bulk
else
while str isvalue "$2"
do list_channels \
| grep "$2" \
| cut -f 2 \
| xargs pig_latin \
| jq '.feed_url' \
| xargs pig_stow
shift
done
fi
;;
subscribe)
str isvalue "$2" && ! str isvalue "$3" \
|| usage
pig_stow "$(feedurl "$(id "$2")")"
;;
watch) # needs work
str isvalue "$2" \
|| usage
while str isvalue "$2"
do youtube-dl "$2" -f 18 -o - \
| mpv -
shift
done
;;
*)
usage
;; ;;
esac esac