Jaffa / amazon-music

Provide programmatic access to Amazon Music/Prime Music's streaming service
Apache License 2.0
336 stars 67 forks source link

Trouble with VLC launch #17

Open smarty125 opened 5 years ago

smarty125 commented 5 years ago

New to Python, but not home automation. Would love to use this...but I need some help...

My setup is: -Running Win 7-32 bit. -Python 3.7 installed per default install; environment variable added to path. -Installed via a CMD window "pip install requests" & also "pip install beatifulsoup4 " <=verified good install. -Added VLC to my path <=so it can work from any path

After modifying the "play-station.py" file on line number 37 to be: os.system("vlc --play-and-stop '%s'" % t.stream_url) <= removed "c" on "cvlc", and kept VLC window from : os.system("cvlc --play-and-exit '%s'" % t.stream_url) <= cvlc is for Linux...right?

I get the following error message from VLC: Your input can't be opened: VLC is unable to open the MRL ''https://d29r7idq0wxsaz.cloudfront.net/DigitalMusicDeliveryService/HPS.m3u8?m=m'. Check the log for details.

So, recapping...From a command prompt window, the script prompts me from my Amazon email, and also password. That part works, and then it gives me the following out put (which looks like it is working):

Art: https://images-na.ssl-images-amazon.com/images/G/01/Gotham/Genre_Stations_U K/PS0001_eudmvd_UKClassicSoul.jpg Playing station Classic Soul... Playing September by Earth Wind & Fire from Greatest Hits [Earth Wind & Fire]...

So, what is wrong with the music stream amazon is sending to my VLC player?

From my VLC log file:

main debug: resyncing on (null)'https://d29r7idq0wxsiz.cloudfront.net/DigitalMusicDeliveryService/HPS.m3u8 main debug: (null)'https://d29r7idq0wxsiz.cloudfront.net/DigitalMusicDeliveryService/HPS.m3u8 is at 0 main debug: creating new input thread main debug: Creating an input for '(null)'https://d29r7idq0wxsiz.cloudfront.net/DigitalMusicDeliveryService/HPS.m3u8' main debug: requesting art for new input thread main debug: using timeshift granularity of 50 MiB main debug: using timeshift path: C:\Users\Smarty\AppData\Local\Temp main debug: 'https://d29r7idq0wxsiz.cloudfront.net/DigitalMusicDeliveryService/HPS.m3u8?m=m' gives access'https' demux any' pathd29r7idq0wxsiz.cloudfront.net/DigitalMusicDeliveryService/HPS.m3u8?m=m' main debug: creating demux: access=''https' demux='any' location='d29r7idq0wxsiz.cloudfront.net/DigitalMusicDeliveryService/HPS.m3u8?m=m' file='\d29r7idq0wxsiz.cloudfront.net\DigitalMusicDeliveryService\HPS.m3u8' main debug: looking for access_demux module matching "'https": 15 candidates main debug: no access_demux modules matched main debug: creating access: 'https://d29r7idq0wxsiz.cloudfront.net/DigitalMusicDeliveryService/HPS.m3u8?m=m main debug: (path: \d29r7idq0wxsiz.cloudfront.net\DigitalMusicDeliveryService\HPS.m3u8) main debug: looking for access

danieldaeschle commented 5 years ago

Now you need to be logged in to access the audio files. This wasn't needed in the past. This example isn't working anymore. You have to access this files with the cookie (with tokens).

smarty125 commented 5 years ago

Thank you very much danieldaeschle for your reply. Because I am about at the limits of my knowledge/understanding with Python programming ....I am not sure I fully comprehend the full aspects of your reply.

My question: How to I get the "token", and where and how do I use it?

I suspect that if it were an easy or simple fix, you would have updated this project or mentioned how to do it in your response. Right?

Again - thank your for taking the time to reply :)

danieldaeschle commented 5 years ago

The access token is in the cookie file. The problem is that if you want to use vlc to access the stream files, vlc doesnt use this cookie file and has no rights to access it.

I tried downloading this stream files and play then... But why? I can just merge this stream files and convert it to a mp3 file. Wow, i got it. Isn't that a security issue at amazon?

