Announcement

Collapse
No announcement yet.

Bash parse mode from status

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Bash parse mode from status

    Hey,

    I want to parse in bash with curl the status if an audio is playing or stopped to play another audio afterwards.
    Read already "mode":"play" and "mode":"stop" with
    Code:
    curl -i -X POST -H "Content-Type: application/json" -d '{"id":1,"method":"slim.request","params":[ "aa:aa:bb:bb:cc:cc", ["'status'","-",1] ]}' http://localhost:9000/jsonrpc.js
    but cant parse the mode tag to read the state and run another code.

    Adding jq to the end of URL does not help me out
    Code:
    curl -i -X POST -H "Content-Type: application/json" -d '{"id":1,"method":"slim.request","params":[ "bb:bb:6c:cf:fc:b2", ["'status'","-",1,"tags"] ]}' http://localhost:9000/jsonrpc.js | jq '.'

    Would be happy for advice and help.
    Last edited by karadayi; 2022-09-11, 20:55.

    #2
    Try this:

    Code:
    curl -s -X POST -H "Content-Type: application/json" -d '{"id":1,"method":"slim.request","params":[ "aa:aa:bb:bb:cc:cc", ["'status'","-",1] ]}' http://localhost:9000/jsonrpc.js | awk -F\"mode\":\" '{print $2}' | awk -F\",\" '{print $1}'
    Awk is one tool that can be used to parse formatted text. It may or may not be the best one for this purpose, but it's the one I'm most familiar with.
    Usually running latest beta LMS nightly on Raspberry Pi OS with virtual players (Squeezelite and Airplay bridge). Occasionally using SB Radio, Boom or Classic.

    Comment


      #3
      Another option I'd recommend is jq (https://stedolan.github.io/jq/), a tool which allows you to query JSON results on the command line. It's available on many systems as a package, afaik:

      Code:
      curl -sX POST -H "Content-Type: application/json" -d '{"id":1,"method":"slim.request","params":[ "00:04:20:...", ["status","-",1] ]}' http://musicpi:9000/jsonrpc.js | jq ".result.mode"
      "stop"
      This would extract the "mode" element of the "result" within the response.
      Michael

      "It doesn't work - what shall I do?" - "Please check your server.log and/or scanner.log file!"
      (LMS: Settings/Information)

      Comment

      Working...
      X