From fbee94e53f4960d726b858ade5025af260969bf4 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Thu, 12 Dec 2024 17:47:51 +0530 Subject: [PATCH] Fix all checkstyle issues. --- .../services/youtube/PoTokenProvider.java | 4 +- .../services/youtube/YoutubeStreamHelper.java | 34 ++++++++---- .../extractors/YoutubeStreamExtractor.java | 52 +++++++++++++------ 3 files changed, 61 insertions(+), 29 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/PoTokenProvider.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/PoTokenProvider.java index 13323184c..3faff9c3f 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/PoTokenProvider.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/PoTokenProvider.java @@ -5,7 +5,6 @@ import javax.annotation.Nullable; /** * An interface to provide poTokens to YouTube player requests. * - * @implNote This interface is expected to be thread-safe, as it may be accessed by multiple threads. * *
* On some major clients, YouTube requires that the integrity of the device passes some checks to @@ -21,6 +20,9 @@ import javax.annotation.Nullable; *
* These tokens may have a role in triggering the sign in requirement. *
+ * + * @implNote This interface is expected to be thread-safe, + * as it may be accessed by multiple threads. */ public interface PoTokenProvider { diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamHelper.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamHelper.java index 30a7049d3..98d17591c 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamHelper.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/YoutubeStreamHelper.java @@ -64,7 +64,11 @@ public final class YoutubeStreamHelper { @Nonnull final String videoId, @Nonnull final PoTokenResult webPoTokenResult) throws IOException, ExtractionException { final byte[] body = JsonWriter.string( - prepareDesktopJsonBuilder(localization, contentCountry, webPoTokenResult.visitorData) + prepareDesktopJsonBuilder( + localization, + contentCountry, + webPoTokenResult.visitorData + ) .value(VIDEO_ID, videoId) .value(CONTENT_CHECK_OK, true) .value(RACY_CHECK_OK, true) @@ -80,14 +84,20 @@ public final class YoutubeStreamHelper { url, getYouTubeHeaders(), body, localization))); } - public static JsonObject getAndroidPlayerResponse(@Nonnull final ContentCountry contentCountry, - @Nonnull final Localization localization, - @Nonnull final String videoId, - @Nonnull final String androidCpn, - @Nonnull final PoTokenResult androidPoTokenResult) + public static JsonObject getAndroidPlayerResponse( + @Nonnull final ContentCountry contentCountry, + @Nonnull final Localization localization, + @Nonnull final String videoId, + @Nonnull final String androidCpn, + @Nonnull final PoTokenResult androidPoTokenResult + ) throws IOException, ExtractionException { final byte[] mobileBody = JsonWriter.string( - prepareAndroidMobileJsonBuilder(localization, contentCountry, androidPoTokenResult.visitorData) + prepareAndroidMobileJsonBuilder( + localization, + contentCountry, + androidPoTokenResult.visitorData + ) .value(VIDEO_ID, videoId) .value(CPN, androidCpn) .value(CONTENT_CHECK_OK, true) @@ -105,10 +115,12 @@ public final class YoutubeStreamHelper { "&t=" + generateTParameter() + "&id=" + videoId); } - public static JsonObject getAndroidReelPlayerResponse(@Nonnull final ContentCountry contentCountry, - @Nonnull final Localization localization, - @Nonnull final String videoId, - @Nonnull final String androidCpn) + public static JsonObject getAndroidReelPlayerResponse( + @Nonnull final ContentCountry contentCountry, + @Nonnull final Localization localization, + @Nonnull final String videoId, + @Nonnull final String androidCpn + ) throws IOException, ExtractionException { final byte[] mobileBody = JsonWriter.string( prepareAndroidMobileJsonBuilder(localization, contentCountry, null) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java index ac60cd10a..68705c7a2 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java @@ -45,14 +45,27 @@ import org.schabi.newpipe.extractor.MetaInfo; import org.schabi.newpipe.extractor.MultiInfoItemsCollector; import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.downloader.Downloader; -import org.schabi.newpipe.extractor.exceptions.*; +import org.schabi.newpipe.extractor.exceptions.AgeRestrictedContentException; +import org.schabi.newpipe.extractor.exceptions.ContentNotAvailableException; +import org.schabi.newpipe.extractor.exceptions.ExtractionException; +import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException; +import org.schabi.newpipe.extractor.exceptions.PaidContentException; +import org.schabi.newpipe.extractor.exceptions.ParsingException; +import org.schabi.newpipe.extractor.exceptions.PrivateContentException; +import org.schabi.newpipe.extractor.exceptions.YoutubeMusicPremiumContentException; import org.schabi.newpipe.extractor.linkhandler.LinkHandler; import org.schabi.newpipe.extractor.localization.ContentCountry; import org.schabi.newpipe.extractor.localization.DateWrapper; import org.schabi.newpipe.extractor.localization.Localization; import org.schabi.newpipe.extractor.localization.TimeAgoParser; import org.schabi.newpipe.extractor.localization.TimeAgoPatternsManager; -import org.schabi.newpipe.extractor.services.youtube.*; +import org.schabi.newpipe.extractor.services.youtube.ItagItem; +import org.schabi.newpipe.extractor.services.youtube.PoTokenProvider; +import org.schabi.newpipe.extractor.services.youtube.PoTokenResult; +import org.schabi.newpipe.extractor.services.youtube.YoutubeJavaScriptPlayerManager; +import org.schabi.newpipe.extractor.services.youtube.YoutubeMetaInfoHelper; +import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper; +import org.schabi.newpipe.extractor.services.youtube.YoutubeStreamHelper; import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory; import org.schabi.newpipe.extractor.stream.AudioStream; import org.schabi.newpipe.extractor.stream.DeliveryMethod; @@ -792,9 +805,9 @@ public class YoutubeStreamExtractor extends StreamExtractor { throw new ExtractionException("IOS player response is not valid"); } - final JsonObject iosStreamingData = iosPlayerResponse.getObject(STREAMING_DATA); - if (!isNullOrEmpty(iosStreamingData)) { - this.iosStreamingData = iosStreamingData; + final JsonObject iosStreamingDataLocal = iosPlayerResponse.getObject(STREAMING_DATA); + if (!isNullOrEmpty(iosStreamingDataLocal)) { + this.iosStreamingData = iosStreamingDataLocal; if (!forceFetchIosClient) { playerCaptionsTracklistRenderer = iosPlayerResponse.getObject("captions") .getObject("playerCaptionsTracklistRenderer"); @@ -839,7 +852,9 @@ public class YoutubeStreamExtractor extends StreamExtractor { throw new PrivateContentException("This video is private."); } } else if (reason.contains("age")) { - throw new AgeRestrictedContentException("Age-restricted videos cannot be watched anonymously"); + throw new AgeRestrictedContentException( + "Age-restricted videos cannot be watched anonymously" + ); } } @@ -877,7 +892,8 @@ public class YoutubeStreamExtractor extends StreamExtractor { private void fetchWebClient(@Nonnull final Localization localization, @Nonnull final ContentCountry contentCountry, @Nonnull final String videoId, - @Nullable final PoTokenResult webPoTokenResult) throws IOException, ExtractionException { + @Nullable final PoTokenResult webPoTokenResult + ) throws IOException, ExtractionException { final JsonObject webPlayerResponse; if (webPoTokenResult == null) { webPlayerResponse = YoutubeStreamHelper.getWebMetadataPlayerResponse( @@ -927,10 +943,10 @@ public class YoutubeStreamExtractor extends StreamExtractor { } if (!isPlayerResponseNotValid(androidPlayerResponse, videoId)) { - final JsonObject androidStreamingData = + final JsonObject androidStreamingDataLocal = androidPlayerResponse.getObject(STREAMING_DATA); - if (!isNullOrEmpty(androidStreamingData)) { - this.androidStreamingData = androidStreamingData; + if (!isNullOrEmpty(androidStreamingDataLocal)) { + this.androidStreamingData = androidStreamingDataLocal; if (isNullOrEmpty(playerCaptionsTracklistRenderer)) { playerCaptionsTracklistRenderer = androidPlayerResponse.getObject("captions") @@ -1519,9 +1535,10 @@ public class YoutubeStreamExtractor extends StreamExtractor { * Sets the {@link PoTokenProvider} instance to be used for fetching poTokens. * *- * This method allows setting an implementation of {@link PoTokenProvider} which will be used - * to obtain poTokens required for YouTube player requests. These tokens are used by YouTube to verify the - * integrity of the device and may be necessary for playback at times. + * This method allows setting an implementation of {@link PoTokenProvider} which will + * be used to obtain poTokens required for YouTube player requests. These tokens are + * used by YouTube to verify the integrity of the device and may be necessary for + * playback at times. *
* * @param poTokenProvider the {@link PoTokenProvider} instance to set @@ -1535,13 +1552,14 @@ public class YoutubeStreamExtractor extends StreamExtractor { * ** This method allows setting a flag to force the fetching of the iOS player response, even if a - * valid webPoTokenResult is available. This can be useful in scenarios where streams from the iOS player - * response is preferred. + * valid webPoTokenResult is available. This can be useful in scenarios where streams from the + * iOS player response is preferred. *
* - * @param forceFetchIosClient a boolean flag indicating whether to force fetch the iOS player response + * @param forceFetchIosClient a boolean flag indicating whether to force fetch the iOS + * player response */ - public static void setForceFetchIosClient(boolean forceFetchIosClient) { + public static void setForceFetchIosClient(final boolean forceFetchIosClient) { YoutubeStreamExtractor.forceFetchIosClient = forceFetchIosClient; } }