updated to new files

This commit is contained in:
2025-03-25 11:11:44 +02:00
parent 91ff63937c
commit c6e7d38a69
13 changed files with 86 additions and 298 deletions

58
src/python_functions.py Normal file
View File

@@ -0,0 +1,58 @@
import requests
import os
import json
from kivy.logger import Logger
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!'
url = f'{server_ip}/api/playlists'
params = {
'hostname': hostname,
'quickconnect_code': quickconnect_code
}
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}')
# 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}')
return playlist
except json.JSONDecodeError as e:
Logger.error(f'Failed to parse JSON response: {e}')
else:
Logger.error(f'Failed to retrieve playlist: {response.text}')
except requests.exceptions.RequestException as e:
Logger.error(f"Failed to load playlist: {e}")
return []
def download_media_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):
os.makedirs(base_dir)
for media in playlist:
file_name = media.get('file_name', '')
file_url = media.get('url', '')
file_path = os.path.join(base_dir, file_name)
try:
response = requests.get(file_url)
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}")
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}")