diff --git a/Makefile b/Makefile index dfa07e8..b4ce4b6 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/sh/trss-yt-id b/sh/trss-yt-id new file mode 100755 index 0000000..8edbfc3 --- /dev/null +++ b/sh/trss-yt-id @@ -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 diff --git a/sh/yt b/sh/yt deleted file mode 100755 index 111af45..0000000 --- a/sh/yt +++ /dev/null @@ -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= -Cache directory: export YT_CACHEDIR= -Torify wrapper: export YT_TORIFY= -" -} -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 \ ${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