Skip to content

Commit

Permalink
Fix all checkstyle issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
FireMasterK committed Dec 12, 2024
1 parent 6f88ce6 commit fbee94e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
/**
* 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>
* On some major clients, YouTube requires that the integrity of the device passes some checks to
Expand All @@ -21,6 +20,9 @@
* <p>
* These tokens may have a role in triggering the sign in requirement.
* </p>
*
* @implNote This interface is expected to be thread-safe,
* as it may be accessed by multiple threads.
*/
public interface PoTokenProvider {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ public static JsonObject getWebFullPlayerResponse(
@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)
Expand All @@ -80,14 +84,20 @@ public static JsonObject getWebFullPlayerResponse(
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)
Expand All @@ -105,10 +115,12 @@ public static JsonObject getAndroidPlayerResponse(@Nonnull final ContentCountry
"&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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,27 @@
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;
Expand Down Expand Up @@ -792,9 +805,9 @@ public void onFetchPage(@Nonnull final Downloader downloader)
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");
Expand Down Expand Up @@ -839,7 +852,9 @@ private static void checkPlayabilityStatus(final JsonObject youtubePlayerRespons
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"
);
}
}

Expand Down Expand Up @@ -877,7 +892,8 @@ private static void checkPlayabilityStatus(final JsonObject youtubePlayerRespons
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(
Expand Down Expand Up @@ -927,10 +943,10 @@ private void fetchAndroidClient(@Nonnull final Localization localization,
}

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")
Expand Down Expand Up @@ -1519,9 +1535,10 @@ public List<MetaInfo> getMetaInfo() throws ParsingException {
* Sets the {@link PoTokenProvider} instance to be used for fetching poTokens.
*
* <p>
* 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.
* </p>
*
* @param poTokenProvider the {@link PoTokenProvider} instance to set
Expand All @@ -1535,13 +1552,14 @@ public static void setPoTokenProvider(@Nullable final PoTokenProvider poTokenPro
*
* <p>
* 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.
* </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;
}
}

0 comments on commit fbee94e

Please sign in to comment.