2020-12-20 11:40:05 -06:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-12-20 13:59:30 -06:00
|
|
|
DATFILE="${HOME}/.config/youtube/dat"
|
|
|
|
CACHEDIR="${HOME}/.config/youtube/cache"
|
2020-12-20 11:40:05 -06:00
|
|
|
tmp1=$(mktemp)
|
|
|
|
tmp2=$(mktemp)
|
|
|
|
|
2020-12-20 11:50:47 -06:00
|
|
|
touch $DATFILE
|
2020-12-20 11:40:05 -06:00
|
|
|
mkdir -p $CACHEDIR
|
|
|
|
|
|
|
|
sync () {
|
|
|
|
for i in $(cat $DATFILE | tr '\n' ' '); do
|
2020-12-20 13:59:30 -06:00
|
|
|
torify curl -s \
|
2020-12-20 11:40:05 -06:00
|
|
|
https://www.youtube.com/feeds/videos.xml?channel_id=$i\
|
|
|
|
> ${CACHEDIR}/$i
|
|
|
|
done
|
|
|
|
}
|
|
|
|
display () {
|
|
|
|
for i in $(ls $CACHEDIR | tr '\n' ' '); do
|
|
|
|
grep \<media:title\> ${CACHEDIR}/$i | cut -c 17- | \
|
|
|
|
rev | cut -c 15- | rev >> $tmp1
|
|
|
|
grep 'link rel' ${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
|
|
|
|
}
|
|
|
|
del () { # $1: line number of channel id
|
|
|
|
sed -i "${1}d" $DATFILE
|
|
|
|
}
|
2020-12-20 11:40:05 -06:00
|
|
|
case $1 in
|
|
|
|
*"sync"*)
|
|
|
|
sync
|
|
|
|
;;
|
2020-12-20 11:50:47 -06:00
|
|
|
*"add"*)
|
|
|
|
[ $# -eq 2 ] && add $2
|
|
|
|
;;
|
|
|
|
*"del"*)
|
|
|
|
[ $# -eq 2 ] && del $2
|
|
|
|
;;
|
2020-12-20 11:40:05 -06:00
|
|
|
*)
|
|
|
|
display
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
exit 0
|