openairplay/airplay2-receiver

Can't stream Apple Music to AP2R

Closed this issue · 14 comments

The problem

It connects but when I press play, it disconnects instantly.

What commit exhibits the issue?

main

Was there a last known working commit?

No response

What type of installation are you running?

virtualenv

With which python3 version do you run Receiver?

Pyhton 3.7.9

OS the receiver runs on

Windows 10

OS the sender runs

iOS 17.0 Developer Beta 2

Which sender client was used

Apple Music

Command invocation

python ap2-reciever.py -m vInf -n "GUID HERE"

Please include --debug output which helps to illustrate the problem

debug.txt

Additional information

No response

something like this:

diff --git a/ap2-receiver.py b/ap2-receiver.py
index d208f1e..f5f5b00 100644
--- a/ap2-receiver.py
+++ b/ap2-receiver.py
@@ -411,6 +411,7 @@ class AP2Handler(http.server.BaseHTTPRequestHandler):
                          "ANNOUNCE, SETUP, RECORD, PAUSE, FLUSH"
                          "FLUSHBUFFERED, TEARDOWN, OPTIONS, POST, GET, PUT"
                          "SETPEERSX"
+                         "SETMAGICCOOKIE"
                          )
         self.end_headers()

@@ -866,6 +867,21 @@ class AP2Handler(http.server.BaseHTTPRequestHandler):
         self.send_header("CSeq", self.headers["CSeq"])
         self.end_headers()

+    def do_SETMAGICCOOKIE(self):
+        # Appears in iOS 17 betas ( User-Agent: AirPlay/710.66.3 )
+        self.logger.info(f'{self.command}: {self.path}')
+        self.logger.debug(self.headers)
+        content_len = int(self.headers["Content-Length"])
+        if content_len > 0:
+            body = self.rfile.read(content_len)
+
+            plist = readPlistFromString(body)
+            self.logger.info(self.pp.pformat(plist))
+        self.send_response(200)
+        self.send_header("Server", self.version_string())
+        self.send_header("CSeq", self.headers["CSeq"])
+        self.end_headers()
+
     def handle_command(self):
         if self.headers["Content-Type"] == HTTP_CT_BPLIST:
             content_len = int(self.headers["Content-Length"])

@xatitive Perhaps you can try the above also.

Tried the above fix and doesn't work exactly as intended, when ran it outputs the magic cookies hex binary string

[AP2Handler: 192.168.1.184:7000<=>192.168.1.157:56953; Thread-2 (process_request_thread)]: SETMAGICCOOKIE: rtsp://192.168.1.184/9278966137520734488
[AP2Handler: 192.168.1.184:7000<=>192.168.1.157:56953; Thread-2 (process_request_thread)]: {'magicCookie': b'\x00\x00\x01`\x00\x18(\n\x0e\x02\x00\xff\x00\x00\x00\x00'
                b'\x00\x00\x00\x00\x00\x00\xbb\x80',
 'magicCookieID': -4859668389756636041}
[comtypes]: Calling CoUninitialize()
[comtypes]: CoUninitialize() done.

Try hacking some more. What happens before and after the cookie bit? On your client (also)?

Nothing new happens before the cookie bit, after receiving the bit we also get the ID of it too but has nowhere to go rn ofc
but now I can "play" music as now it'll say it's playing to the receiver while not receiving anything to play.

After the bit CoUninitialize gets called and nothing more happens when trying to interact with it

You could maybe try the streams mode. I added support, but never really figured out what it was supposed to do or how it was supposed to work differently. I see different behaviour in the logs, however.

See commit 723bace

running python ap2-receiver.py -m myap2 -n "{250B8E87-4420-470E-8B1B-75DD2836809B}" --debug -ftxor 59 did the same thing, (i think thats what u wanted me to run) doesnt do anything new compared to what happened last time. although now im seeing that once connecting to the reciever you have to restart since it just hangs after recieving the cookie

Hmm - just taking stabs in the dark here. You're welcome to try hacking yourself. That's what this project is for.

How is this in the latest beta?

I just tried this project today with YouTube and I too got the SETMAGICCOOKIE error now on iOS 17 public release.

Try the latest master 6c343d3. Works for me on iOS 17.0.2.