aboutsummaryrefslogtreecommitdiff
path: root/web/native-protocol/jellynative
blob: e1b310c1f2c0aa4fe5ada69fdfebd8c5782b370d (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
47
48
49
50
51
52
53
54
55
#!/bin/fish
set parts (string split / $argv[1])
set protocol $parts[1]
set action $parts[3]
set secret $parts[4]

if not test $protocol = "jellynative:"
    die "Wrong protocol"
end

function die
    notify-send -u critical -t 5000 'Jellynative Error' $argv[1]
    exit 1
end

function player
    if which mpv &>/dev/null
        set playercommand mpv
    else if which vlc &>/dev/null
        set playercommand vlc
    else
        die 'No Media Player detected'
    end
    notify-send -u low -t 1000 Jellynative 'Player ist launching...'
    if not $playercommand $argv[2..] $argv[1]
        die 'Player exited with error code'
    end
end

set config_dir $XDG_CONFIG_HOME
if test -z $config
    set config_dir ~/.config
end
set config $config_dir/jellynative_secret
if not test -e $config
    random 0 4000000000 >$config
end
set secret (cat $config)

if test $action != show-secret
    if test $secret != $parts[4]
        die 'Incorrect secret'
    end
end

switch $action
    case show-secret
        notify-send -u low Jellynative "Secret: $secret"
    case player
        player (string join / $parts[5..])
    case player-fullscreen
        player (string join / $parts[5..]) --fullscreen
    case '*'
        die 'Unknown action'
end