From 4c3918ac4cb4f8290ee07e9eb2e6728cb9f754d1 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Wed, 12 Feb 2025 22:09:03 +0100 Subject: [PATCH] Removed unused code --- .../youtube/YoutubeParsingHelper.java | 18 ----- .../newpipe/extractor/utils/ProtoBuilder.java | 73 ------------------- .../extractor/utils/ProtoBuilderTest.java | 18 ----- 3 files changed, 109 deletions(-) delete mode 100644 extractor/src/main/java/org/schabi/newpipe/extractor/utils/ProtoBuilder.java delete mode 100644 extractor/src/test/java/org/schabi/newpipe/extractor/utils/ProtoBuilderTest.java diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java index 0a1c7865b..55d08cf91 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeParsingHelper.java @@ -60,7 +60,6 @@ import org.schabi.newpipe.extractor.playlist.PlaylistInfo; import org.schabi.newpipe.extractor.stream.AudioTrackType; import org.schabi.newpipe.extractor.utils.JsonUtils; import org.schabi.newpipe.extractor.utils.Parser; -import org.schabi.newpipe.extractor.utils.ProtoBuilder; import org.schabi.newpipe.extractor.utils.RandomStringFromAlphabetGenerator; import org.schabi.newpipe.extractor.utils.Utils; @@ -235,23 +234,6 @@ public final class YoutubeParsingHelper { return url.getHost().equalsIgnoreCase("y2u.be"); } - public static String randomVisitorData(final ContentCountry country) { - final ProtoBuilder pbE2 = new ProtoBuilder(); - pbE2.string(2, ""); - pbE2.varint(4, numberGenerator.nextInt(255) + 1); - - final ProtoBuilder pbE = new ProtoBuilder(); - pbE.string(1, country.getCountryCode()); - pbE.bytes(2, pbE2.toBytes()); - - final ProtoBuilder pb = new ProtoBuilder(); - pb.string(1, RandomStringFromAlphabetGenerator.generate( - CONTENT_PLAYBACK_NONCE_ALPHABET, 11, numberGenerator)); - pb.varint(5, System.currentTimeMillis() / 1000 - numberGenerator.nextInt(600000)); - pb.bytes(6, pbE.toBytes()); - return pb.toUrlencodedBase64(); - } - /** * Parses the duration string of the video expecting ":" or "." as separators * diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/ProtoBuilder.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/ProtoBuilder.java deleted file mode 100644 index 0ced5bed2..000000000 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/ProtoBuilder.java +++ /dev/null @@ -1,73 +0,0 @@ -package org.schabi.newpipe.extractor.utils; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; -import java.util.Base64; - -public class ProtoBuilder { - ByteArrayOutputStream byteBuffer; - - public ProtoBuilder() { - this.byteBuffer = new ByteArrayOutputStream(); - } - - public byte[] toBytes() { - return byteBuffer.toByteArray(); - } - - public String toUrlencodedBase64() { - final String b64 = Base64.getUrlEncoder().encodeToString(toBytes()); - return URLEncoder.encode(b64, StandardCharsets.UTF_8); - } - - private void writeVarint(final long val) { - try { - if (val == 0) { - byteBuffer.write(new byte[]{(byte) 0}); - } else { - long v = val; - while (v != 0) { - byte b = (byte) (v & 0x7f); - v >>= 7; - - if (v != 0) { - b |= (byte) 0x80; - } - byteBuffer.write(new byte[]{b}); - } - } - } catch (final IOException e) { - throw new UncheckedIOException(e); - } - } - - private void field(final int field, final byte wire) { - final long fbits = ((long) field) << 3; - final long wbits = ((long) wire) & 0x07; - final long val = fbits | wbits; - writeVarint(val); - } - - public void varint(final int field, final long val) { - field(field, (byte) 0); - writeVarint(val); - } - - public void string(final int field, final String string) { - final byte[] strBts = string.getBytes(StandardCharsets.UTF_8); - bytes(field, strBts); - } - - public void bytes(final int field, final byte[] bytes) { - field(field, (byte) 2); - writeVarint(bytes.length); - try { - byteBuffer.write(bytes); - } catch (final IOException e) { - throw new UncheckedIOException(e); - } - } -} diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/utils/ProtoBuilderTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/utils/ProtoBuilderTest.java deleted file mode 100644 index b39879451..000000000 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/utils/ProtoBuilderTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.schabi.newpipe.extractor.utils; - -import org.junit.jupiter.api.Test; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class ProtoBuilderTest { - @Test - public void testProtoBuilder() { - final ProtoBuilder pb = new ProtoBuilder(); - pb.varint(1, 128); - pb.varint(2, 1234567890); - pb.varint(3, 1234567890123456789L); - pb.string(4, "Hello"); - pb.bytes(5, new byte[]{1, 2, 3}); - assertEquals("CIABENKF2MwEGJWCpu_HnoSRESIFSGVsbG8qAwECAw%3D%3D", pb.toUrlencodedBase64()); - } -}