diff --git a/main.py b/main.py index 2fede10..a865aba 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ import random import string import subprocess import time +import urllib.parse import requests DEBUG = os.environ.get('DEBUG') @@ -12,13 +13,21 @@ logging.basicConfig( level=logging.DEBUG if DEBUG else logging.INFO) def run_pls_command(playlist_id, playlist_name): - """Runs the docker exec command for a given playlist.""" + """Runs the docker exec command for a given playlist and transforms the output.""" cmd = ['docker', 'exec', 'navidrome-navidrome-1', '/app/navidrome', 'pls', '-l', 'error', '-np', playlist_id] try: result = subprocess.run(cmd, capture_output=True, text=True, check=False) print(f"\n--- Output for playlist '{playlist_name}' ---") if result.stdout.strip(): - print(result.stdout.strip()) + transformed_lines = [] + for line in result.stdout.strip().splitlines(): + if line.strip() and not line.startswith('#'): + if line.startswith('/music/'): + path = line[len('/music/'):] + encoded_path = urllib.parse.quote(path) + transformed_lines.append(f"local:track:{encoded_path}") + if transformed_lines: + print('\n'.join(transformed_lines)) if result.stderr.strip(): print("STDERR:") print(result.stderr.strip())