summaryrefslogtreecommitdiff
path: root/bin/extra/append2mpv
blob: 28c3916d11e1a0ebd54c7e3c192cc6449e59a673 (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
#!/bin/sh
IPC="/tmp/mpvsocket"

die () { >&2 printf '%s\n' "$@"; exit 1; }
append_to_mpv()
{
    file="$(readlink -f "$1")"
    if [ ! -r "$file" ]
    then
        >&2 printf '%s\n' "'$file' not found"
        return
    fi

    echo '{ "command":   ["loadfile", "'"$file"'", "append"] }' |
        socat - "$IPC"
}

[ -S "$IPC" ] || die "$IPC is not a socket or doesn't exist"
which socat > /dev/null || exit 1


if [ -t 0 ]
then
    append_to_mpv "$1"
else
    while read -r file
    do
        append_to_mpv "$file"
    done
fi