#!/bin/bash

arp -i br-lan|grep 'ether'|grep '192.168.'|awk '{print $1}' > /tmp/hostlist.tmp

readarray -t bundels < /tmp/hostlist.tmp
for addr in ${bundels[@]};
    do
        kurl='-u kodi:kodipassword http://$addr:8080/jsonrpc -H "Content-Type: application/json"'
        if $(curl -u kodi:kodipassword http://$addr:8080/jsonrpc -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"JSONRPC.Ping","id":1}'|grep -Fq 'pong'); then
            if $(curl -u kodi:kodipassword http://$addr:8080/jsonrpc -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "Player.GetItem","params": {"playerid": 1,"properties": ["file"]},"id": 1}'|grep -vFq 'rtsp-local.strm'); then
                curl -u kodi:kodipassword http://$addr:8080/jsonrpc -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"/storage/emulated/0/Download/rtsp-local.strm"}},"id":1}'
            fi
        fi
        
        #if grep -Fq 'pong' $result; then
    done
#if `arp -i br-lan|grep 'ether'|grep -Fq '192.168.11111'`; then

