finish
This commit is contained in:
@@ -9,9 +9,10 @@ def load_config():
|
||||
"""Load configuration from app_config.txt."""
|
||||
if os.path.exists(CONFIG_FILE):
|
||||
with open(CONFIG_FILE, 'r') as file:
|
||||
Logger.info("python_functions: Configuration file loaded successfully.")
|
||||
return json.load(file)
|
||||
else:
|
||||
Logger.error(f"Configuration file {CONFIG_FILE} not found.")
|
||||
Logger.error(f"python_functions: Configuration file {CONFIG_FILE} not found.")
|
||||
return {
|
||||
"screen_orientation": "Landscape",
|
||||
"screen_name": "",
|
||||
@@ -32,46 +33,48 @@ if server and host and quick and port:
|
||||
else:
|
||||
config_status = "not_ok"
|
||||
|
||||
Logger.info(f"Configuration loaded: server={server}, host={host}, quick={quick}, port={port}")
|
||||
Logger.info(f"Configuration status: {config_status}")
|
||||
Logger.info(f"python_functions: Configuration loaded: server={server}, host={host}, quick={quick}, port={port}")
|
||||
Logger.info(f"python_functions: Configuration status: {config_status}")
|
||||
|
||||
def load_playlist():
|
||||
# Load playlist from the server or local storage
|
||||
"""Load playlist from the server or local storage."""
|
||||
try:
|
||||
Logger.debug("Attempting to load playlist from server...")
|
||||
server_ip = f'http://{server}:{port}'
|
||||
hostname = host
|
||||
quickconnect_code = quick
|
||||
url = f'{server_ip}/api/playlists'
|
||||
Logger.info("python_functions: Attempting to load playlist from server...")
|
||||
server_ip = f'{server}:{port}' # Construct the server IP with port
|
||||
url = f'http://{server_ip}/api/playlists'
|
||||
params = {
|
||||
'hostname': hostname,
|
||||
'quickconnect_code': quickconnect_code
|
||||
'hostname': host,
|
||||
'quickconnect_code': quick
|
||||
}
|
||||
response = requests.get(url, params=params)
|
||||
|
||||
|
||||
# Print the raw response content and status code for debugging
|
||||
Logger.debug(f'Status Code: {response.status_code}')
|
||||
Logger.debug(f'Response Content: {response.text}')
|
||||
|
||||
Logger.debug(f"python_functions: Status Code: {response.status_code}")
|
||||
Logger.debug(f"python_functions: Response Content: {response.text}")
|
||||
|
||||
# Check if the request was successful
|
||||
if response.status_code == 200:
|
||||
try:
|
||||
# Parse the JSON response
|
||||
playlist = response.json().get('playlist', [])
|
||||
Logger.debug(f'Playlist: {playlist}')
|
||||
Logger.info("python_functions: Playlist loaded successfully.")
|
||||
Logger.debug(f"python_functions: Loaded playlist: {playlist}")
|
||||
return playlist
|
||||
except json.JSONDecodeError as e:
|
||||
Logger.error(f'Failed to parse JSON response: {e}')
|
||||
Logger.error(f"python_functions: Failed to parse JSON response: {e}")
|
||||
else:
|
||||
Logger.error(f'Failed to retrieve playlist: {response.text}')
|
||||
Logger.error(f"python_functions: Failed to retrieve playlist: {response.text}")
|
||||
except requests.exceptions.RequestException as e:
|
||||
Logger.error(f"Failed to load playlist: {e}")
|
||||
Logger.error(f"python_functions: Failed to load playlist: {e}")
|
||||
return []
|
||||
|
||||
def download_media_files(playlist):
|
||||
"""Download media files from the playlist."""
|
||||
Logger.info("python_functions: Starting media file download...")
|
||||
base_dir = os.path.join(os.path.dirname(__file__), 'static', 'resurse') # Update this to the correct path
|
||||
if not os.path.exists(base_dir):
|
||||
os.makedirs(base_dir)
|
||||
Logger.info(f"python_functions: Created directory {base_dir} for media files.")
|
||||
|
||||
for media in playlist:
|
||||
file_name = media.get('file_name', '')
|
||||
@@ -83,16 +86,18 @@ def download_media_files(playlist):
|
||||
if response.status_code == 200:
|
||||
with open(file_path, 'wb') as file:
|
||||
file.write(response.content)
|
||||
Logger.debug(f"Downloaded {file_name} to {file_path}")
|
||||
Logger.info(f"python_functions: Downloaded {file_name} to {file_path}")
|
||||
else:
|
||||
Logger.error(f"Failed to download {file_name}: {response.status_code}")
|
||||
Logger.error(f"python_functions: Failed to download {file_name}: {response.status_code}")
|
||||
except requests.exceptions.RequestException as e:
|
||||
Logger.error(f"Failed to download {file_name}: {e}")
|
||||
Logger.error(f"python_functions: Failed to download {file_name}: {e}")
|
||||
|
||||
def clean_unused_files(playlist):
|
||||
"""Remove unused media files from the resource folder."""
|
||||
Logger.info("python_functions: Cleaning unused media files...")
|
||||
base_dir = os.path.join(os.path.dirname(__file__), 'static', 'resurse') # Update this to the correct path
|
||||
if not os.path.exists(base_dir):
|
||||
Logger.debug(f"Directory {base_dir} does not exist. No files to clean.")
|
||||
Logger.debug(f"python_functions: Directory {base_dir} does not exist. No files to clean.")
|
||||
return
|
||||
|
||||
# Get all file names from the playlist
|
||||
@@ -109,6 +114,6 @@ def clean_unused_files(playlist):
|
||||
file_path = os.path.join(base_dir, file_name)
|
||||
try:
|
||||
os.remove(file_path)
|
||||
Logger.debug(f"Deleted unused file: {file_path}")
|
||||
Logger.info(f"python_functions: Deleted unused file: {file_path}")
|
||||
except OSError as e:
|
||||
Logger.error(f"Failed to delete {file_path}: {e}")
|
||||
Logger.error(f"python_functions: Failed to delete {file_path}: {e}")
|
||||
Reference in New Issue
Block a user