Auto-restart script for Libreelec

  • Dear All,

    I currently have a script that automatically runs after startup. It basically sleeps for 12 hours and then reboots. The problem I am having is that my PI is restarting while media is playing in Kodi. Is there any shell/terminal command that can check if Kodi is currently playing media?

    *Before you ask :) I need this script because for some reason I am having SMB issues. I have an external 2-bay HDD enclosure connected via USB and after startup I am able to access the drives from other PCs. Unfortunately, after some time the SMBs seem to slow down soooo badly, that is not even possible to read-write to the drives from another PC. The solution I am using is just rebooting my PI. This is a separate problem, and I am aware that there might be million different causes so for the time being, I am happy by rebooting (IF media is NOT playing)

  • Maybe something like

    Code
    curl -s -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["tvshowid"], "playerid": 1}, "id": "VideoGetItem"}' http://127.0.0.1:8080/jsonrpc
  • vpeter

    I just tried it but is not returning any output. (I changed the port to my own)

    MyPI:~/.config # curl -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["tvshowid"], "playerid": 1}, "id": "VideoGetItem"}' http://127.0.0.1:58080/jsonrpc > curl.txt

    % Total % Received % Xferd Average Speed Time Time Time Current

    Dload Upload Total Spent Left Speed

    100 124 0 0 100 124 0 41333 --:--:-- --:--:-- --:--:-- 62000

    MyPI:~/.config #

    MyPI:~/.config # more curl.txt

    MyPI:~/.config #

    Any ideas what could be the problem?

  • Code
    curl --user username:password -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["tvshowid"], "playerid": 1}, "id": "VideoGetItem"}' http://127.0.0.1:58080/jsonrpc

    Maybe :)

  • vpeter

    Actually I used and it worked :):

    http://user:[email protected]:58080/jsonrpc)

    Now I am suffering with the script.. grrr. I'm not a unix guy. My Script:

    MyPI:~/.config # more testscript.sh

    Code
    myvar=""
    myvar=$(curl -s -H 'Content-Type: application/json' -d '{"jsonrpc": "2.0", "method": "Player.GetItem", "params": { "p roperties": ["tvshowid"], "playerid": 1}, "id": "VideoGetItem"}' http://user:[email protected]:58080/json rpc)
    
    echo $myvar
    if [[ $myvar == *"unknown"* ]]
    then
    echo "NOT PLAYING"
    else
    echo "PLAYING"
    fi

    MyPI:~/.config #

    MyPI:~/.config # ./testscript.sh

    {"id":"VideoGetItem","jsonrpc":"2.0","result":{"item":{"label":"","type":"unknown"}}}

    PLAYING

    MyPI:~/.config #

    The variable is storing the output correctly, but I don't seem to find away how to check if the variable contains 'unknown' :S The problem seems to be the IF statement with the pattern matching.

    Any ideas are welcome :)