Fix all checkstyle issues.

This commit is contained in:
Kavin 2024-12-12 17:47:51 +05:30
parent 6f88ce659f
commit fbee94e53f
No known key found for this signature in database
GPG Key ID: 6E4598CA5C92C41F
3 changed files with 61 additions and 29 deletions

View File

@ -5,7 +5,6 @@ import javax.annotation.Nullable;
/** /**
* An interface to provide poTokens to YouTube player requests. * 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.
* *
* <p> * <p>
* On some major clients, YouTube requires that the integrity of the device passes some checks to * On some major clients, YouTube requires that the integrity of the device passes some checks to
@ -21,6 +20,9 @@ import javax.annotation.Nullable;
* <p> * <p>
* These tokens may have a role in triggering the sign in requirement. * These tokens may have a role in triggering the sign in requirement.
* </p> * </p>
*
* @implNote This interface is expected to be thread-safe,
* as it may be accessed by multiple threads.
*/ */
public interface PoTokenProvider { public interface PoTokenProvider {

View File

@ -64,7 +64,11 @@ public final class YoutubeStreamHelper {
@Nonnull final String videoId, @Nonnull final String videoId,
@Nonnull final PoTokenResult webPoTokenResult) throws IOException, ExtractionException { @Nonnull final PoTokenResult webPoTokenResult) throws IOException, ExtractionException {
final byte[] body = JsonWriter.string( final byte[] body = JsonWriter.string(
prepareDesktopJsonBuilder(localization, contentCountry, webPoTokenResult.visitorData) prepareDesktopJsonBuilder(
localization,
contentCountry,
webPoTokenResult.visitorData
)
.value(VIDEO_ID, videoId) .value(VIDEO_ID, videoId)
.value(CONTENT_CHECK_OK, true) .value(CONTENT_CHECK_OK, true)
.value(RACY_CHECK_OK, true) .value(RACY_CHECK_OK, true)
@ -80,14 +84,20 @@ public final class YoutubeStreamHelper {
url, getYouTubeHeaders(), body, localization))); url, getYouTubeHeaders(), body, localization)));
} }
public static JsonObject getAndroidPlayerResponse(@Nonnull final ContentCountry contentCountry, public static JsonObject getAndroidPlayerResponse(
@Nonnull final Localization localization, @Nonnull final ContentCountry contentCountry,
@Nonnull final String videoId, @Nonnull final Localization localization,
@Nonnull final String androidCpn, @Nonnull final String videoId,
@Nonnull final PoTokenResult androidPoTokenResult) @Nonnull final String androidCpn,
@Nonnull final PoTokenResult androidPoTokenResult
)
throws IOException, ExtractionException { throws IOException, ExtractionException {
final byte[] mobileBody = JsonWriter.string( final byte[] mobileBody = JsonWriter.string(
prepareAndroidMobileJsonBuilder(localization, contentCountry, androidPoTokenResult.visitorData) prepareAndroidMobileJsonBuilder(
localization,
contentCountry,
androidPoTokenResult.visitorData
)
.value(VIDEO_ID, videoId) .value(VIDEO_ID, videoId)
.value(CPN, androidCpn) .value(CPN, androidCpn)
.value(CONTENT_CHECK_OK, true) .value(CONTENT_CHECK_OK, true)
@ -105,10 +115,12 @@ public final class YoutubeStreamHelper {
"&t=" + generateTParameter() + "&id=" + videoId); "&t=" + generateTParameter() + "&id=" + videoId);
} }
public static JsonObject getAndroidReelPlayerResponse(@Nonnull final ContentCountry contentCountry, public static JsonObject getAndroidReelPlayerResponse(
@Nonnull final Localization localization, @Nonnull final ContentCountry contentCountry,
@Nonnull final String videoId, @Nonnull final Localization localization,
@Nonnull final String androidCpn) @Nonnull final String videoId,
@Nonnull final String androidCpn
)
throws IOException, ExtractionException { throws IOException, ExtractionException {
final byte[] mobileBody = JsonWriter.string( final byte[] mobileBody = JsonWriter.string(
prepareAndroidMobileJsonBuilder(localization, contentCountry, null) prepareAndroidMobileJsonBuilder(localization, contentCountry, null)

View File

@ -45,14 +45,27 @@ import org.schabi.newpipe.extractor.MetaInfo;
import org.schabi.newpipe.extractor.MultiInfoItemsCollector; import org.schabi.newpipe.extractor.MultiInfoItemsCollector;
import org.schabi.newpipe.extractor.StreamingService; import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.downloader.Downloader; 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.linkhandler.LinkHandler;
import org.schabi.newpipe.extractor.localization.ContentCountry; import org.schabi.newpipe.extractor.localization.ContentCountry;
import org.schabi.newpipe.extractor.localization.DateWrapper; import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.localization.Localization; import org.schabi.newpipe.extractor.localization.Localization;
import org.schabi.newpipe.extractor.localization.TimeAgoParser; import org.schabi.newpipe.extractor.localization.TimeAgoParser;
import org.schabi.newpipe.extractor.localization.TimeAgoPatternsManager; 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.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
import org.schabi.newpipe.extractor.stream.AudioStream; import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.DeliveryMethod; 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"); throw new ExtractionException("IOS player response is not valid");
} }
final JsonObject iosStreamingData = iosPlayerResponse.getObject(STREAMING_DATA); final JsonObject iosStreamingDataLocal = iosPlayerResponse.getObject(STREAMING_DATA);
if (!isNullOrEmpty(iosStreamingData)) { if (!isNullOrEmpty(iosStreamingDataLocal)) {
this.iosStreamingData = iosStreamingData; this.iosStreamingData = iosStreamingDataLocal;
if (!forceFetchIosClient) { if (!forceFetchIosClient) {
playerCaptionsTracklistRenderer = iosPlayerResponse.getObject("captions") playerCaptionsTracklistRenderer = iosPlayerResponse.getObject("captions")
.getObject("playerCaptionsTracklistRenderer"); .getObject("playerCaptionsTracklistRenderer");
@ -839,7 +852,9 @@ public class YoutubeStreamExtractor extends StreamExtractor {
throw new PrivateContentException("This video is private."); throw new PrivateContentException("This video is private.");
} }
} else if (reason.contains("age")) { } 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, private void fetchWebClient(@Nonnull final Localization localization,
@Nonnull final ContentCountry contentCountry, @Nonnull final ContentCountry contentCountry,
@Nonnull final String videoId, @Nonnull final String videoId,
@Nullable final PoTokenResult webPoTokenResult) throws IOException, ExtractionException { @Nullable final PoTokenResult webPoTokenResult
) throws IOException, ExtractionException {
final JsonObject webPlayerResponse; final JsonObject webPlayerResponse;
if (webPoTokenResult == null) { if (webPoTokenResult == null) {
webPlayerResponse = YoutubeStreamHelper.getWebMetadataPlayerResponse( webPlayerResponse = YoutubeStreamHelper.getWebMetadataPlayerResponse(
@ -927,10 +943,10 @@ public class YoutubeStreamExtractor extends StreamExtractor {
} }
if (!isPlayerResponseNotValid(androidPlayerResponse, videoId)) { if (!isPlayerResponseNotValid(androidPlayerResponse, videoId)) {
final JsonObject androidStreamingData = final JsonObject androidStreamingDataLocal =
androidPlayerResponse.getObject(STREAMING_DATA); androidPlayerResponse.getObject(STREAMING_DATA);
if (!isNullOrEmpty(androidStreamingData)) { if (!isNullOrEmpty(androidStreamingDataLocal)) {
this.androidStreamingData = androidStreamingData; this.androidStreamingData = androidStreamingDataLocal;
if (isNullOrEmpty(playerCaptionsTracklistRenderer)) { if (isNullOrEmpty(playerCaptionsTracklistRenderer)) {
playerCaptionsTracklistRenderer = playerCaptionsTracklistRenderer =
androidPlayerResponse.getObject("captions") androidPlayerResponse.getObject("captions")
@ -1519,9 +1535,10 @@ public class YoutubeStreamExtractor extends StreamExtractor {
* Sets the {@link PoTokenProvider} instance to be used for fetching poTokens. * Sets the {@link PoTokenProvider} instance to be used for fetching poTokens.
* *
* <p> * <p>
* This method allows setting an implementation of {@link PoTokenProvider} which will be used * This method allows setting an implementation of {@link PoTokenProvider} which will
* to obtain poTokens required for YouTube player requests. These tokens are used by YouTube to verify the * be used to obtain poTokens required for YouTube player requests. These tokens are
* integrity of the device and may be necessary for playback at times. * used by YouTube to verify the integrity of the device and may be necessary for
* playback at times.
* </p> * </p>
* *
* @param poTokenProvider the {@link PoTokenProvider} instance to set * @param poTokenProvider the {@link PoTokenProvider} instance to set
@ -1535,13 +1552,14 @@ public class YoutubeStreamExtractor extends StreamExtractor {
* *
* <p> * <p>
* This method allows setting a flag to force the fetching of the iOS player response, even if a * 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 * valid webPoTokenResult is available. This can be useful in scenarios where streams from the
* response is preferred. * iOS player response is preferred.
* </p> * </p>
* *
* @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; YoutubeStreamExtractor.forceFetchIosClient = forceFetchIosClient;
} }
} }