JustYuuto / spotify-downloader

A Python script to download music straight from Spotify servers lol
MIT License
64 stars 11 forks source link

ogg file is not properly decr ? OGG_VORBIS_320 #10

Open AmarnathCJD opened 4 months ago

AmarnathCJD commented 4 months ago

[ogg @ 000001dcbcc31e80] Format ogg detected only with low score of 1, misdetection possible! [ogg @ 000001dcbcc31e80] cannot find sync word [in#0 @ 000001dcbcc1b480] Error opening input: Invalid data found when processing input Error opening input file C:\Users\amarn\spotify-downloader\Desperado-encrypted.ogg. Error opening input files: Invalid data found when processing input Error: Command '['ffmpeg', '-decryption_key', '1a4adea5249948f37a53f11efddfb2c8', '-i', 'C:\Users\amarn\spotify-downloader\Desperado-encrypted.ogg', 'C:\Users\amarn\spotify-downloader\Desperado.ogg']' returned non-zero exit status 3199971767.

AmarnathCJD commented 4 months ago

POST https://gae2-spclient.spotify.com/playplay/v1/key/fcaee7629075da20d8765dfeac0608841c68daef HTTP/1.1 Host: gae2-spclient.spotify.com Connection: keep-alive Content-Length: 30 Accept-Language: en App-Platform: Win32_x86_64 Spotify-App-Version: 123900578 User-Agent: Spotify/123900578 Win32_x86_64/Windows 10 (10.0.22631; x64; AppX) Content-Type: application/x-www-form-urlencoded

its resolved like this ig

DevLARLEY commented 3 months ago

What does this request?

AmarnathCJD commented 3 months ago

What does this request?

I got it from intercepting Spotify windows client, as web client only allow low quality audio playback. This req returns the key for decryption ig, need more investigation with windows client.

DevLARLEY commented 3 months ago

Could a post a sample of the request and response if you have the time? The only other piece of information I found is this TypeScript file: https://github.com/DaXcess/node-spotify-ap/blob/main/lib/audio/AudioKeyManager.ts#L10 which indicates that i have to parse the needed information as protobuf. I compiled the playplay.proto file to a *_pb2.py file protoc.exe --proto_path=proto --pyi_out=gen proto/playplay.proto and used it with the requests module to query the endpoint. But it seems like I'm not able to understand the mentioned file good enough as I don't know what the 'cache_id' is supposed to be. The official librespot python module doesn't mention the PlayPlayRequest. I also tried just sending a raw widevine challenge to the endpoint but that returned a 403 (Forbidden) error code.

My code:

req = playplay_pb2.PlayPlayLicenseRequest(
    version=3,
    cache_id=b'\x00',
    interactivity=playplay_pb2.Interactivity.INTERACTIVE,
    content_type=playplay_pb2.ContentType.AUDIO_TRACK,
)

response = requests.post(
    url='https://gae2-spclient.spotify.com/playplay/v1/key/c0f23483a2a7634a09a7b209ef2242c9b4b03ab0',
    data=req.SerializeToString(),
    headers={
        'Content-Type': 'application/x-protobuf',
        'App-Platform': 'Win32',
        "Authorization": f'Bearer {token_manager.get_access_token()}'
    }
)

Could you help me out here?

AmarnathCJD commented 3 months ago

Could a post a sample of the request and response if you have the time? The only other piece of information I found is this TypeScript file: https://github.com/DaXcess/node-spotify-ap/blob/main/lib/audio/AudioKeyManager.ts#L10 which indicates that i have to parse the needed information as protobuf. I compiled the playplay.proto file to a *_pb2.py file protoc.exe --proto_path=proto --pyi_out=gen proto/playplay.proto and used it with the requests module to query the endpoint. But it seems like I'm not able to understand the mentioned file good enough as I don't know what the 'cache_id' is supposed to be. The official librespot python module doesn't mention the PlayPlayRequest. I also tried just sending a raw widevine challenge to the endpoint but that returned a 403 (Forbidden) error code.

My code:

req = playplay_pb2.PlayPlayLicenseRequest(
    version=3,
    cache_id=b'\x00',
    interactivity=playplay_pb2.Interactivity.INTERACTIVE,
    content_type=playplay_pb2.ContentType.AUDIO_TRACK,
)

response = requests.post(
    url='https://gae2-spclient.spotify.com/playplay/v1/key/c0f23483a2a7634a09a7b209ef2242c9b4b03ab0',
    data=req.SerializeToString(),
    headers={
        'Content-Type': 'application/x-protobuf',
        'App-Platform': 'Win32',
        "Authorization": f'Bearer {token_manager.get_access_token()}'
    }
)

Could you help me out here?

Yeah wait till tommorow I'll send the details;

you could try intercepting windows Spotify client requests using Fiddler and try to understand the woorking.

DevLARLEY commented 3 months ago
r = requests.post(
    url="https://gew4-spclient.spotify.com/playplay/v1/key/f9608d4d11ce765a2f901fa8fddf76b0fd9d9e81",
    headers={
        "Authorization": f"Bearer {token_manager.get_access_token()}",
    },
    data=bytes.fromhex("0803121001a3840cfd43462497863e0d52139bd62001280130e7fec4b406")
)

print(r.status_code, r.content.hex())
# 200 0a1058cb0cd8f16b0f7bd4fe0890910a7e4412040895d37d

This works

AmarnathCJD commented 3 months ago

that sounds cool

But the next steps?

DevLARLEY commented 3 months ago

Some analysis later i got to this point:

PlayPlayLicenseRequest:
version: 3
token: 01a3840cfd43462497863e0d52139bd6
interactivity: INTERACTIVE
content_type: AUDIO_TRACK

PlayPlayLicenseResponse:
obfuscated_key: aaedcf042aae01f00836ed93e2ca1c71

I parsed the request and response as Protobuf and got this.

Next step would be to figure out how to use the output and where the input comes from. Do you know if the spotify client javascript-based?

DevLARLEY commented 3 months ago

ok it seems like this is quite complicated. For reference:

https://github.com/librespot-org/librespot-java/discussions/421
https://github.com/librespot-org/librespot-java/discussions/421/comments/1812935/threads
AmarnathCJD commented 3 months ago

wait can we rec eng libspot to get the track.?

if you ever figure out anything more please post here, these seems interesting

DevLARLEY commented 3 months ago

I'll try to, yes

DevLARLEY commented 3 months ago

I did it! Look at this: https://github.com/librespot-org/librespot-java/discussions/421#discussioncomment-10035969

AmarnathCJD commented 3 months ago

I did it! Look at this: https://github.com/librespot-org/librespot-java/discussions/421#discussioncomment-10035969

where to get the playplay.exe ?

DevLARLEY commented 3 months ago

I won't upload it here but it's the decrypt code leaked compiled using CMake on Windows. The code is accessible on the internet, that's all I'm going to say.

AmarnathCJD commented 3 months ago

I won't upload it here but it's the decrypt code leaked compiled using CMake on Windows. The code is accessible on the internet, that's all I'm going to say.

ah come.on just a hint where to find the uncompiled version :(

DevLARLEY commented 3 months ago

github

AmarnathCJD commented 3 months ago

github

suischan?

DevLARLEY commented 3 months ago

that got taken down, but it can still be found. just search for it

AmarnathCJD commented 3 months ago

wow that's amazing 😹😹

DevLARLEY commented 3 months ago

seems like it worked?

AmarnathCJD commented 3 months ago

seems like it worked?

Yup figuring out how to write the ogg headers

DevLARLEY commented 3 months ago

let me know if you figure something out, as i was only able to play the file using vlc. ffmpeg failed

AmarnathCJD commented 3 months ago

let me know if you figure something out, as i was only able to play the file using vlc. ffmpeg failed

https://gist.github.com/AmarnathCJD/ef4c368c38d5dfcb76f520dd76076189

here

after that you can rebuild proper metadata via ffmpeg

DevLARLEY commented 3 months ago

Do you mind if integrate this into my spotify downloader that I'm developing? Also, while you're at it, could you also do this to the AAC_24 quality, as it's also protected using the same system?

AmarnathCJD commented 3 months ago

yeah go on.

On Sat, Jul 13, 2024, 4:07 PM larley @.***> wrote:

Do you mind if integrate this into my spotify downloader that I'm developing?

— Reply to this email directly, view it on GitHub https://github.com/JustYuuto/spotify-downloader/issues/10#issuecomment-2226851292, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARJ64S6IRD4T5OYLTFNLFOLZMD7O3AVCNFSM6AAAAABJN7LYD2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMRWHA2TCMRZGI . You are receiving this because you authored the thread.Message ID: @.***>

DevLARLEY commented 3 months ago

A sample aac file sample_aac.zip

AmarnathCJD commented 3 months ago

Do you mind if integrate this into my spotify downloader that I'm developing? Also, while you're at it, could you also do this to the AAC_24 quality, as it's also protected using the same system?

Ah aac

why do we need it?

isn't ogg 320 the best quality

DevLARLEY commented 3 months ago

Sure, but i'd like the downloader to support it too. It's up to you if you want to create another rebuilder.

AmarnathCJD commented 3 months ago

I'll try;

AmarnathCJD commented 3 months ago

A sample aac file sample_aac.zip

this aint even playable in vlc

https://gist.github.com/AmarnathCJD/7c3a804e7685b0237f6da42d32f7986a

try with this

DevLARLEY commented 3 months ago

No luck, did you get it to work?

AmarnathCJD commented 3 months ago

No luck, did you get it to work?

is the decrypt failing on some songs??

for eg;- https://open.spotify.com/track/2qSkIjg1o9h3YT9RAgYN75

are you able to do on this.

DevLARLEY commented 3 months ago

Yes, i've had this too. Don't know why this is happening...

DevLARLEY commented 3 months ago

What i do know is that you can go down to OGG_VORBIS_160 and it should work (that's what the desktop app is requesting by default)

AmarnathCJD commented 3 days ago

What i do know is that you can go down to OGG_VORBIS_160 and it should work (that's what the desktop app is requesting by default)

Is this still working?

DevLARLEY commented 3 days ago

Of course, just make sure to compile the latest playplay version: https://git.gay/uhwot/unplayplay the old one got deprecated.

AmarnathCJD commented 2 days ago

Ah that was the reason meyb it was failing and what about the playplay keys??

On Wed, Nov 6, 2024, 1:04 AM larley @.***> wrote:

Of course, just make sure to compile the latest playplay version: https://git.gay/uhwot/unplayplay the old one got deprecated.

— Reply to this email directly, view it on GitHub https://github.com/JustYuuto/spotify-downloader/issues/10#issuecomment-2458002283, or unsubscribe https://github.com/notifications/unsubscribe-auth/ARJ64SY2LI5JD7R2BMBKHD3Z7EMS7AVCNFSM6AAAAABJN7LYD2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINJYGAYDEMRYGM . You are receiving this because you authored the thread.Message ID: @.***>