mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-04-29 22:24:27 +02:00
fix(Spotify): Ignore optional attributes if not present (#4688)
This commit is contained in:
parent
58ffbf40a5
commit
84f585492e
@ -1,54 +1,87 @@
|
||||
package app.revanced.extension.spotify.misc;
|
||||
|
||||
import static java.lang.Boolean.FALSE;
|
||||
import static java.lang.Boolean.TRUE;
|
||||
|
||||
import com.spotify.remoteconfig.internal.AccountAttribute;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
import app.revanced.extension.shared.Logger;
|
||||
|
||||
/**
|
||||
* @noinspection unused
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public final class UnlockPremiumPatch {
|
||||
|
||||
private static final Map<String, Object> OVERRIDES = new HashMap<>() {{
|
||||
// Disables player and app ads.
|
||||
put("ads", false);
|
||||
// Works along on-demand, allows playing any song without restriction.
|
||||
put("player-license", "premium");
|
||||
// Disables shuffle being initially enabled when first playing a playlist.
|
||||
put("shuffle", false);
|
||||
// Allows playing any song on-demand, without a shuffled order.
|
||||
put("on-demand", true);
|
||||
// Make sure playing songs is not disabled remotely and playlists show up.
|
||||
put("streaming", true);
|
||||
// Allows adding songs to queue and removes the smart shuffle mode restriction,
|
||||
// allowing to pick any of the other modes.
|
||||
put("pick-and-shuffle", false);
|
||||
// Disables shuffle-mode streaming-rule, which forces songs to be played shuffled
|
||||
// and breaks the player when other patches are applied.
|
||||
put("streaming-rules", "");
|
||||
// Enables premium UI in settings and removes the premium button in the nav-bar.
|
||||
put("nft-disabled", "1");
|
||||
// Enable Cross-Platform Spotify Car Thing.
|
||||
put("can_use_superbird", true);
|
||||
// Removes the premium button in the nav-bar for tablet users.
|
||||
put("tablet-free", false);
|
||||
}};
|
||||
private static class OverrideAttribute {
|
||||
/**
|
||||
* Account attribute key.
|
||||
*/
|
||||
final String key;
|
||||
|
||||
/**
|
||||
* Override value.
|
||||
*/
|
||||
final Object overrideValue;
|
||||
|
||||
/**
|
||||
* If this attribute is expected to be present in all situations.
|
||||
* If false, then no error is raised if the attribute is missing.
|
||||
*/
|
||||
final boolean isExpected;
|
||||
|
||||
OverrideAttribute(String key, Object overrideValue) {
|
||||
this(key, overrideValue, true);
|
||||
}
|
||||
|
||||
OverrideAttribute(String key, Object overrideValue, boolean isExpected) {
|
||||
this.key = Objects.requireNonNull(key);
|
||||
this.overrideValue = Objects.requireNonNull(overrideValue);
|
||||
this.isExpected = isExpected;
|
||||
}
|
||||
}
|
||||
|
||||
private static final List<OverrideAttribute> OVERRIDES = List.of(
|
||||
// Disables player and app ads.
|
||||
new OverrideAttribute("ads", FALSE),
|
||||
// Works along on-demand, allows playing any song without restriction.
|
||||
new OverrideAttribute("player-license", "premium"),
|
||||
// Disables shuffle being initially enabled when first playing a playlist.
|
||||
new OverrideAttribute("shuffle", FALSE),
|
||||
// Allows playing any song on-demand, without a shuffled order.
|
||||
new OverrideAttribute("on-demand", TRUE),
|
||||
// Make sure playing songs is not disabled remotely and playlists show up.
|
||||
new OverrideAttribute("streaming", TRUE),
|
||||
// Allows adding songs to queue and removes the smart shuffle mode restriction,
|
||||
// allowing to pick any of the other modes.
|
||||
new OverrideAttribute("pick-and-shuffle", FALSE),
|
||||
// Disables shuffle-mode streaming-rule, which forces songs to be played shuffled
|
||||
// and breaks the player when other patches are applied.
|
||||
new OverrideAttribute("streaming-rules", ""),
|
||||
// Enables premium UI in settings and removes the premium button in the nav-bar.
|
||||
new OverrideAttribute("nft-disabled", "1"),
|
||||
// Enable Spotify Car Thing hardware device.
|
||||
// Device is discontinued and no longer works with the latest releases,
|
||||
// but it might still work with older app targets.
|
||||
new OverrideAttribute("can_use_superbird", TRUE, false),
|
||||
// Removes the premium button in the nav-bar for tablet users.
|
||||
new OverrideAttribute("tablet-free", FALSE, false)
|
||||
);
|
||||
|
||||
/**
|
||||
* Injection point.
|
||||
*/
|
||||
public static void overrideAttribute(Map<String, AccountAttribute> attributes) {
|
||||
try {
|
||||
for (var entry : OVERRIDES.entrySet()) {
|
||||
var key = entry.getKey();
|
||||
var attribute = attributes.get(key);
|
||||
for (var override : OVERRIDES) {
|
||||
var attribute = attributes.get(override.key);
|
||||
if (attribute == null) {
|
||||
Logger.printException(() -> "Account attribute not found: " + key);
|
||||
if (override.isExpected) {
|
||||
Logger.printException(() -> "''" + override.key + "' expected but not found");
|
||||
}
|
||||
} else {
|
||||
attribute.value_ = entry.getValue();
|
||||
attribute.value_ = override.overrideValue;
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user