Home of the Squeezebox™ & Transporter® network music players.
Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Senior Member
    Join Date
    Apr 2014
    Posts
    286

    Launch a track with cli or http, without path.

    Is this possible?
    I would like to be able to launch whatever track I want, using a single command or maybe more commands. I've seen a version where you can launch a track using the exact path. But is it maybe possible to have a command where I put the artist and the song in this command, and then lms plays this song? Even when there are more than 1 in the database?

  2. #2
    Senior Member
    Join Date
    Apr 2014
    Posts
    286
    Not possible?

  3. #3
    Senior Member paul-'s Avatar
    Join Date
    Jan 2013
    Posts
    3,938
    Yes you can

    Using wget. I created a variable with the request to make it easier to see the full command.

    Code:
    REQUEST={"id":1,"method":"slim.request","params":[ "myPlayer", ["playlist","loadtracks","track.titlesearch=Do%20It%20Again"]]}
    wget -T 5 -O- --post-data="$REQUEST" --header 'Content-Type: application/json' http://<ip.address.of lms>:9000/jsonrpc.js
    Where you see "myPlayer" in the request line, insert the name of your player.
    Enter the ip address of your lms server
    Then where you see the track name, you need to use %20 instead of the space in the name.
    piCorePlayer a small player for the Raspberry Pi in RAM.
    Homepage: https://www.picoreplayer.org

    Please donate if you like the piCorePlayer

  4. #4
    Senior Member
    Join Date
    Apr 2014
    Posts
    286
    Quote Originally Posted by paul- View Post
    Yes you can

    Using wget. I created a variable with the request to make it easier to see the full command.

    Code:
    REQUEST={"id":1,"method":"slim.request","params":[ "myPlayer", ["playlist","loadtracks","track.titlesearch=Do%20It%20Again"]]}
    wget -T 5 -O- --post-data="$REQUEST" --header 'Content-Type: application/json' http://<ip.address.of lms>:9000/jsonrpc.js
    Where you see "myPlayer" in the request line, insert the name of your player.
    Enter the ip address of your lms server
    Then where you see the track name, you need to use %20 instead of the space in the name.
    Thanks for the reply.

    Where do I put this code? I know a little bit. But should this be a bash script? Or a python script?

  5. #5
    Senior Member paul-'s Avatar
    Join Date
    Jan 2013
    Posts
    3,938
    The commands below are for a shell script. If you would rather work in python, you can still do the same. Either with an os.system call, or build routine that does an http POST.

    I assume you want to have a few different track name options? How are you going to select the tracks to be played?
    piCorePlayer a small player for the Raspberry Pi in RAM.
    Homepage: https://www.picoreplayer.org

    Please donate if you like the piCorePlayer

  6. #6
    Senior Member
    Join Date
    Apr 2014
    Posts
    286
    Quote Originally Posted by paul- View Post
    The commands below are for a shell script. If you would rather work in python, you can still do the same. Either with an os.system call, or build routine that does an http POST.

    I assume you want to have a few different track name options? How are you going to select the tracks to be played?
    My end goal is, to use tasker with AutoVoice and google home to launch the song. For now I use it to launch a playlist or some radio channel.
    But the goal is to use a certain command with the name of the song in it, and use the script to launch that song in lms. I could even use node red to do some stuff if needed.

    But say, I want launch the song: Purple Rain
    What command would I need? Something like this?:
    Code:
    wget -T 5 -O- --post-data="{"id":1,"method":"slim.request","params":[ "raspberrypi", ["playlist","loadtracks","track.titlesearch=Purple%20Rain"]]}" --header 'Content-Type: application/json' http://192.168.1.29:9000/jsonrpc.js
    I get this:

    http://192.168.1.29:9000/jsonrpc.js
    Connecting to 192.168.1.29:9000... connected.
    HTTP request sent, awaiting response... Read error (Connection timed out) in headers.
    Retrying.

    So what is going wrong?

  7. #7
    Senior Member paul-'s Avatar
    Join Date
    Jan 2013
    Posts
    3,938
    You have to be careful with placement and types of quote marks. Its odd the difference when using shell variables and when entering straight. Put single quotes around the post-data.

    Code:
    wget -T 5 -O- --post-data='{"id":1,"method":"slim.request","params":[ "raspberrypi", ["playlist","loadtracks","track.titlesearch=Purple%20Rain"]]}' --header 'Content-Type: application/json' http://192.168.1.29:9000/jsonrpc.js
    Here is how I've done it in python, I know there is a more glamorous way to do it in python, but I'm only doing a few calls.
    Code:
    # Sends a command to LMS via the jsonrpc interface.
    def send_lms_command (json, lmsip, port):
    	cmdline = '/usr/bin/wget -T 5 -q -O- --post-data=\'%s\' --header \'Content-Type: application/json\' http://%s:%s/jsonrpc.js' % ( json, lmsip, port)
    	t = Popen( cmdline, shell=True, stdout=DEVNULL, stderr=DEVNULL)
    	t.wait(timeout=6)
    
    def send_play_command( lmsip, port, player):
    	json_req = '{"id":1,"method":"slim.request","params":[ "%s", [ "play" ]]}' % player
    	send_lms_command (json_req, lmsip, port)
    piCorePlayer a small player for the Raspberry Pi in RAM.
    Homepage: https://www.picoreplayer.org

    Please donate if you like the piCorePlayer

  8. #8
    Senior Member
    Join Date
    Apr 2014
    Posts
    286
    Quote Originally Posted by paul- View Post
    You have to be careful with placement and types of quote marks. Its odd the difference when using shell variables and when entering straight. Put single quotes around the post-data.

    Code:
    wget -T 5 -O- --post-data='{"id":1,"method":"slim.request","params":[ "raspberrypi", ["playlist","loadtracks","track.titlesearch=Purple%20Rain"]]}' --header 'Content-Type: application/json' http://192.168.1.29:9000/jsonrpc.js
    Here is how I've done it in python, I know there is a more glamorous way to do it in python, but I'm only doing a few calls.
    Code:
    # Sends a command to LMS via the jsonrpc interface.
    def send_lms_command (json, lmsip, port):
    	cmdline = '/usr/bin/wget -T 5 -q -O- --post-data=\'%s\' --header \'Content-Type: application/json\' http://%s:%s/jsonrpc.js' % ( json, lmsip, port)
    	t = Popen( cmdline, shell=True, stdout=DEVNULL, stderr=DEVNULL)
    	t.wait(timeout=6)
    
    def send_play_command( lmsip, port, player):
    	json_req = '{"id":1,"method":"slim.request","params":[ "%s", [ "play" ]]}' % player
    	send_lms_command (json_req, lmsip, port)
    The first code worked! That's nice. In my case 7 songs were loaded, because I have multiple versions stored. Would it possible to launch only the first song/result? Then it would be perfect.

  9. #9
    Senior Member paul-'s Avatar
    Join Date
    Jan 2013
    Posts
    3,938
    You would have to use the song IDĺs. The unique number assigned by LMS in the library.
    piCorePlayer a small player for the Raspberry Pi in RAM.
    Homepage: https://www.picoreplayer.org

    Please donate if you like the piCorePlayer

  10. #10
    Senior Member
    Join Date
    Apr 2014
    Posts
    286
    Quote Originally Posted by paul- View Post
    You would have to use the song IDĺs. The unique number assigned by LMS in the library.
    That makes things more complicated. Then the last way would be to make a playlist and delete everything but 1 song. And play that playlist.

Posting Permissions

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