mirror of
https://github.com/revanced/revanced-integrations.git
synced 2025-01-17 23:37:32 +01:00
fix(youtube/spoof-signature-verification): additional fixes for subtitle window positions (#369)
This commit is contained in:
parent
cb7063b2b3
commit
6f2ae313cf
@ -1,12 +1,15 @@
|
|||||||
package app.revanced.integrations.patches;
|
package app.revanced.integrations.patches;
|
||||||
|
|
||||||
|
import static app.revanced.integrations.utils.ReVancedUtils.containsAny;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import app.revanced.integrations.settings.SettingsEnum;
|
import app.revanced.integrations.settings.SettingsEnum;
|
||||||
import app.revanced.integrations.shared.PlayerType;
|
import app.revanced.integrations.shared.PlayerType;
|
||||||
import app.revanced.integrations.utils.LogHelper;
|
import app.revanced.integrations.utils.LogHelper;
|
||||||
import app.revanced.integrations.utils.ReVancedUtils;
|
import app.revanced.integrations.utils.ReVancedUtils;
|
||||||
|
|
||||||
import static app.revanced.integrations.utils.ReVancedUtils.containsAny;
|
|
||||||
|
|
||||||
public class SpoofSignatureVerificationPatch {
|
public class SpoofSignatureVerificationPatch {
|
||||||
/**
|
/**
|
||||||
* Protobuf parameters used for autoplay in scrim.
|
* Protobuf parameters used for autoplay in scrim.
|
||||||
@ -28,6 +31,14 @@ public class SpoofSignatureVerificationPatch {
|
|||||||
"SAFg" // Autoplay in scrim
|
"SAFg" // Autoplay in scrim
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static String currentVideoId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If any of the subtitles settings encountered from the current video have been non default values.
|
||||||
|
*/
|
||||||
|
private static boolean nonDefaultSubtitlesEncountered;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Injection point.
|
* Injection point.
|
||||||
*
|
*
|
||||||
@ -49,7 +60,7 @@ public class SpoofSignatureVerificationPatch {
|
|||||||
if (isPlayingFeed) {
|
if (isPlayingFeed) {
|
||||||
// Videos in feed won't autoplay with sound.
|
// Videos in feed won't autoplay with sound.
|
||||||
return PROTOBUF_PARAMETER_SCRIM + PROTOBUF_PARAMETER_SHORTS;
|
return PROTOBUF_PARAMETER_SCRIM + PROTOBUF_PARAMETER_SHORTS;
|
||||||
} else{
|
} else {
|
||||||
// Spoof the parameter to prevent playback issues.
|
// Spoof the parameter to prevent playback issues.
|
||||||
return PROTOBUF_PARAMETER_SHORTS;
|
return PROTOBUF_PARAMETER_SHORTS;
|
||||||
}
|
}
|
||||||
@ -121,21 +132,40 @@ public class SpoofSignatureVerificationPatch {
|
|||||||
// Videos with custom captions that specify screen positions appear to always have correct screen positions (even with spoofing).
|
// Videos with custom captions that specify screen positions appear to always have correct screen positions (even with spoofing).
|
||||||
// But for auto generated and most other captions, the spoof incorrectly gives various default Shorts caption settings.
|
// But for auto generated and most other captions, the spoof incorrectly gives various default Shorts caption settings.
|
||||||
// Check for these known default shorts captions parameters, and replace with the known correct values.
|
// Check for these known default shorts captions parameters, and replace with the known correct values.
|
||||||
if (signatureSpoofing && !PlayerType.getCurrent().isNoneOrHidden()) { // video is not a Short or Story
|
//
|
||||||
|
// If a regular video uses a custom subtitle setting that match a default short setting,
|
||||||
|
// then this will incorrectly replace the setting.
|
||||||
|
// But, if the video uses multiple subtitles in different screen locations, then detect the non-default values
|
||||||
|
// and do not replace any window settings for the video (regardless if they match a shorts default).
|
||||||
|
if (signatureSpoofing && !nonDefaultSubtitlesEncountered && !PlayerType.getCurrent().isNoneOrHidden()) {
|
||||||
for (SubtitleWindowReplacementSettings setting : SubtitleWindowReplacementSettings.values()) {
|
for (SubtitleWindowReplacementSettings setting : SubtitleWindowReplacementSettings.values()) {
|
||||||
if (setting.match(ap, ah, av, vs, sd)) {
|
if (setting.match(ap, ah, av, vs, sd)) {
|
||||||
return setting.replacementSetting();
|
return setting.replacementSetting();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Parameters are either subtitles with custom positions, or a set of unidentified (and incorrect) default parameters.
|
// Settings appear to be custom subtitles.
|
||||||
// The subtitles could be forced to the bottom no matter what, but that would override custom screen positions.
|
nonDefaultSubtitlesEncountered = true;
|
||||||
// For now, just return the original parameters.
|
LogHelper.printDebug(() -> "Non default subtitles found. Using existing settings without replacement.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// No matches, pass back the original values
|
|
||||||
return new int[]{ap, ah, av};
|
return new int[]{ap, ah, av};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injection point.
|
||||||
|
*/
|
||||||
|
public static void setCurrentVideoId(@NonNull String videoId) {
|
||||||
|
try {
|
||||||
|
if (videoId.equals(currentVideoId)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
currentVideoId = videoId;
|
||||||
|
nonDefaultSubtitlesEncountered = false;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
LogHelper.printException(() -> "setCurrentVideoId failure", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Known incorrect default Shorts subtitle parameters, and the corresponding correct (non-Shorts) values.
|
* Known incorrect default Shorts subtitle parameters, and the corresponding correct (non-Shorts) values.
|
||||||
@ -152,8 +182,8 @@ public class SpoofSignatureVerificationPatch {
|
|||||||
final int ap, ah, av;
|
final int ap, ah, av;
|
||||||
final boolean vs, sd;
|
final boolean vs, sd;
|
||||||
|
|
||||||
// replacement values
|
// replacement int values
|
||||||
final int replacementAp, replacementAh, replacementAv;
|
final int[] replacement;
|
||||||
|
|
||||||
SubtitleWindowReplacementSettings(int ap, int ah, int av, boolean vs, boolean sd,
|
SubtitleWindowReplacementSettings(int ap, int ah, int av, boolean vs, boolean sd,
|
||||||
int replacementAp, int replacementAh, int replacementAv) {
|
int replacementAp, int replacementAh, int replacementAv) {
|
||||||
@ -162,9 +192,7 @@ public class SpoofSignatureVerificationPatch {
|
|||||||
this.av = av;
|
this.av = av;
|
||||||
this.vs = vs;
|
this.vs = vs;
|
||||||
this.sd = sd;
|
this.sd = sd;
|
||||||
this.replacementAp = replacementAp;
|
this.replacement = new int[]{replacementAp, replacementAh, replacementAv};
|
||||||
this.replacementAh = replacementAh;
|
|
||||||
this.replacementAv = replacementAv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean match(int ap, int ah, int av, boolean vs, boolean sd) {
|
boolean match(int ap, int ah, int av, boolean vs, boolean sd) {
|
||||||
@ -172,7 +200,7 @@ public class SpoofSignatureVerificationPatch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int[] replacementSetting() {
|
int[] replacementSetting() {
|
||||||
return new int[]{replacementAp, replacementAh, replacementAv};
|
return replacement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user