generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(YouTube): Add
Change default audio track
patch
- Loading branch information
1 parent
b0cde78
commit 9fe88b9
Showing
15 changed files
with
470 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...src/main/java/app/revanced/extension/youtube/patches/ChangeDefaultAudioLanguagePatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package app.revanced.extension.youtube.patches; | ||
|
||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import app.revanced.extension.shared.Logger; | ||
import app.revanced.extension.shared.spoof.AudioStreamLanguage; | ||
import app.revanced.extension.youtube.settings.Settings; | ||
|
||
@SuppressWarnings("unused") | ||
public class ChangeDefaultAudioLanguagePatch { | ||
|
||
private static final String DEFAULT_AUDIO_TRACKS_IDENTIFIER = "original"; | ||
|
||
/** | ||
* Audio track identifier. | ||
* | ||
* Examples: | ||
* fr-FR.10 | ||
* it.10 | ||
*/ | ||
private static final Pattern AUDIO_TRACK_ID_PATTERN = | ||
Pattern.compile("^([a-z]{2})(-[A-Z]{2})?(\\.\\d+)"); | ||
|
||
private static void printDebug(Logger.LogMessage message) { | ||
// Do not log by default as it's spammy. | ||
final boolean logAudioStreams = false; | ||
|
||
//noinspection ConstantConditions | ||
if (logAudioStreams) { | ||
Logger.printDebug(message); | ||
} | ||
} | ||
|
||
/** | ||
* Injection point. | ||
*/ | ||
public static boolean setAudioStreamAsDefault(boolean isDefault, String audioTrackId, String audioTrackDisplayName) { | ||
try { | ||
AudioStreamLanguage defaultLanguage = Settings.AUDIO_DEFAULT_LANGUAGE.get(); | ||
if (defaultLanguage == AudioStreamLanguage.DEFAULT) { | ||
return isDefault; // Do nothing. | ||
} | ||
|
||
printDebug(() -> "isDefault: " + isDefault + " audioTrackId: " + audioTrackId | ||
+ " audioTrackDisplayName:" + audioTrackDisplayName); | ||
|
||
if (defaultLanguage == AudioStreamLanguage.ORIGINAL) { | ||
final boolean isOriginal = audioTrackDisplayName.contains(DEFAULT_AUDIO_TRACKS_IDENTIFIER); | ||
if (isOriginal) { | ||
printDebug(() -> "Using original audio language: " + audioTrackId); | ||
} | ||
|
||
return isOriginal; | ||
} | ||
|
||
Matcher matcher = AUDIO_TRACK_ID_PATTERN.matcher(audioTrackId); | ||
if (!matcher.matches()) { | ||
Logger.printException(() -> "Cannot set default audio, unknown track: " + audioTrackId); | ||
return isDefault; | ||
} | ||
|
||
String desiredIso639 = defaultLanguage.getIso639_1(); | ||
if (desiredIso639.equals(matcher.group(1)) | ||
|| desiredIso639.equals(matcher.group(2))) { | ||
printDebug(() -> "Using preferred audio language: " + audioTrackId); | ||
return true; | ||
} | ||
} catch (Exception ex) { | ||
Logger.printException(() -> "setAudioStreamAsDefault failure", ex); | ||
} | ||
|
||
return isDefault; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
patches/src/main/kotlin/app/revanced/patches/music/misc/spoof/SpoofVideoStreamsPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,7 @@ | ||
package app.revanced.patches.music.misc.spoof | ||
|
||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction | ||
import app.revanced.patches.music.misc.gms.musicActivityOnCreateFingerprint | ||
import app.revanced.patches.shared.misc.spoof.EXTENSION_CLASS_DESCRIPTOR | ||
import app.revanced.patches.shared.misc.spoof.spoofVideoStreamsPatch | ||
|
||
val spoofVideoStreamsPatch = spoofVideoStreamsPatch({ | ||
compatibleWith("com.google.android.apps.youtube.music") | ||
}, { | ||
musicActivityOnCreateFingerprint.method.addInstruction( | ||
0, | ||
"invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->setClientTypeToAndroidVrNoHl()V" | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.