updates to yt
This commit is contained in:
parent
1071d2c372
commit
ce3431afa8
61
scripts/yt
61
scripts/yt
|
@ -2,11 +2,9 @@
|
||||||
|
|
||||||
[ -z "${YT_DATFILE}" ] && YT_DATFILE="${HOME}/.local/share/ytdat"
|
[ -z "${YT_DATFILE}" ] && YT_DATFILE="${HOME}/.local/share/ytdat"
|
||||||
[ -z "${YT_CACHEDIR}" ] && YT_CACHEDIR="${HOME}/.local/share/ytcache"
|
[ -z "${YT_CACHEDIR}" ] && YT_CACHEDIR="${HOME}/.local/share/ytcache"
|
||||||
|
[ -z "${YT_TORIFY}" ] && YT_TORIFY="torify"
|
||||||
ver=0.1
|
ver=0.1
|
||||||
|
|
||||||
touch $DATFILE
|
|
||||||
mkdir -p $CACHEDIR
|
|
||||||
|
|
||||||
info () {
|
info () {
|
||||||
printf %s "\
|
printf %s "\
|
||||||
yt - youtube tool
|
yt - youtube tool
|
||||||
|
@ -15,21 +13,38 @@ yt - youtube tool
|
||||||
=> [a]dd [id] - Add a channel to the list
|
=> [a]dd [id] - Add a channel to the list
|
||||||
=> [d]el [id] - Remove a channel from the list
|
=> [d]el [id] - Remove a channel from the list
|
||||||
=> [h]elp - Show this help
|
=> [h]elp - Show this help
|
||||||
|
=> [i]d [url] - Show internal channel id
|
||||||
|
|
||||||
List file: export DATFILE=<your file here>
|
List file: export YT_DATFILE=<your file here>
|
||||||
Cache directory: export CACHEDIR=<your dir here>
|
Cache directory: export YT_CACHEDIR=<your dir here>
|
||||||
|
Torify wrapper: export YT_TORIFY=<your torify here>
|
||||||
see yt(1) for more information on usage
|
|
||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
cache () {
|
||||||
|
touch ${YT_DATFILE}
|
||||||
|
mkdir -p ${YT_CACHEDIR}
|
||||||
|
}
|
||||||
|
err () {
|
||||||
|
printf "err: %s\n" ${1}
|
||||||
|
[ -z ${2} ] 2=1
|
||||||
|
exit ${2}
|
||||||
|
}
|
||||||
sync () {
|
sync () {
|
||||||
|
cache
|
||||||
for i in $(cat $YT_DATFILE | tr '\n' ' '); do
|
for i in $(cat $YT_DATFILE | tr '\n' ' '); do
|
||||||
torify curl -s \
|
${YT_TORIFY} curl -s \
|
||||||
https://www.youtube.com/feeds/videos.xml?channel_id=$i\
|
https://www.youtube.com/feeds/videos.xml?channel_id=$i\
|
||||||
> ${YT_CACHEDIR}/$i
|
> ${YT_CACHEDIR}/$i
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
id () {
|
||||||
|
${YT_TORIFY} curl "${1}" -s | \
|
||||||
|
grep 'youtube/www\.youtube\.com/channel/.\{24\}' -o | \
|
||||||
|
awk -F'/' '{print $NF}' | \
|
||||||
|
sed 1q
|
||||||
|
}
|
||||||
display () {
|
display () {
|
||||||
|
cache
|
||||||
tmp1=$(mktemp)
|
tmp1=$(mktemp)
|
||||||
tmp2=$(mktemp)
|
tmp2=$(mktemp)
|
||||||
for i in $(ls $YT_CACHEDIR | tr '\n' ' '); do
|
for i in $(ls $YT_CACHEDIR | tr '\n' ' '); do
|
||||||
|
@ -41,26 +56,40 @@ display () {
|
||||||
cat $tmp1 $tmp2 | pr -2t -s" | "
|
cat $tmp1 $tmp2 | pr -2t -s" | "
|
||||||
}
|
}
|
||||||
add () { # $1: name of channel id
|
add () { # $1: name of channel id
|
||||||
printf "%s\n" $1 >> $DATFILE
|
cache
|
||||||
|
printf "%s\n" $1 >> ${YT_DATFILE}
|
||||||
}
|
}
|
||||||
del () { # $1: line number of channel id
|
del () { # $1: line number of channel id
|
||||||
sed -i "${1}d" $DATFILE
|
cache
|
||||||
|
sed -i "${1}d" ${YT_DATFILE}
|
||||||
}
|
}
|
||||||
case $1 in
|
case $1 in
|
||||||
*"s"*)
|
"s"*)
|
||||||
sync
|
sync
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
*"a"*)
|
"a"*)
|
||||||
[ $# -eq 2 ] && add $2
|
[ $# -eq 2 ] && add $2 || \
|
||||||
|
err "two args required"
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
*"d"*)
|
"d"*)
|
||||||
[ $# -eq 2 ] && del $2
|
[ $# -eq 2 ] && del $2 || \
|
||||||
|
err "two args required"
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
*"h"*)
|
"h"*)
|
||||||
info
|
info
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
"i"*)
|
||||||
|
[ $# -eq 2 ] && id $2 || \
|
||||||
|
err "two args required"
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
display
|
display
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue