dot_testing/scripts/yt

67 lines
1.3 KiB
Plaintext
Raw Normal View History

#!/bin/sh
2021-02-15 12:02:09 -06:00
[ -z "${YT_DATFILE}" ] && YT_DATFILE="${HOME}/.local/share/ytdat"
[ -z "${YT_CACHEDIR}" ] && YT_CACHEDIR="${HOME}/.local/share/ytcache"
ver=0.1
2020-12-20 11:50:47 -06:00
touch $DATFILE
mkdir -p $CACHEDIR
2021-02-15 12:02:09 -06:00
info () {
printf %s "\
yt - youtube tool
=> [s]ync - Sync RSS feeds
=> [a]dd [id] - Add a channel to the list
=> [d]el [id] - Remove a channel from the list
=> [h]elp - Show this help
List file: export DATFILE=<your file here>
Cache directory: export CACHEDIR=<your dir here>
see yt(1) for more information on usage
"
}
sync () {
for i in $(cat $YT_DATFILE | tr '\n' ' '); do
torify curl -s \
https://www.youtube.com/feeds/videos.xml?channel_id=$i\
> ${YT_CACHEDIR}/$i
done
}
display () {
tmp1=$(mktemp)
tmp2=$(mktemp)
for i in $(ls $YT_CACHEDIR | tr '\n' ' '); do
grep \<media:title\> ${YT_CACHEDIR}/$i | cut -c 17- | \
rev | cut -c 15- | rev >> $tmp1
grep 'link rel' ${YT_CACHEDIR}/$i | grep 'watch' | \
cut -c31- | rev | cut -c4- | rev >> $tmp2
done
cat $tmp1 $tmp2 | pr -2t -s" | "
}
2020-12-20 11:50:47 -06:00
add () { # $1: name of channel id
printf "%s\n" $1 >> $DATFILE
2020-12-20 11:50:47 -06:00
}
del () { # $1: line number of channel id
sed -i "${1}d" $DATFILE
2020-12-20 11:50:47 -06:00
}
case $1 in
*"s"*)
sync
;;
*"a"*)
[ $# -eq 2 ] && add $2
;;
*"d"*)
[ $# -eq 2 ] && del $2
;;
*"h"*)
info
;;
*)
display
;;
esac
exit 0