1
0
Fork 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
1 changed files with 30 additions and 43 deletions

View File

@ -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