Skip to content

Commit 2ef3e55

Browse files
committed
Make user agent version match the client version being sent
1 parent cf045e4 commit 2ef3e55

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

extensions/spotify/src/main/java/app/revanced/extension/spotify/misc/fix/ClientTokenFetcher.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ static ClienttokenHttp.ClientTokenRequest buildSpoofedClientTokenRequest(String
5858

5959
@Nullable
6060
static ClienttokenHttp.ClientTokenResponse fetchClientToken(
61-
@NonNull String androidUserAgent,
6261
@NonNull ClienttokenHttp.ClientTokenRequest originalClientTokenRequest
6362
) throws IOException {
64-
String iosUserAgent = getIOSUserAgent(androidUserAgent);
63+
String iosUserAgent = getIOSUserAgent();
6564
if (iosUserAgent == null) {
6665
return null;
6766
}
@@ -102,17 +101,17 @@ static HttpURLConnection createProtobufRequestConnection(String url) throws IOEx
102101
}
103102

104103
@Nullable
105-
static String getIOSUserAgent(@NonNull String androidUserAgent) {
106-
Pattern iosSpotifyVersionPattern = Pattern.compile("Spotify/(\\d+\\.\\d+\\.\\d+)\\.\\d+");
107-
Matcher androidSpotifyVersionMatcher = iosSpotifyVersionPattern.matcher(androidUserAgent);
104+
static String getIOSUserAgent() {
105+
Pattern iosSpotifyVersionPattern = Pattern.compile("iphone-(\\d+\\.\\d+\\.\\d+)\\.\\d+");
106+
Matcher iosSpotifyVersionMatcher = iosSpotifyVersionPattern.matcher(getClientVersion());
108107

109-
if (!androidSpotifyVersionMatcher.find()) {
110-
Logger.printException(() -> "Failed to match iOS Spotify version from original android User-Agent. " +
111-
"Original User-Agent: " + androidUserAgent);
108+
if (!iosSpotifyVersionMatcher.find()) {
109+
Logger.printException(() -> "Failed to match iOS Spotify version from the client version " +
110+
getClientVersion());
112111
return null;
113112
}
114113

115-
String iosSpotifyVersion = androidSpotifyVersionMatcher.group(1);
114+
String iosSpotifyVersion = iosSpotifyVersionMatcher.group(1);
116115
return "Spotify/" + iosSpotifyVersion + " iOS/" +
117116
getSystemVersion() + " (" +
118117
getHardwareMachine() + ")";

extensions/spotify/src/main/java/app/revanced/extension/spotify/misc/fix/RequestListener.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,9 @@ public Response serve(@NonNull IHTTPSession request) {
4343
return newResponse(INTERNAL_ERROR);
4444
}
4545

46-
String androidUserAgent = request.getHeaders().get("user-agent");
47-
if (androidUserAgent == null) {
48-
Logger.printException(() -> "Failed to find original android User-Agent");
49-
return newResponse(INTERNAL_ERROR);
50-
}
51-
5246
try {
5347
ClienttokenHttp.ClientTokenResponse clientTokenResponse =
54-
ClientTokenFetcher.fetchClientToken(androidUserAgent, clientTokenRequest);
48+
ClientTokenFetcher.fetchClientToken(clientTokenRequest);
5549

5650
if (clientTokenResponse == null) {
5751
return newResponse(INTERNAL_ERROR);

0 commit comments

Comments
 (0)