Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 3 of 3
  1. #1
    Junior Member
    Join Date
    May 2019
    Posts
    7

    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 at 11:55.

  2. #2
    Senior Member
    Join Date
    Jun 2017
    Posts
    866
    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.

  3. #3
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,776
    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •