miraclx / freyr-js

A tool for downloading songs from music streaming services like Spotify and Apple Music.
https://git.io/freyr-js
Apache License 2.0
1.53k stars 95 forks source link

Automate Apple Music token updates #590

Closed miraclx closed 9 months ago

miraclx commented 11 months ago

The most filed, recurring issue is the Apple Music token expiring - https://github.com/miraclx/freyr-js/issues/14, https://github.com/miraclx/freyr-js/issues/70, https://github.com/miraclx/freyr-js/issues/91, https://github.com/miraclx/freyr-js/pull/399, https://github.com/miraclx/freyr-js/issues/439, https://github.com/miraclx/freyr-js/issues/481, https://github.com/miraclx/freyr-js/issues/497, https://github.com/miraclx/freyr-js/issues/498, https://github.com/miraclx/freyr-js/issues/501, https://github.com/miraclx/freyr-js/issues/530, https://github.com/miraclx/freyr-js/issues/534, https://github.com/miraclx/freyr-js/issues/548, https://github.com/miraclx/freyr-js/issues/584 and https://github.com/miraclx/freyr-js/issues/585.

It would be great to have the updates automated, and not require new releases of freyr.

Right now? I do the process manually which is;

$ xh https://music.apple.com/us/browse | rg 'assets/index-[a-z0-9]{8}.js' --only-matching
assets/index-e39f660e.js

$ xh https://music.apple.com/assets/index-e39f660e.js | rg 'eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IldlYlBsYXlLaWQifQ[^"]+' --only-matching
eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IldlYlBsYXlLaWQifQ.eyJpc3MiOiJBTVBXZWJQbGF5IiwiaWF0IjoxNjk4Nzg1ODQzLCJleHAiOjE3MDYwNDM0NDMsInJvb3RfaHR0cHNfb3JpZ2luIjpbImFwcGxlLmNvbSJdfQ.67_dZZLL08roWZOP_7OyujGvoudeZN5aQgpvYQfrwxG7EotRme5a6YcZ9aKD66A1bvLY1zBvfoCroC5RJfOJpw

# update the conf.json

We should be able to do this extraction inside freyr itself like we do with Spotify to auto-refresh the token.

p0we7 commented 10 months ago

https://music.apple.com/assets/index-d98aab9a.js

Why is the docker image still running with a 401 error even though I replaced the tonken in the default conf.json with the latest token?

miraclx commented 10 months ago

First, can you file another issue? since this is a tracking issue for automation not token-related issues.

And in that, can you elaborate on how you are updating the token and building the image?

zykrah commented 9 months ago

@miraclx This may be of use https://github.com/lujjjh/LitoMusic/blob/main/scripts/update-developer-token.sh.

miraclx commented 9 months ago

@zykrah, yeah it's practically equivalent to the script I have in the OP. Just that they're writing it to the file at the end, but you still have to manually call the script.

For freyr, I would like to integrate it directly so that when freyr itself detects that the token has expired, it updates it itself.

zykrah commented 9 months ago

I've translated the process into a python script, I don't know much JavaScript but I'm sure it wouldn't be too difficult using requests and regex/whatever other string manipulation? As for detection of whether the token has expired, couldn't you just test for 401 responses whenever you call to the endpoint and then run the token update function (and cache it locally?).

miraclx commented 9 months ago

Yes, exactly. We already have detection, just not update and eventual persistence.

Haven't had the time for a while. 😓

eepyeunomia commented 9 months ago

how can i do this on my own, i cant run the commands (linux)

eepyeunomia commented 9 months ago

nvm i got used the script and it worked

miraclx commented 9 months ago

@Khadeeejah just submitted #623, which is a promising resolution for this issue.