1
0

fix weirder arg stuff, make a bit faster

This commit is contained in:
dtb 2022-11-07 01:42:33 -05:00
parent bfee05b744
commit a2ae9d1ae8

View File

@ -6,14 +6,11 @@ argv0="$0"
PIGPEN="$(pig_pen)" PIGPEN="$(pig_pen)"
id(){ latin(){
youtube-dl --skip-download --print-json --playlist-items 1 "$1" \ case "$1" in
| jq '.channel_id' \ *json) jq '.feed.pig' <"$1" ;;
| tr -d '"' *xml) xq '.feed.pig' <"$1" ;;
} esac
feedurl(){
printf "http://www.youtube.com/feeds/videos.xml?channel_id=%b\n" "$1"
} }
list_channels(){ list_channels(){
@ -35,16 +32,13 @@ list_channels(){
} }
list_videos(){ list_videos(){
file="$( \ file="$(printf "$PIGPEN"/$( \
ls "$PIGPEN" \ list_channels \
| grep "$( \ | sed "/$1/q" \
list_channels \ | tail -n 1 \
| sed "/$(printf '%b' "$1")/q" \ | cut -f 1 \
| tail -n 1 \ | xargs pig_name \
| cut -f 1 \ )*)"
| xargs pig_name
)" \
)"
case "$file" in case "$file" in
*json) *json)
jq \ jq \
@ -69,14 +63,9 @@ list_videos(){
-e '$d' \ -e '$d' \
-e 's/\": \"/ /g' \ -e 's/\": \"/ /g' \
-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(){ stow(){
@ -109,12 +98,12 @@ usage(){
printf "\ printf "\
Usage: %s Usage: %s
list_channels list_channels
list_videos [channel name...] list_videos [channel name]
listen [video URL] listen [video URL]
refresh (channel name...) refresh (channel name...)
subscribe [channel URL...] subscribe [channel URL...]
watch [video URL...] watch [video URL]
watch_latest [channel name...] watch_latest [channel name]
" "$argv0" 1>&2 " "$argv0" 1>&2
} }
@ -125,12 +114,7 @@ list_channels)
list_channels list_channels
;; ;;
list_videos) # do something with youtube-dl? list_videos) # do something with youtube-dl?
str isvalue "$2" \ list_videos "$2"
|| usage
while str isvalue "$2"
do list_videos "$2"
shift
done
;; ;;
listen) listen)
str isvalue "$2" \ str isvalue "$2" \
@ -166,7 +150,13 @@ subscribe)
str isvalue "$2" \ str isvalue "$2" \
|| usage || usage
while str isvalue "$2" 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 shift
done done
;; ;;
@ -180,14 +170,11 @@ watch) # needs work
watch_latest) watch_latest)
str isvalue "$2" \ str isvalue "$2" \
|| usage || usage
while str isvalue "$2" watch "$( \
do watch "$( \ list_videos "$2" \
list_videos "$2" \ | head -n 1 \
| head -n 1 \ | cut -f 1 \
| cut -f 1 \ )"
)"
shift
done
;; ;;
*) usage ;; *) usage ;;
esac esac