Final update: correct playlist endpoint, robust server handling, and production-ready logic

This commit is contained in:
2025-08-23 16:10:49 +03:00
parent 8fa2918905
commit 1056fd2090
7 changed files with 158 additions and 17 deletions

View File

@@ -4,6 +4,7 @@ import requests
from logging_config import Logger # Import the shared logger
import bcrypt
import time
import re
# Update paths to use the new directory structure
CONFIG_FILE = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'resources', 'app_config.txt')
@@ -75,14 +76,18 @@ def save_local_playlist(playlist):
def fetch_server_playlist():
"""Fetch the updated playlist from the server."""
try:
server_ip = f'{server}:{port}' # Construct the server IP with port
url = f'http://{server_ip}/api/playlists'
# Use port only if server is an IP address
ip_pattern = r'^\d+\.\d+\.\d+\.\d+$'
if re.match(ip_pattern, server):
server_url = f'http://{server}:{port}/api/playlists' # fixed endpoint
else:
server_url = f'http://{server}/api/playlists' # fixed endpoint
params = {
'hostname': host,
'quickconnect_code': quick
}
Logger.info(f"Fetching playlist from URL: {url} with params: {params}")
response = requests.get(url, params=params)
Logger.info(f"Fetching playlist from URL: {server_url} with params: {params}")
response = requests.get(server_url, params=params)
if response.status_code == 200:
response_data = response.json()