2020-12-20 11:40:05 -06:00
|
|
|
#!/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:40:05 -06:00
|
|
|
|
2020-12-20 11:50:47 -06:00
|
|
|
touch $DATFILE
|
2020-12-20 11:40:05 -06:00
|
|
|
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
|
|
|
|
"
|
|
|
|
}
|
2020-12-20 11:40:05 -06:00
|
|
|
sync () {
|
2021-02-16 10:31:48 -06:00
|
|
|
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
|
2020-12-20 11:40:05 -06:00
|
|
|
}
|
|
|
|
display () {
|
2021-02-16 10:31:48 -06:00
|
|
|
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:40:05 -06:00
|
|
|
}
|
2020-12-20 11:50:47 -06:00
|
|
|
add () { # $1: name of channel id
|
2021-02-16 10:31:48 -06:00
|
|
|
printf "%s\n" $1 >> $DATFILE
|
2020-12-20 11:50:47 -06:00
|
|
|
}
|
|
|
|
del () { # $1: line number of channel id
|
2021-02-16 10:31:48 -06:00
|
|
|
sed -i "${1}d" $DATFILE
|
2020-12-20 11:50:47 -06:00
|
|
|
}
|
2020-12-20 11:40:05 -06:00
|
|
|
case $1 in
|
2021-02-16 10:31:48 -06:00
|
|
|
*"s"*)
|
|
|
|
sync
|
|
|
|
;;
|
|
|
|
*"a"*)
|
|
|
|
[ $# -eq 2 ] && add $2
|
|
|
|
;;
|
|
|
|
*"d"*)
|
|
|
|
[ $# -eq 2 ] && del $2
|
|
|
|
;;
|
|
|
|
*"h"*)
|
|
|
|
info
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
display
|
|
|
|
;;
|
2020-12-20 11:40:05 -06:00
|
|
|
esac
|
|
|
|
exit 0
|