updated server

This commit is contained in:
2025-06-20 16:33:21 +03:00
parent 2e94a334de
commit c57bb7fe6d
10 changed files with 87 additions and 91 deletions

View File

@@ -3,10 +3,10 @@ import os
# Replace with the actual server IP address or domain name, hostname, and quick connect code
server_ip = 'http://localhost:5000'
hostname = 'tv1'
quickconnect_code = '4321'
hostname = 'rpi-tv11'
quickconnect_code = '8887779'
# Construct the URL with the hostname and quick connect code as query parameters
# Construct the URL for the playlist API
url = f'{server_ip}/api/playlists'
params = {
'hostname': hostname,
@@ -24,21 +24,37 @@ print(f'Response Content: {response.text}')
if response.status_code == 200:
try:
# Parse the JSON response
playlist = response.json().get('playlist', [])
print('Playlist:', playlist)
response_data = response.json()
playlist = response_data.get('playlist', [])
playlist_version = response_data.get('playlist_version', None)
print(f'Playlist Version: {playlist_version}')
print(f'Playlist: {playlist}')
# Define the local folder for saving files
local_folder = './static/resurse'
if not os.path.exists(local_folder):
os.makedirs(local_folder)
# Download each file in the playlist
for item in playlist:
file_url = item['url']
file_name = item['file_name']
response = requests.get(file_url)
if response.status_code == 200:
with open(file_name, 'wb') as f:
f.write(response.content)
print(f'Downloaded {file_name}')
else:
print(f'Failed to download {file_name}: {response.status_code}')
for media in playlist:
file_name = media.get('file_name', '')
file_url = media.get('url', '')
duration = media.get('duration', 10) # Default duration if not provided
local_file_path = os.path.join(local_folder, file_name)
print(f'Downloading {file_name} from {file_url}...')
try:
file_response = requests.get(file_url, timeout=10)
if file_response.status_code == 200:
with open(local_file_path, 'wb') as file:
file.write(file_response.content)
print(f'Successfully downloaded {file_name} to {local_file_path}')
else:
print(f'Failed to download {file_name}. Status Code: {file_response.status_code}')
except requests.exceptions.RequestException as e:
print(f'Error downloading {file_name}: {e}')
except requests.exceptions.JSONDecodeError as e:
print(f'Failed to parse JSON response: {e}')
else:
print('Failed to retrieve playlist:', response.text)
print(f'Failed to retrieve playlist. Status Code: {response.status_code}')