Skip to content

Commit accd5dd

Browse files
committed
Adress requested changes in YoutubeStreamExtractor
1 parent 632772d commit accd5dd

1 file changed

Lines changed: 13 additions & 23 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -719,17 +719,12 @@ public void onFetchPage(@Nonnull final Downloader downloader)
719719
.done())
720720
.getBytes(UTF_8);
721721

722-
// This boolean is needed if we don't want to fetch again the JSON player if the sts string
723-
// is not null.
724-
boolean stsKnown = false;
725-
726722
// Put the sts string if we already know it so we don't have to fetch again the player
727723
// endpoint of the desktop internal API if something went wrong when parsing the Android
728724
// API.
729725
if (sts != null) {
730726
playerResponse = getJsonPostResponse("player", createPlayerBodyWithSts(localization,
731727
contentCountry, videoId), localization);
732-
stsKnown = true;
733728
} else {
734729
playerResponse = getJsonPostResponse("player", body, localization);
735730
}
@@ -760,7 +755,7 @@ public void onFetchPage(@Nonnull final Downloader downloader)
760755

761756
streamingData = playerResponse.getObject("streamingData");
762757
if (hasOtfStreams() || isCipherProtectedContent()) {
763-
fetchAndroidMobileJsonPlayer(contentCountry, localization, videoId, stsKnown);
758+
fetchAndroidMobileJsonPlayer(contentCountry, localization, videoId);
764759
}
765760
}
766761

@@ -777,11 +772,10 @@ private void checkPlayabilityStatus(final JsonObject youtubePlayerResponse,
777772
if (status.equalsIgnoreCase("login_required")) {
778773
if (reason == null) {
779774
final String message = playabilityStatus.getArray("messages").getString(0);
780-
if (message != null && message.equals(
781-
"This is a private video. Please sign in to verify that you may see it.")) {
775+
if (message != null && message.contains("private")) {
782776
throw new PrivateContentException("This video is private.");
783777
}
784-
} else if (reason.equals("Sign in to confirm your age")) {
778+
} else if (reason.contains("age")) {
785779
// No streams can be fetched, therefore throw an AgeRestrictedContentException
786780
// explicitly.
787781
throw new AgeRestrictedContentException(
@@ -790,23 +784,22 @@ private void checkPlayabilityStatus(final JsonObject youtubePlayerResponse,
790784
}
791785
if (status.equalsIgnoreCase("unplayable")) {
792786
if (reason != null) {
793-
if (reason.equals("This video is only available to Music Premium members")) {
787+
if (reason.contains("Music Premium")) {
794788
throw new YoutubeMusicPremiumContentException();
795789
}
796-
if (reason.equals("This video requires payment to watch.")) {
790+
if (reason.contains("payment")) {
797791
throw new PaidContentException("This video is a paid video");
798792
}
799-
if (reason.equals("Join this channel to get access to members-only content like this video, and other exclusive perks.")
800-
|| reason.equals("Join this channel to get access to members-only content like this video and other exclusive perks.")) {
801-
throw new PaidContentException("This video is only available for members of the channel of this video");
793+
if (reason.contains("members-only")) {
794+
throw new PaidContentException(
795+
"This video is only available for members of the channel of this video");
802796
}
803-
if (reason.equals("Video unavailable")) {
797+
if (reason.contains("unavailable")) {
804798
final String detailedErrorMessage = getTextFromObject(playabilityStatus
805799
.getObject("errorScreen").getObject("playerErrorMessageRenderer")
806800
.getObject("subreason"));
807801
if (detailedErrorMessage != null) {
808-
if (detailedErrorMessage.equals(
809-
"The uploader has not made this video available in your country.")) {
802+
if (detailedErrorMessage.contains("country")) {
810803
throw new GeographicRestrictionException(
811804
"This video is not available in user's country.");
812805
}
@@ -827,8 +820,7 @@ private void checkPlayabilityStatus(final JsonObject youtubePlayerResponse,
827820
*/
828821
private void fetchAndroidMobileJsonPlayer(final ContentCountry contentCountry,
829822
final Localization localization,
830-
final String videoId,
831-
final boolean stsKnown) throws ExtractionException,
823+
final String videoId) throws ExtractionException,
832824
IOException {
833825
JsonObject mobilePlayerResponse = null;
834826
final byte[] mobileBody = JsonWriter.string(prepareMobileJsonBuilder(localization,
@@ -851,7 +843,7 @@ private void fetchAndroidMobileJsonPlayer(final ContentCountry contentCountry,
851843
// The cipher signatures from the player endpoint without a timestamp are invalid so
852844
// download it again only if we didn't have a signatureTimestamp before fetching the
853845
// data of this video (the sts string).
854-
if (!stsKnown && isCipherProtectedContent()) {
846+
if (sts == null && isCipherProtectedContent()) {
855847
getStsFromPlayerJs();
856848
final JsonObject playerResponseWithSignatureTimestamp = getJsonPostResponse(
857849
"player", createPlayerBodyWithSts(localization, contentCountry, videoId),
@@ -865,9 +857,7 @@ private void fetchAndroidMobileJsonPlayer(final ContentCountry contentCountry,
865857
}
866858

867859
private void fetchVideoInfoPage() throws ParsingException, ReCaptchaException, IOException {
868-
if (sts == null) {
869-
getStsFromPlayerJs();
870-
}
860+
getStsFromPlayerJs();
871861
final String videoInfoUrl = getVideoInfoUrl(getId(), sts);
872862
final String infoPageResponse = NewPipe.getDownloader()
873863
.get(videoInfoUrl, getExtractorLocalization()).responseBody();

0 commit comments

Comments
 (0)