remove yt and add trss-yt-id

This commit is contained in:
randomuser 2022-07-18 22:07:17 -05:00
parent 62eec5e9ab
commit 6ed0ede26d
3 changed files with 9 additions and 103 deletions

View File

@ -12,6 +12,7 @@ sh:
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -f sh/paste $(DESTDIR)$(PREFIX)/bin
cp -f sh/trss $(DESTDIR)$(PREFIX)/bin
cp -f sh/trss-yt-id $(DESTDIR)$(PREFIX)/bin
cp -f sh/disp $(DESTDIR)$(PREFIX)/bin
cp -f sh/wallpaper $(DESTDIR)$(PREFIX)/bin
cp -f sh/yt $(DESTDIR)$(PREFIX)/bin

8
sh/trss-yt-id Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
[ -z "$1" ] && exit 1
curl "${1}" -s | \
grep 'youtube/www\.youtube\.com/channel/.\{24\}' -o | \
awk -F'/' '{print "https://www.youtube.com/feeds/videos.xml?channel_id=" $NF}' | \
sed 1q

103
sh/yt
View File

@ -1,103 +0,0 @@
#!/bin/sh
[ -z "${YT_DATFILE}" ] && YT_DATFILE="${HOME}/.local/share/ytdat"
[ -z "${YT_CACHEDIR}" ] && YT_CACHEDIR="${HOME}/.local/share/ytcache"
[ -z "${YT_TORIFY}" ] && YT_TORIFY=""
ver=0.1
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
=> [i]d [url] - Show internal channel id
=> [c]lear - Clear cache
List file: export YT_DATFILE=<your file here>
Cache directory: export YT_CACHEDIR=<your dir here>
Torify wrapper: export YT_TORIFY=<your torify here>
"
}
cache () {
touch ${YT_DATFILE}
mkdir -p ${YT_CACHEDIR}
}
err () {
printf "err: %s\n" ${1}
[ -z "${2}" ] && exit 1
exit ${2}
}
sync () {
cache
for i in $(cat $YT_DATFILE | tr '\n' ' '); do
${YT_TORIFY} curl -s \
https://www.youtube.com/feeds/videos.xml?channel_id=$i\
> ${YT_CACHEDIR}/$i
done
}
id () {
${YT_TORIFY} curl "${1}" -s | \
grep 'youtube/www\.youtube\.com/channel/.\{24\}' -o | \
awk -F'/' '{print $NF}' | \
sed 1q
}
display () {
cache
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" | "
}
add () { # $1: name of channel id
cache
printf "%s\n" $1 >> ${YT_DATFILE}
}
del () { # $1: line number of channel id
cache
sed -i "${1}d" ${YT_DATFILE}
}
cclear () {
rm -r ${YT_CACHEDIR}
}
case $1 in
"s"*)
sync
exit 0
;;
"a"*)
[ $# -eq 2 ] && add $2 || \
err "two args required"
exit 0
;;
"d"*)
[ $# -eq 2 ] && del $2 || \
err "two args required"
exit 0
;;
"h"*)
info
exit 0
;;
"i"*)
[ $# -eq 2 ] && id $2 || \
err "two args required"
exit 0
;;
"c"*)
cclear
exit 0
;;
*)
display
exit 0
;;
esac
exit 0