Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
fix(YouTube/Shorts components): app crashes when `Replace channel han…
Browse files Browse the repository at this point in the history
…dle` setting is turned on
  • Loading branch information
inotia00 committed Oct 20, 2024
1 parent 18f72a6 commit 284e5e3
Showing 1 changed file with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@

@SuppressWarnings({"unused", "CharsetObjectCanBeUsed"})
public final class ReturnYouTubeChannelNameFilterPatch extends Filter {
private static final String DELIMITING_CHARACTER = "❙";
private static final String CHANNEL_ID_IDENTIFIER_CHARACTER = "UC";
private static final String CHANNEL_ID_IDENTIFIER_WITH_DELIMITING_CHARACTER =
DELIMITING_CHARACTER + CHANNEL_ID_IDENTIFIER_CHARACTER;
private static final String HANDLE_IDENTIFIER_CHARACTER = "@";
private static final String HANDLE_IDENTIFIER_WITH_DELIMITING_CHARACTER =
HANDLE_IDENTIFIER_CHARACTER + CHANNEL_ID_IDENTIFIER_CHARACTER;

private final ByteArrayFilterGroupList shortsChannelBarAvatarFilterGroup = new ByteArrayFilterGroupList();

public ReturnYouTubeChannelNameFilterPatch() {
Expand All @@ -37,16 +45,27 @@ public boolean isFiltered(String path, @Nullable String identifier, String allVa

private void setLastShortsChannelId(byte[] protobufBufferArray) {
try {
final String delimitingCharacter = "❙"; // Non ascii character, to allow easier log filtering.
final String channelIdIdentifierCharacter = "UC";
final String channelIdIdentifierWithDelimitingCharacter = "❙UC";
final String handleIdentifierCharacter = "@";
final String handleIdentifierWithDelimitingCharacter = "❙/@";

String[] splitArr;
final String bufferString = findAsciiStrings(protobufBufferArray);
final String splitedBufferString = channelIdIdentifierCharacter + bufferString.split(channelIdIdentifierWithDelimitingCharacter)[1];
final String cachedHandle = handleIdentifierCharacter + splitedBufferString.split(handleIdentifierWithDelimitingCharacter)[1].split(delimitingCharacter)[0];
final String channelId = splitedBufferString.split(delimitingCharacter)[0].replaceAll("\"", "").trim();
splitArr = bufferString.split(CHANNEL_ID_IDENTIFIER_WITH_DELIMITING_CHARACTER);
if (splitArr.length < 2) {
return;
}
final String splitedBufferString = CHANNEL_ID_IDENTIFIER_CHARACTER + splitArr[1];
splitArr = splitedBufferString.split(HANDLE_IDENTIFIER_WITH_DELIMITING_CHARACTER);
if (splitArr.length < 2) {
return;
}
splitArr = splitArr[1].split(DELIMITING_CHARACTER);
if (splitArr.length < 1) {
return;
}
final String cachedHandle = HANDLE_IDENTIFIER_CHARACTER + splitArr[0];
splitArr = splitedBufferString.split(DELIMITING_CHARACTER);
if (splitArr.length < 1) {
return;
}
final String channelId = splitArr[0].replaceAll("\"", "").trim();
final String handle = URLDecoder.decode(cachedHandle, "UTF-8").trim();

ReturnYouTubeChannelNamePatch.setLastShortsChannelId(handle, channelId);
Expand Down

0 comments on commit 284e5e3

Please sign in to comment.