mirror of
https://github.com/revanced/revanced-patches.git
synced 2025-05-02 15:44:39 +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;
|
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 com.spotify.remoteconfig.internal.AccountAttribute;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import app.revanced.extension.shared.Logger;
|
import app.revanced.extension.shared.Logger;
|
||||||
|
|
||||||
/**
|
@SuppressWarnings("unused")
|
||||||
* @noinspection unused
|
|
||||||
*/
|
|
||||||
public final class UnlockPremiumPatch {
|
public final class UnlockPremiumPatch {
|
||||||
|
|
||||||
private static final Map<String, Object> OVERRIDES = new HashMap<>() {{
|
private static class OverrideAttribute {
|
||||||
// Disables player and app ads.
|
/**
|
||||||
put("ads", false);
|
* Account attribute key.
|
||||||
// Works along on-demand, allows playing any song without restriction.
|
*/
|
||||||
put("player-license", "premium");
|
final String key;
|
||||||
// Disables shuffle being initially enabled when first playing a playlist.
|
|
||||||
put("shuffle", false);
|
/**
|
||||||
// Allows playing any song on-demand, without a shuffled order.
|
* Override value.
|
||||||
put("on-demand", true);
|
*/
|
||||||
// Make sure playing songs is not disabled remotely and playlists show up.
|
final Object overrideValue;
|
||||||
put("streaming", true);
|
|
||||||
// Allows adding songs to queue and removes the smart shuffle mode restriction,
|
/**
|
||||||
// allowing to pick any of the other modes.
|
* If this attribute is expected to be present in all situations.
|
||||||
put("pick-and-shuffle", false);
|
* If false, then no error is raised if the attribute is missing.
|
||||||
// Disables shuffle-mode streaming-rule, which forces songs to be played shuffled
|
*/
|
||||||
// and breaks the player when other patches are applied.
|
final boolean isExpected;
|
||||||
put("streaming-rules", "");
|
|
||||||
// Enables premium UI in settings and removes the premium button in the nav-bar.
|
OverrideAttribute(String key, Object overrideValue) {
|
||||||
put("nft-disabled", "1");
|
this(key, overrideValue, true);
|
||||||
// Enable Cross-Platform Spotify Car Thing.
|
}
|
||||||
put("can_use_superbird", true);
|
|
||||||
// Removes the premium button in the nav-bar for tablet users.
|
OverrideAttribute(String key, Object overrideValue, boolean isExpected) {
|
||||||
put("tablet-free", false);
|
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.
|
* Injection point.
|
||||||
*/
|
*/
|
||||||
public static void overrideAttribute(Map<String, AccountAttribute> attributes) {
|
public static void overrideAttribute(Map<String, AccountAttribute> attributes) {
|
||||||
try {
|
try {
|
||||||
for (var entry : OVERRIDES.entrySet()) {
|
for (var override : OVERRIDES) {
|
||||||
var key = entry.getKey();
|
var attribute = attributes.get(override.key);
|
||||||
var attribute = attributes.get(key);
|
|
||||||
if (attribute == null) {
|
if (attribute == null) {
|
||||||
Logger.printException(() -> "Account attribute not found: " + key);
|
if (override.isExpected) {
|
||||||
|
Logger.printException(() -> "''" + override.key + "' expected but not found");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
attribute.value_ = entry.getValue();
|
attribute.value_ = override.overrideValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user