How to return path of playing item?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cpd73
    Senior Member
    • Mar 2017
    • 5007

    #31
    Material skin

    If you use Material skin, you can add an entry to the context menu shown when you right-click (or long press for mobile) on the cover in now-playing. Create a file named "actions.json" and place it within a "material-skin" folder in your LMS's prefs folder - e.g. "prefs/material-skin/actions.json" - with the following:

    Code:
    {
    "track":[
      {
        "title":"Copy file location",
        "script":"lmsCommand('$ID', ['status', '-', '1', 'tags:u']).then(({data}) => {copyTextToClipboard(decodeURI(data.result.playlist_loop[0].url));});",
        "icon":"file_copy"
      }
     ]
    }
    Selecting "Copy file location" from the menu will copy the location of the current track to the clipboard.
    Material debug: 1. Launch via http: //SERVER:9000/material/?debug=json (Use http: //SERVER:9000/material/?debug=json,cometd to also see update messages, e.g. play queue) 2. Open browser's developer tools 3. Open console tab in developer tools 4. REQ/RESP messages sent to/from LMS will be logged here.

    Comment

    • Lestrad
      Senior Member
      • Oct 2010
      • 433

      #32
      Originally posted by cpd73
      If you use Material skin, you can add an entry to the context menu shown when you right-click (or long press for mobile) on the cover in now-playing. ...

      Selecting "Copy file location" from the menu will copy the location of the current track to the clipboard.
      Wow. That works. I know this is beyond the call of duty, but can the script (which I assume is what's in the line beginning ""script"" up to the first """) be altered to convert the path that's sent to the clipboard from //Linux /to \\Windows\ ? And/or possibly call another script (to launch Foobar, for example)?

      I'm now refreshing my almost non-existent knowledge of Javascript.
      __________________________________________________ _____________________
      Logitech Media Server Version: 8.0.0 - ARCH-AUR-GIT.20200807.1a544e3 running on Wandboard Quad, music library on USB HDD
      Squeezebox Touch plugged into run-of-the-mill stereo rig via Musical Fidelity X-Act, extra speakers in kitchen, basement, and bedroom connected by ordinary (not unidirectional) copper wire.

      Comment

      • cpd73
        Senior Member
        • Mar 2017
        • 5007

        #33
        Originally posted by Lestrad
        Wow. That works. I know this is beyond the call of duty, but can the script (which I assume is what's in the line beginning ""script"" up to the first """) be altered to convert the path that's sent to the clipboard from //Linux /to \\Windows\ ? And/or possibly call another script (to launch Foobar, for example)?

        I'm now refreshing my almost non-existent knowledge of Javascript.
        The script is javascript, so yes it could do path conversion, etc. Pretty sure it cannot launch another app though - as the script runs in the browser. If you want to launch a command the you can use "command" and not "script" as the action. This would start a command on the LMS machine. So, what you could do is have a simple python script that converts an LMS track ID into a path and then runs Foobar. e.g.

        Code:
        {
        "track":[
          {
            "title":"Edit with foobar",
            "command":"start /b c:\to\command\launch-foobar.py $TRACKID",
            "icon":"file_copy"
          }
         ]
        }
        (My windows knowledge is pretty non-existant, but I'm assuming "start / b <command>" launches a command in the "background" - as you dont want LMS to be stalled whilst your command runs)

        'launch-foobar.py' would be passed a track ID, it then needs to call into LMS to convert this into a path - using code similar to the above. e.g.

        Code:
        import json
        import os
        import requests
        
        SERVER_IP = '127.0.0.1'
        
        try:
            resp = json.loads(requests.post('http://%s:9000/jsonrpc.js' % SERVER_IP, data = '{"id":1,"method":"slim.request","params":["",["songinfo",0,10,"tags:u","track_id:%s" % sys.argv[1]]]}').text)
            url = resp['result']['songinfo_loop'][0]['url']
            # convert URL, invoke foolbar
        except:
            print("FAILED")
        Material debug: 1. Launch via http: //SERVER:9000/material/?debug=json (Use http: //SERVER:9000/material/?debug=json,cometd to also see update messages, e.g. play queue) 2. Open browser's developer tools 3. Open console tab in developer tools 4. REQ/RESP messages sent to/from LMS will be logged here.

        Comment

        • Lestrad
          Senior Member
          • Oct 2010
          • 433

          #34
          Originally posted by cpd73
          The script is javascript, so yes it could do path conversion, etc. Pretty sure it cannot launch another app though - as the script runs in the browser. If you want to launch a command the you can use "command" and not "script" as the action. This would start a command on the LMS machine. So, what you could do is have a simple python script that converts an LMS track ID into a path and then runs Foobar.
          Hmm... Since I know a little VBScript, could I use that instead of Python?
          __________________________________________________ _____________________
          Logitech Media Server Version: 8.0.0 - ARCH-AUR-GIT.20200807.1a544e3 running on Wandboard Quad, music library on USB HDD
          Squeezebox Touch plugged into run-of-the-mill stereo rig via Musical Fidelity X-Act, extra speakers in kitchen, basement, and bedroom connected by ordinary (not unidirectional) copper wire.

          Comment

          • Paul Webster
            Senior Member
            • Apr 2005
            • 9634

            #35
            You would launch cscript.exe or vbscript.exe rather than python
            Paul Webster
            Author of "Now Playing" plugins covering Radio France (FIP etc), PlanetRadio (Bauer - Kiss, Absolute, Scala, JazzFM etc), KCRW, ABC Australia and CBC/Radio-Canada
            and, via the extra "Radio Now Playing" plugin lots more - see https://forums.slimdevices.com/showt...Playing-plugin

            Comment

            • cpd73
              Senior Member
              • Mar 2017
              • 5007

              #36
              Originally posted by Lestrad
              Hmm... Since I know a little VBScript, could I use that instead of Python?
              The "command" can be any command - all Material does here is blindly call whatever is set in the string.
              Material debug: 1. Launch via http: //SERVER:9000/material/?debug=json (Use http: //SERVER:9000/material/?debug=json,cometd to also see update messages, e.g. play queue) 2. Open browser's developer tools 3. Open console tab in developer tools 4. REQ/RESP messages sent to/from LMS will be logged here.

              Comment

              • Lestrad
                Senior Member
                • Oct 2010
                • 433

                #37
                First attempt

                Originally posted by cpd73
                The "command" can be any command - all Material does here is blindly call whatever is set in the string.
                Well, I've made a first stab. For the moment all I'm trying to do is get "Edit with foobar" to appear on the right-click menu and send the path of the playing item to my little .vbs script when I click it.

                I edited actions.json as follows:

                Code:
                {
                "track":[
                  {
                    "title":"Copy file location",
                    "script":"lmsCommand('$ID', 
                ['status', '-', '1', 'tags:u']).then
                (({data}) => {copyTextToClipboard
                (decodeURI(data.result.playlist_loop
                [0].url));});",
                    "icon":"file_copy"
                
                [B]"title":"Edit with foobar",
                    "command":"start /b O:\Mes_Documents\Computer\SCRIPTING\LMS2Foo.vbs $TRACKID",
                    "icon":"file_copy"[/B]
                  }
                 ]
                }
                The part I added is in bold. Now neither "Copy file location" nor "Edit with foobar" show up in the right-click menu. I'm sure there's a stupid error I'd see if I... weren't so stupid ;-[
                __________________________________________________ _____________________
                Logitech Media Server Version: 8.0.0 - ARCH-AUR-GIT.20200807.1a544e3 running on Wandboard Quad, music library on USB HDD
                Squeezebox Touch plugged into run-of-the-mill stereo rig via Musical Fidelity X-Act, extra speakers in kitchen, basement, and bedroom connected by ordinary (not unidirectional) copper wire.

                Comment

                • Roland0
                  Senior Member
                  • Aug 2012
                  • 1340

                  #38
                  Originally posted by Lestrad
                  Well, I've made a first stab. For the moment all I'm trying to do is get "Edit with foobar" to appear on the right-click menu and send the path of the playing item to my little .vbs script when I click it.
                  Before you invest any more time into this, note that Craig wrote:
                  Originally posted by cpd73
                  Pretty sure it cannot launch another app though - as the script runs in the browser. If you want to launch a command the you can use "command" and not "script" as the action. This would start a command on the LMS machine
                  Various SW: Web Interface | Text Interface | Playlist Editor / Generator | Music Classification | Similar Music | Announce | EventTrigger | Ambient Noise Mixer | DB Optimizer | Image Enhancer | Chiptunes | LMSlib2go | ...
                  Various HowTos: build a self-contained LMS | Bluetooth/ALSA | Control LMS with any device | ...

                  Comment

                  • cpd73
                    Senior Member
                    • Mar 2017
                    • 5007

                    #39
                    Originally posted by Lestrad
                    Well, I've made a first stab. For the moment all I'm trying to do is get "Edit with foobar" to appear on the right-click menu and send the path of the playing item to my little .vbs script when I click it.

                    I edited actions.json as follows:

                    Code:
                    {
                    "track":[
                      {
                        "title":"Copy file location",
                        "script":"lmsCommand('$ID', 
                    ['status', '-', '1', 'tags:u']).then
                    (({data}) => {copyTextToClipboard
                    (decodeURI(data.result.playlist_loop
                    [0].url));});",
                        "icon":"file_copy"
                    
                    [B]"title":"Edit with foobar",
                        "command":"start /b O:\Mes_Documents\Computer\SCRIPTING\LMS2Foo.vbs $TRACKID",
                        "icon":"file_copy"[/B]
                      }
                     ]
                    }
                    The part I added is in bold. Now neither "Copy file location" nor "Edit with foobar" show up in the right-click menu. I'm sure there's a stupid error I'd see if I... weren't so stupid ;-[
                    Try this:
                    Code:
                    {
                    "track":[
                      {
                        "title":"Edit with foobar",
                        "command":"start /b O:\Mes_Documents\Computer\SCRIPTING\LMS2Foo.vbs $TRACKID",
                        "icon":"file_copy"
                      }
                     ]
                    }
                    Material debug: 1. Launch via http: //SERVER:9000/material/?debug=json (Use http: //SERVER:9000/material/?debug=json,cometd to also see update messages, e.g. play queue) 2. Open browser's developer tools 3. Open console tab in developer tools 4. REQ/RESP messages sent to/from LMS will be logged here.

                    Comment

                    • Lestrad
                      Senior Member
                      • Oct 2010
                      • 433

                      #40
                      Originally posted by cpd73
                      Try this:
                      Code:
                      {
                      "track":[
                        {
                          "title":"Edit with foobar",
                          "command":"start /b O:\Mes_Documents\Computer\SCRIPTING\LMS2Foo.vbs $TRACKID",
                          "icon":"file_copy"
                        }
                       ]
                      }
                      For some reason that doesn't show up on the menu... However (to answer Roland) I am able to launch a test .vbs script from the Tray Menu of Squeezelite-X.
                      __________________________________________________ _____________________
                      Logitech Media Server Version: 8.0.0 - ARCH-AUR-GIT.20200807.1a544e3 running on Wandboard Quad, music library on USB HDD
                      Squeezebox Touch plugged into run-of-the-mill stereo rig via Musical Fidelity X-Act, extra speakers in kitchen, basement, and bedroom connected by ordinary (not unidirectional) copper wire.

                      Comment

                      • Roland0
                        Senior Member
                        • Aug 2012
                        • 1340

                        #41
                        Originally posted by Lestrad
                        For some reason that doesn't show up on the menu..
                        try escaping the backslashes:
                        Code:
                         "command":"start /b O:\\Mes_Documents\\Computer\\SCRIPTING\\LMS2Foo.vbs $TRACKID",
                        or maybe even:
                        Code:
                         "command":"start /b O:\\\\Mes_Documents\\\\Computer\\\\SCRIPTING\\LMS2Foo.vbs $TRACKID",
                        Last edited by Roland0; 2020-11-21, 14:33.
                        Various SW: Web Interface | Text Interface | Playlist Editor / Generator | Music Classification | Similar Music | Announce | EventTrigger | Ambient Noise Mixer | DB Optimizer | Image Enhancer | Chiptunes | LMSlib2go | ...
                        Various HowTos: build a self-contained LMS | Bluetooth/ALSA | Control LMS with any device | ...

                        Comment

                        • cpd73
                          Senior Member
                          • Mar 2017
                          • 5007

                          #42
                          Originally posted by Roland0
                          try escaping the backslashes:
                          Yup, that works for me:

                          Code:
                          {
                          "track":[
                            {
                              "title":"Edit with foobar",
                              "command":"start /b O:\\Mes_Documents\\Computer\\SCRIPTING\\LMS2Foo.vbs $TRACKID",
                              "icon":"file_copy"
                            }
                           ]
                          }
                          Material debug: 1. Launch via http: //SERVER:9000/material/?debug=json (Use http: //SERVER:9000/material/?debug=json,cometd to also see update messages, e.g. play queue) 2. Open browser's developer tools 3. Open console tab in developer tools 4. REQ/RESP messages sent to/from LMS will be logged here.

                          Comment

                          • Lestrad
                            Senior Member
                            • Oct 2010
                            • 433

                            #43
                            Originally posted by cpd73
                            Yup, that works for me:

                            Code:
                            {
                            "track":[
                              {
                                "title":"Edit with foobar",
                                "command":"start /b O:\\Mes_Documents\\Computer\\SCRIPTING\\LMS2Foo.vbs $TRACKID",
                                "icon":"file_copy"
                              }
                             ]
                            }
                            Sorry, not for me, with or without the quadruple backslashes. The LMS Server log shows:
                            Code:
                            [20-11-21 17:30:00.2442] Slim::Web::JSONRPC::requestMethod (486) request not dispatchable!
                            I'll try some debugging when I get a chance. Thanks to both of you, wish I could buy you a beer.
                            Last edited by Lestrad; 2020-11-21, 17:44.
                            __________________________________________________ _____________________
                            Logitech Media Server Version: 8.0.0 - ARCH-AUR-GIT.20200807.1a544e3 running on Wandboard Quad, music library on USB HDD
                            Squeezebox Touch plugged into run-of-the-mill stereo rig via Musical Fidelity X-Act, extra speakers in kitchen, basement, and bedroom connected by ordinary (not unidirectional) copper wire.

                            Comment

                            Working...