I reported it to amazon security. They told me that this is a known issue.

So, i think this library won't work in future because this will be completely fixed in future.

Actually you can just convert every song into an mp3 😂. But because this is a vulnerabilty and reverse engineering is forbidden i can't tell you how i did this :(

What do you want todo with this library?

smarty125 commented 5 years ago

Here is my use case - I have touchscreens and Echo dots throughout the house (touch and voice input control). When I am having a larger "party/get-together", I would like to be able to change amazon streaming radio stations via the touch screen, and not use voice control (too much ambient noise during the party).

Presently I have one of my dots set up to output to my amp (feeding whole house music), and I can control that dot via my I-phone...but it would be much nicer if I could change audio streams (to different pre-sets) via my touch panels (X-Lobby is my GUI, and PowerHome is my HA program that runs all the touchscreens) .

I have no desire to download and reconstruct any stream files....I would rather just have VLC play the incoming stream in a minimized instance that I can output to the whole house amp. Based on your reply, it doesn't sound like it is possible anymore.

Nice security catch by the way!!!

danieldaeschle commented 5 years ago

Is there no way to send a "change song" from the gui?

smarty125 commented 5 years ago

...From the Amazon I-phone Alexa app, under the "Music/Video&Books" area, you can control individual echos/dots. I believe you can also do this from your computer's browser (once logged into Amazon).

I was hoping that I could have my HA program (PowerHome) trigger off the touch screen press, and use this repo to call pre-defined Amazon streaming music stations.

I just wanted to keep everything "clean", and under the hood of my GUI.

danieldaeschle commented 5 years ago

Ok, i think you have to reverse engineer which api call is made on this action. I can't help you at this time. I have no echo dot.

Jaffa commented 5 years ago

Now you need to be logged in to access the audio files. This wasn't needed in the past.

Nope, still working for me without logging in. What is interesting is that it only seems to be 22.05kHz:

[00007f7d8404f558] packetizer_mpeg4audio packetizer: AAC channels: 2 samplerate: 22050
Jaffa commented 5 years ago

Looking at the web interface, the old streaming URL's been downgraded. Amazon's switched to MPEG-DASH

Note: None of this is the reason @smarty125 has had a problem with VLC, AFAICT. That might just be a Windows problem. The example of passing it to VLC as an external player is just that. Ideally there'd be a play function in the library...

Jaffa commented 5 years ago

Extracting the DASH manifest and trying to play it in a browser results in a couple of errors:

DRM: No license server URL specified!

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://dfqzuzzcqflbd.cloudfront.net/********-f246469139/bbc62065-ec67-3280-9c8f-394873******.mp4. (Reason: CORS request did not succeed

smarty125 commented 5 years ago

Jaffa, So you say it is still working for you? Can you please describe your set-up and what you are playing the streams with?

While I prefer to use a window 7/10 environment with VLC, I could also attempt to switch my approach over to my Linux Sinology NAS environment (if that would help).

danieldaeschle commented 5 years ago

It hasn't worked on my windows too.

I found a bug to download all the music files. I reported that to amazon and they told me that they're still fixing it. Maybe there will be some changes in the api soon.

Jaffa commented 5 years ago

@danieldaeschle - the old mechanism to get access to the stream data (the M3U playlist) was necessary for the library to get access to data that was needed to play the track in an open way.

I can't find any way of doing that in any reasonable quality now. The streams still exist, but are now atrocious quality. The Amazon Music web client now uses DASH, relying on in-browser DRM and the HTML5 Media Extensions to play the protected content. Playing that in an open source library will be nigh on impossible; or certainly in a library that exposes media data.

TBH, my own interest has diminished considerably, unless we can find a way of playing the tracks. I don't want to rip Amazon off, but the lack of a library to play songs was the driver; and they've effectively locked that down.

danieldaeschle commented 5 years ago

https://www.androidpolice.com/2019/01/02/googles-widevine-l3-drm-used-by-netflix-hulu-and-hbo-has-been-broken/

DRM can be hacked now 😆