summaryrefslogtreecommitdiff
path: root/odin/strm/cache_media
blob: c34e20fe96f782b351a9216ded4091add6323917 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!@zsh@/bin/zsh

logTag=${0:t}

exec 1> >(logger -t "$logTag" -p news.notice)
exec 2> >(logger -t "$logTag" -p news.error)

debug() { logger -t "$logTag" -p news.debug }

function notmuch {
    msg1=1
    while true; do
        result=$(env NOTMUCH_CONFIG=${HOME}/.notmuch-rss-config @notmuch@/bin/notmuch $@)
        if ! [[ "$result" =~ "already locked" ]]; then
            echo -nE "$result"
            return
        else
            [[ $msg1 == "1" ]] && echo "Already locked" >&2
            msg1=0
        fi
        sleep 2
    done
}

acted=false

while {
    results=$(notmuch search --sort=oldest-first --output=messages "( tag:inbox AND is:media AND is:unread ) AND NOT ( tag:new OR tag:killed OR tag:failed OR tag:cached )")
    ids=("${(f)results}")
    for i in $checkedIds; do
        ids=(${ids#$i})
    done
    checkedIds=($checkedIds $ids)
} && [[ -n "${ids}" ]]; do
    url=""

    for id (${ids}); do
        systemctl --user start $(systemd-escape --template=download-youtube@.service ${id})

        acted=true
    done
done

if ${acted}; then
    systemctl --no-block start uucico@hel.service
fi