postlund / pyatv

A client library for Apple TV and AirPlay devices
https://pyatv.dev
MIT License
891 stars 100 forks source link

AirPlay play_url /play 404 response #1518

Open oownus opened 2 years ago

oownus commented 2 years ago

Describe the bug

I'm trying to play a video file from a URL, any idea why /play is responding with 404 with valid airplay credentials? Thanks in advance

Error log

2021-12-10 00:42:53 DEBUG [pyatv.support.net]: Binding on *:5353
2021-12-10 00:42:53 DEBUG [pyatv.support.net]: Binding on 127.0.0.1:0
...
2021-12-10 00:42:56 DEBUG [pyatv.protocols.airplay.player]: Starting to play https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4
2021-12-10 00:42:56 DEBUG [pyatv.support.http]: Sending HTTP/1.1 message: b'POST /play HTTP/1.1\r\nContent-Length: 257\r\nUser-Agent: MediaControl/1.0\r\nContent-Type: application/x-apple-binary-plist\r\n\r\nbplist00\xd3\x01\x02\x03\x04\x05\x06_\x10\x10Content-Location^Start-Position_\x10\x12X-Apple-Session-ID_\x10hhttps://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4\x10\x00_\x10$6505b070-6ac2-4826-b4b5-957c1f272e5d\x08\x0f"1F\xb1\xb3\x00\x00\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xda'
2021-12-10 00:42:56 DEBUG [pyatv.support.http]: Received: b'HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\nServer: AirTunes/377.25.06\r\n\r\n'
2021-12-10 00:42:56 DEBUG [pyatv.support.http]: Got HTTP response: HttpResponse(protocol='HTTP', version='1.1', code=404, message='Not Found', headers={'content-length': '0', 'server': 'AirTunes/377.25.06'}, body=''):
2021-12-10 00:42:56 ERROR [pyatv.scripts.atvremote]: Authentication error: status code: 404
2021-12-10 00:42:56 DEBUG [pyatv.scripts.atvremote]: Waiting for 0 remaining tasks
2021-12-10 00:42:56 DEBUG [pyatv.support.http]: Connection closed

How to reproduce the bug?

$ atvremote -n "[LG] webOS TV UM7300PUA" --airplay-credentials
641e7f20c7919a5c56c352294e1e7630dc0c64a97bbce09c07a306c7848950b9:fd9efcac8d477cf92f58e1f49f2e06e031c89d4023cb6f930f7540f77de805a3:35383a32383a42343a32333a31373a4244:32333666343966362d613162302d346564392d383030322d313165366333326330663230
--debug
play_url=https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4

What is expected behavior?

AirPlay to play video from URL

Operating System

macOS

Python

3.9

pyatv

master

Device

LG TV 55" UM7300PUA

Additional context

Trying to play mp4 video from URL on LG TV 55"

postlund commented 2 years ago

The exception is a bit misleading as that is obviously not an authentication error (I should fix that). My guess is that your TV does not support the /play command. I must say that I am not very confident as to what feature flag corresponds what actual feature in the protocol, but https://openairplay.github.io/airplay-spec/features.html with your feature flags (0x7F8AD0,0x38BCB46) suggests that video is not supported. HTTP live streams and audio are supported though (only audio streaming is supported by pyatv). So we are likely out of luck here until I get around supporting video streaming and to be honest, I'm not sure that will ever happen as it is very CPU intensive and hard to do in python. If offloaded to another application, maybe it can be accomplished.

postlund commented 2 years ago

Would you mind pasting the result of:

atvremote -n "[LG] webOS TV UM7300PUA" --airplay-credentials 641e7f20c7919a5c56c352294e1e7630dc0c64a97bbce09c07a306c7848950b9:fd9efcac8d477cf92f58e1f49f2e06e031c89d4023cb6f930f7540f77de805a3:35383a32383a42343a32333a31373a4244:32333666343966362d613162302d346564392d383030322d313165366333326330663230 features

Looks like I have already implemented feature detection in pyatv, just not applying it in Home Assistant. Just want to verify this is the case.

oownus commented 2 years ago
$ atvremote -n "[LG] webOS TV UM7300PUA" --airplay-credentials 641e7f20c7919a5c56c352294e1e7630dc0c64a97bbce09c07a306c7848950b9:fd9efcac8d477cf92f58e1f49f2e06e031c89d4023cb6f930f7540f77de805a3:35383a32383a42343a32333a31373a4244:32333666343966362d613162302d346564392d383030322d313165366333326330663230 features
NOTE: Push updates are not supported in this configuration
Feature list:
-------------
PlayUrl: Available

Legend:
-------
Available: Supported by device and usable now
Unavailable: Supported by device but not usable now
Unknown: Supported by the device but availability not known
Unsupported: Not supported by this device (or by pyatv)
postlund commented 2 years ago

Thanks! I might be parsing the flags a bit wrong, I'll have a look at that so at least feature detection is correct.

oownus commented 2 years ago

Perhaps that could be the case, pretty bummed to find out that this TV doesn't support PlayUrl feature 😭 Thanks for the awesome library though

postlund commented 2 years ago

Yeah, I totally agree! It's so strange that they aren't focusing more on streaming videos directly from the target device, e.g. via URL. Doing so now usually just breaks everything and makes stuff stop working (like metadata).

postlund commented 1 year ago

Can you try if #2079 fixes this for you?