@@ -111,6 +111,7 @@ public static class DeobfuscateException extends ParsingException {
111111 private JsonObject videoPrimaryInfoRenderer ;
112112 private JsonObject videoSecondaryInfoRenderer ;
113113 private int ageLimit = -1 ;
114+ private boolean isGetVideoInfoPlayerResponse = false ;
114115 @ Nullable
115116 private List <SubtitlesStream > subtitles = null ;
116117
@@ -759,9 +760,14 @@ public void onFetchPage(@Nonnull final Downloader downloader)
759760
760761 nextResponse = getJsonPostResponse ("next" , body , localization );
761762
762- streamingData = playerResponse .getObject ("streamingData" );
763- if (hasOtfStreams () || isCipherProtectedContent ()) {
763+ // Workaround for rate limits on web streaming URLs.
764+ // TODO: add ability to deobfuscate the n param of these URLs
765+
766+ // It's not needed to request the mobile API for age-restricted videos
767+ if (!isGetVideoInfoPlayerResponse ) {
764768 fetchAndroidMobileJsonPlayer (contentCountry , localization , videoId );
769+ } else {
770+ streamingData = playerResponse .getObject ("streamingData" );
765771 }
766772 }
767773
@@ -859,6 +865,8 @@ private void fetchAndroidMobileJsonPlayer(final ContentCountry contentCountry,
859865 streamingData = playerResponseWithSignatureTimestamp .getObject (
860866 "streamingData" );
861867 }
868+ } else {
869+ streamingData = playerResponse .getObject ("streamingData" );
862870 }
863871 }
864872 }
@@ -876,6 +884,7 @@ private void fetchVideoInfoPage() throws ParsingException, ReCaptchaException, I
876884 throw new ParsingException (
877885 "Could not parse YouTube player response from video info page" , e );
878886 }
887+ isGetVideoInfoPlayerResponse = true ;
879888 }
880889
881890 @ Nonnull
@@ -940,21 +949,6 @@ private void storePlayerJs() throws ParsingException {
940949 }
941950 }
942951
943- private boolean hasOtfStreams () {
944- if (streamingData != null ) {
945- final JsonArray adaptiveFormats = streamingData .getArray ("adaptiveFormats" );
946- for (final Object adaptiveFormat : adaptiveFormats ) {
947- final JsonObject jsonAdaptiveFormat = (JsonObject ) adaptiveFormat ;
948- final String streamTypeFormat = jsonAdaptiveFormat .getString ("type" , EMPTY_STRING );
949- if (streamTypeFormat .equalsIgnoreCase ("FORMAT_STREAM_TYPE_OTF" )) {
950- return true ;
951- }
952- }
953- }
954-
955- return false ;
956- }
957-
958952 private boolean isCipherProtectedContent () {
959953 if (streamingData != null ) {
960954 if (streamingData .has ("adaptiveFormats" )) {
0 commit comments