forked from n-92/AnyCast-Ubuntu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdlna_send_audio.py
More file actions
50 lines (43 loc) · 1.68 KB
/
Copy pathdlna_send_audio.py
File metadata and controls
50 lines (43 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import requests
# Target device and control URL
device_base_url = "http://192.168.1.112:62343"
control_url = f"{device_base_url}/AVTransport/control"
# Media URI — change this to your own image if desired
image_url = "http://192.168.1.108:8088/streamaudio"
# SOAP headers
headers = {
"Content-Type": "text/xml; charset=\"utf-8\"",
"SOAPAction": "\"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI\""
}
# SOAP body
soap_body = f"""<?xml version="1.0" encoding="utf-8"?>
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:SetAVTransportURI
xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
<InstanceID>0</InstanceID>
<CurrentURI>{image_url}</CurrentURI>
<CurrentURIMetaData></CurrentURIMetaData>
</u:SetAVTransportURI>
</s:Body>
</s:Envelope>"""
# Send the SetAVTransportURI command
response = requests.post(control_url, data=soap_body, headers=headers)
print("SetAVTransportURI response:", response.status_code, response.text)
# Now send the Play command
headers["SOAPAction"] = "\"urn:schemas-upnp-org:service:AVTransport:1#Play\""
soap_body_play = """<?xml version="1.0" encoding="utf-8"?>
<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:Play xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">
<InstanceID>0</InstanceID>
<Speed>1</Speed>
</u:Play>
</s:Body>
</s:Envelope>"""
response_play = requests.post(control_url, data=soap_body_play, headers=headers)
print("Play response:", response_play.status_code, response_play.text)