updated to download
This commit is contained in:
43
test_api.py
43
test_api.py
@@ -1,19 +1,44 @@
|
||||
import requests
|
||||
import os
|
||||
|
||||
# Replace with the actual server IP address or domain name and quick connect code
|
||||
server_ip = 'Http://192.168.0.115'
|
||||
# Replace with the actual server IP address or domain name, hostname, and quick connect code
|
||||
server_ip = 'http://192.168.0.115:5000'
|
||||
hostname = 'TvHolBa1'
|
||||
quickconnect_code = 'Initial01!'
|
||||
|
||||
# Construct the URL with the quick connect code as a query parameter
|
||||
url = f'{server_ip}/api/playlists?quickconnect_code={quickconnect_code}'
|
||||
# Construct the URL with the hostname and quick connect code as query parameters
|
||||
url = f'{server_ip}/api/playlists'
|
||||
params = {
|
||||
'hostname': hostname,
|
||||
'quickconnect_code': quickconnect_code
|
||||
}
|
||||
|
||||
# Make the GET request to the API
|
||||
response = requests.get(url)
|
||||
response = requests.get(url, params=params)
|
||||
|
||||
# Print the raw response content and status code for debugging
|
||||
print(f'Status Code: {response.status_code}')
|
||||
print(f'Response Content: {response.text}')
|
||||
|
||||
# Check if the request was successful
|
||||
if response.status_code == 200:
|
||||
# Parse the JSON response
|
||||
playlist = response.json().get('playlist', [])
|
||||
print('Playlist:', playlist)
|
||||
try:
|
||||
# Parse the JSON response
|
||||
playlist = response.json().get('playlist', [])
|
||||
print('Playlist:', playlist)
|
||||
|
||||
# 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}')
|
||||
except requests.exceptions.JSONDecodeError as e:
|
||||
print(f'Failed to parse JSON response: {e}')
|
||||
else:
|
||||
print('Failed to retrieve playlist:', response.json())
|
||||
print('Failed to retrieve playlist:', response.text)
|
||||
Reference in New Issue
Block a user