From 48d897e6ad1643e24f0e1a943988d7b31abce30a Mon Sep 17 00:00:00 2001 From: XiangRongLin <41164160+XiangRongLin@users.noreply.github.com> Date: Thu, 29 Jul 2021 21:33:45 +0200 Subject: [PATCH] Add final and adjust utils class name --- .../youtube/YoutubeThrottlingDecrypter.java | 4 ++-- .../org/schabi/newpipe/extractor/utils/Parser.java | 6 +++--- .../utils/{StringUtil.java => StringUtils.java} | 13 +++++++------ .../youtube/YoutubeThrottlingDecrypterTest.java | 4 ++-- 4 files changed, 14 insertions(+), 13 deletions(-) rename extractor/src/main/java/org/schabi/newpipe/extractor/utils/{StringUtil.java => StringUtils.java} (76%) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingDecrypter.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingDecrypter.java index 8de3ac983..fb56e2c7b 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingDecrypter.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingDecrypter.java @@ -3,7 +3,7 @@ package org.schabi.newpipe.extractor.services.youtube; import org.schabi.newpipe.extractor.exceptions.ParsingException; import org.schabi.newpipe.extractor.utils.JavaScript; import org.schabi.newpipe.extractor.utils.Parser; -import org.schabi.newpipe.extractor.utils.StringUtil; +import org.schabi.newpipe.extractor.utils.StringUtils; import javax.annotation.Nonnull; import java.util.HashMap; @@ -81,7 +81,7 @@ public class YoutubeThrottlingDecrypter { private String parseWithParenthesisMatching(final String playerJsCode, final String functionName) { final String functionBase = functionName + "=function"; - return functionBase + StringUtil.matchToClosingParenthesis(playerJsCode, functionBase) + ";"; + return functionBase + StringUtils.matchToClosingParenthesis(playerJsCode, functionBase) + ";"; } private String parseWithRegex(final String playerJsCode, final String functionName) throws Parser.RegexException { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Parser.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Parser.java index 0a766fd16..5b25ed760 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Parser.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/Parser.java @@ -79,13 +79,13 @@ public class Parser { } public static boolean isMatch(String pattern, String input) { - Pattern pat = Pattern.compile(pattern); - Matcher mat = pat.matcher(input); + final Pattern pat = Pattern.compile(pattern); + final Matcher mat = pat.matcher(input); return mat.find(); } public static boolean isMatch(Pattern pattern, String input) { - Matcher mat = pattern.matcher(input); + final Matcher mat = pattern.matcher(input); return mat.find(); } diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/StringUtil.java b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/StringUtils.java similarity index 76% rename from extractor/src/main/java/org/schabi/newpipe/extractor/utils/StringUtil.java rename to extractor/src/main/java/org/schabi/newpipe/extractor/utils/StringUtils.java index 42f8d9623..3f0af27cf 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/utils/StringUtil.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/utils/StringUtils.java @@ -1,20 +1,21 @@ package org.schabi.newpipe.extractor.utils; -import edu.umd.cs.findbugs.annotations.NonNull; -public class StringUtil { +import javax.annotation.Nonnull; - private StringUtil() { +public class StringUtils { + + private StringUtils() { } /** * @param string The string to search in * @param start A string from which to start searching. * @return A substring where each '{' matches a '}' - * @throws IndexOutOfBoundsException If {@ string} does not contain {@code start} + * @throws IndexOutOfBoundsException If {@code string} does not contain {@code start} */ - @NonNull - public static String matchToClosingParenthesis(@NonNull final String string, @NonNull final String start) { + @Nonnull + public static String matchToClosingParenthesis(@Nonnull final String string, @Nonnull final String start) { int startIndex = string.indexOf(start); if (startIndex < 0) { throw new IndexOutOfBoundsException(); diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingDecrypterTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingDecrypterTest.java index 4a87245ec..5d107594c 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingDecrypterTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/youtube/YoutubeThrottlingDecrypterTest.java @@ -23,11 +23,11 @@ public class YoutubeThrottlingDecrypterTest { @Test public void testExtractFunction__success() throws ParsingException { - String[] videoIds = {"jE1USQrs1rw", "CqxjzfudGAc", "goH-9MfQI7w", "KYIdr_7H5Yw", "J1WeqmGbYeI"}; + final String[] videoIds = {"jE1USQrs1rw", "CqxjzfudGAc", "goH-9MfQI7w", "KYIdr_7H5Yw", "J1WeqmGbYeI"}; final String encryptedUrl = "https://r6---sn-4g5ednek.googlevideo.com/videoplayback?expire=1626562120&ei=6AnzYO_YBpql1gLGkb_IBQ&ip=127.0.0.1&id=o-ANhBEf36Z5h-8U9DDddtPDqtS0ZNwf0XJAAigudKI2uI&itag=278&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278&source=youtube&requiressl=yes&vprv=1&mime=video%2Fwebm&ns=TvecOReN0vPuXb3j_zq157IG&gir=yes&clen=2915100&dur=270.203&lmt=1608157174907785&keepalive=yes&fexp=24001373,24007246&c=WEB&txp=5535432&n=N9BWSTFT7vvBJrvQ&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cvprv%2Cmime%2Cns%2Cgir%2Cclen%2Cdur%2Clmt&alr=yes&sig=AOq0QJ8wRQIgW6XnUDKPDSxiT0_KE_tDDMpcaCJl2Un5p0Fu9qZNQGkCIQDWxsDHi_s2BEmRqIbd1C5g_gzfihB7RZLsScKWNMwzzA%3D%3D&cpn=9r2yt3BqcYmeb2Yu&cver=2.20210716.00.00&redirect_counter=1&cm2rm=sn-4g5ezy7s&cms_redirect=yes&mh=Y5&mm=34&mn=sn-4g5ednek&ms=ltu&mt=1626540524&mv=m&mvi=6&pl=43&lsparams=mh,mm,mn,ms,mv,mvi,pl&lsig=AG3C_xAwRQIhAIUzxTn9Vw1-vm-_7OQ5-0h1M6AZsY9Bx1FlCCTeMICzAiADtGggbn4Znsrh2EnvyOsGnYdRGcbxn4mW9JMOQiInDQ%3D%3D&range=259165-480735&rn=11&rbuf=20190"; - for (String videoId : videoIds) { + for (final String videoId : videoIds) { try { final String decryptedUrl = new YoutubeThrottlingDecrypter(videoId).apply(encryptedUrl); assertNotEquals(encryptedUrl, decryptedUrl);