feat: Convert M3U playlist output to M3U8 with encoded paths
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
13
main.py
13
main.py
@@ -4,6 +4,7 @@ import random
|
|||||||
import string
|
import string
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
import urllib.parse
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
DEBUG = os.environ.get('DEBUG')
|
DEBUG = os.environ.get('DEBUG')
|
||||||
@@ -12,13 +13,21 @@ logging.basicConfig(
|
|||||||
level=logging.DEBUG if DEBUG else logging.INFO)
|
level=logging.DEBUG if DEBUG else logging.INFO)
|
||||||
|
|
||||||
def run_pls_command(playlist_id, playlist_name):
|
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]
|
cmd = ['docker', 'exec', 'navidrome-navidrome-1', '/app/navidrome', 'pls', '-l', 'error', '-np', playlist_id]
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(cmd, capture_output=True, text=True, check=False)
|
result = subprocess.run(cmd, capture_output=True, text=True, check=False)
|
||||||
print(f"\n--- Output for playlist '{playlist_name}' ---")
|
print(f"\n--- Output for playlist '{playlist_name}' ---")
|
||||||
if result.stdout.strip():
|
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():
|
if result.stderr.strip():
|
||||||
print("STDERR:")
|
print("STDERR:")
|
||||||
print(result.stderr.strip())
|
print(result.stderr.strip())
|
||||||
|
|||||||
Reference in New Issue
Block a user