Merge listing and fetching into one

This commit is contained in:
Alex D. 2020-11-06 00:32:00 +01:00
parent 7656235b00
commit 552ae9cfd0
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
2 changed files with 25 additions and 15 deletions

View File

@ -1,15 +0,0 @@
#!/bin/zsh
source ~/.config/twitch-subs
LIST=()
for cur in $SUBSCRIPTIONS; do
<<< "Fetching twitch.tv/$cur" >&2
desc="$(youtube-dl --get-description "https://twitch.tv/$cur" 2>/dev/null)"
if [ -z "$desc" ]; then
<<< "$cur is offline." >&2
else
LIST+=("$cur | $desc")
fi
done
print -l $LIST > ~/.cache/twitch

25
twitch-list.zsh Executable file
View File

@ -0,0 +1,25 @@
#!/bin/zsh
source ~/.config/twitch-subs
cachefile=~/.cache/twitch
LIST=()
if [[ "$1" == "fetch" ]]; then
for cur in $SUBSCRIPTIONS; do
<<< "Fetching twitch.tv/$cur" >&2
desc="$(youtube-dl --get-description "https://twitch.tv/$cur" 2>/dev/null)"
if [ -z "$desc" ]; then
<<< "$cur is offline." >&2
else
LIST+=("$cur | $desc")
fi
done
print -l $LIST > $cachefile
else
list="$(< $cachefile)"
[ -z "$cachefile" ] && return
res="$(dmenu -l 20 <<< $list)"
res="${res%% | *}"
[ -z "$res" ] && return
mpv --profile=v "https://twitch.tv/$res"
fi