Using a playlist  is a good idea.
Here's a python script which reads all tracks from a LMS playlist, runs
a replace on the path name, and executes a local command with the paths
as an argument:

Code:
--------------------
    
  #!/usr/bin/env python3
  import urllib.request
  from urllib.parse import urlparse
  from urllib.parse import unquote
  import json, subprocess
  
  pls_name = "bad tags"
  url = "http://lms:9000/jsonrpc.js";
  path_server = "/data/music"
  path_client = "/data/client"
  exec_cmd = ["tageditor"]
  
  headers = { 'Content-Type': 'application/json'}
  req = urllib.request.Request(url, json.dumps( {"id":1, 
"method":"slim.request", "params": ["-", ["playlists", 0, 1, 
"search:"+pls_name]]}).encode('utf-8'), headers)
  with urllib.request.urlopen(req) as response:
        result = response.read()
        res = json.loads(result.decode("utf-8"))
        if res and 'result' in res and res['result'] and 'playlists_loop' in 
res['result'] and res['result']['count'] == 1:
                req = urllib.request.Request(url, json.dumps( {"id":1, 
"method":"slim.request", "params": ["-", ["playlists", "tracks", 0, 999, 
"playlist_id:"+str(res['result']['playlists_loop'][0]['id']), 
"tags:u"]]}).encode('utf-8'), headers)
                with urllib.request.urlopen(req) as response:
                        result = response.read()
                        res = json.loads(result.decode("utf-8"))
                        if res and 'result' in res and res['result'] and 
'playlisttracks_loop' in res['result']:
                                alltracks = exec_cmd
                                for track in 
res['result']['playlisttracks_loop']:
                                        alltracks.append( unquote( urlparse( 
track['url']).path).replace( path_server, path_client))
                                cp = subprocess.run( alltracks, 
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
                                if cp.returncode != 0:
                                        print("Error: exec failed 
rc:{}\noutput:\n{}".format( cp.returncode, repr( cp)))
                        else:
                                print("Error: failed to get tracks for playlist 
{})".format( res['result']['playlists_loop'][0]['id']))
        else:
                print("Error: playlist {} not found (result: {})".format( 
pls_name, repr( res)))
  
  
--------------------


note: adapt the values of the first 5 variables to your local setup



'Various SW' (https://www.nexus0.net/pub/sw/): Web Interface | TUI |
Playlist Editor / Generator | Music Classification | Similar Music |
Announce | EventTrigger | Chiptunes | LMSlib2go | ...
'Various HowTos' (https://www.nexus0.net/pub/documents/LMS/): build a
self-contained LMS | Bluetooth/ALSA | Control LMS with any device | ...
------------------------------------------------------------------------
Roland0's Profile: http://forums.slimdevices.com/member.php?userid=56808
View this thread: http://forums.slimdevices.com/showthread.php?t=113145

_______________________________________________
Squeezecenter mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/squeezecenter

Reply via email to