sinish player
This commit is contained in:
@@ -3,13 +3,45 @@ import os
|
||||
import json
|
||||
from kivy.logger import Logger
|
||||
|
||||
CONFIG_FILE = './Resurse/app_config.txt'
|
||||
|
||||
def load_config():
|
||||
"""Load configuration from app_config.txt."""
|
||||
if os.path.exists(CONFIG_FILE):
|
||||
with open(CONFIG_FILE, 'r') as file:
|
||||
return json.load(file)
|
||||
else:
|
||||
Logger.error(f"Configuration file {CONFIG_FILE} not found.")
|
||||
return {
|
||||
"screen_orientation": "Landscape",
|
||||
"screen_name": "",
|
||||
"quickconnect_key": "",
|
||||
"server_ip": "",
|
||||
"port": ""
|
||||
}
|
||||
|
||||
# Load configuration and initialize variables
|
||||
config_data = load_config()
|
||||
server = config_data.get("server_ip", "")
|
||||
host = config_data.get("screen_name", "")
|
||||
quick = config_data.get("quickconnect_key", "")
|
||||
port = config_data.get("port", "")
|
||||
# Determine the configuration status
|
||||
if server and host and quick and port:
|
||||
config_status = "ok"
|
||||
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}")
|
||||
|
||||
def load_playlist():
|
||||
# Load playlist from the server or local storage
|
||||
try:
|
||||
Logger.debug("Attempting to load playlist from server...")
|
||||
server_ip = 'http://192.168.0.115:5000'
|
||||
hostname = 'TvHolBa1'
|
||||
quickconnect_code = 'Initial01!'
|
||||
server_ip = f'http://{server}:{port}'
|
||||
hostname = host
|
||||
quickconnect_code = quick
|
||||
url = f'{server_ip}/api/playlists'
|
||||
params = {
|
||||
'hostname': hostname,
|
||||
@@ -55,4 +87,28 @@ def download_media_files(playlist):
|
||||
else:
|
||||
Logger.error(f"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"Failed to download {file_name}: {e}")
|
||||
|
||||
def clean_unused_files(playlist):
|
||||
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.")
|
||||
return
|
||||
|
||||
# Get all file names from the playlist
|
||||
playlist_files = {media.get('file_name', '') for media in playlist}
|
||||
|
||||
# Get all files in the directory
|
||||
all_files = set(os.listdir(base_dir))
|
||||
|
||||
# Determine unused files
|
||||
unused_files = all_files - playlist_files
|
||||
|
||||
# Delete unused files
|
||||
for file_name in unused_files:
|
||||
file_path = os.path.join(base_dir, file_name)
|
||||
try:
|
||||
os.remove(file_path)
|
||||
Logger.debug(f"Deleted unused file: {file_path}")
|
||||
except OSError as e:
|
||||
Logger.error(f"Failed to delete {file_path}: {e}")
|
||||
Reference in New Issue
Block a user