@@ -834,8 +834,8 @@ private void fetchAndroidMobileJsonPlayer(final ContentCountry contentCountry,
834834 throws IOException , ExtractionException {
835835 final byte [] mobileBody = JsonWriter .string (prepareAndroidMobileJsonBuilder (
836836 localization , contentCountry )
837- .value ("videoId" , videoId )
838- .done ())
837+ .value ("videoId" , videoId )
838+ .done ())
839839 .getBytes (UTF_8 );
840840 final JsonObject mobilePlayerResponse = getJsonMobilePostResponse ("player" ,
841841 mobileBody , contentCountry , localization );
@@ -1126,59 +1126,60 @@ private Map<String, ItagItem> getStreamsFromStreamingDataKey(
11261126 if (streamingData != null && streamingData .has (streamingDataKey )) {
11271127 final JsonArray formats = streamingData .getArray (streamingDataKey );
11281128 for (int i = 0 ; i != formats .size (); ++i ) {
1129- JsonObject formatData = formats .getObject (i );
1130- int itag = formatData .getInt ("itag" );
1131-
1132- if (ItagItem .isSupported (itag )) {
1133- try {
1134- final ItagItem itagItem = ItagItem .getItag (itag );
1135- if (itagItem .itagType == itagTypeWanted ) {
1136- // Ignore streams that are delivered using YouTube's OTF format,
1137- // as those only work with DASH and not with progressive HTTP.
1138- if (formatData .getString ("type" , EMPTY_STRING )
1139- .equalsIgnoreCase ("FORMAT_STREAM_TYPE_OTF" )) {
1140- continue ;
1141- }
1142-
1143- final String streamUrl ;
1144- if (formatData .has ("url" )) {
1145- streamUrl = formatData .getString ("url" );
1146- } else {
1147- // This url has an obfuscated signature
1148- final String cipherString = formatData .has ("cipher" )
1149- ? formatData .getString ("cipher" )
1150- : formatData .getString ("signatureCipher" );
1151- final Map <String , String > cipher = Parser .compatParseMap (
1152- cipherString );
1153- streamUrl = cipher .get ("url" ) + "&" + cipher .get ("sp" ) + "="
1154- + deobfuscateSignature (cipher .get ("s" ));
1155- }
1129+ final JsonObject formatData = formats .getObject (i );
1130+ final int itag = formatData .getInt ("itag" );
1131+ final int averageBitrate = formatData .getInt ("averageBitrate" );
1132+ final int fps = formatData .getInt ("fps" );
1133+ final String qualityLabel = formatData .getString ("qualityLabel" );
1134+ final String mimeType = formatData .getString ("mimeType" , EMPTY_STRING );
1135+
1136+ try {
1137+ final ItagItem itagItem = ItagItem .getItag (itag , averageBitrate , fps , qualityLabel , mimeType );
1138+ if (itagItem .itagType == itagTypeWanted ) {
1139+ // Ignore streams that are delivered using YouTube's OTF format,
1140+ // as those only work with DASH and not with progressive HTTP.
1141+ if (formatData .getString ("type" , EMPTY_STRING )
1142+ .equalsIgnoreCase ("FORMAT_STREAM_TYPE_OTF" )) {
1143+ continue ;
1144+ }
11561145
1157- final JsonObject initRange = formatData .getObject ("initRange" );
1158- final JsonObject indexRange = formatData .getObject ("indexRange" );
1159- final String mimeType = formatData .getString ("mimeType" , EMPTY_STRING );
1160- final String codec = mimeType .contains ("codecs" )
1161- ? mimeType .split ("\" " )[1 ] : EMPTY_STRING ;
1162-
1163- itagItem .setBitrate (formatData .getInt ("bitrate" ));
1164- itagItem .setWidth (formatData .getInt ("width" ));
1165- itagItem .setHeight (formatData .getInt ("height" ));
1166- itagItem .setInitStart (Integer .parseInt (initRange .getString ("start" ,
1167- "-1" )));
1168- itagItem .setInitEnd (Integer .parseInt (initRange .getString ("end" ,
1169- "-1" )));
1170- itagItem .setIndexStart (Integer .parseInt (indexRange .getString ("start" ,
1171- "-1" )));
1172- itagItem .setIndexEnd (Integer .parseInt (indexRange .getString ("end" ,
1173- "-1" )));
1174- itagItem .fps = formatData .getInt ("fps" );
1175- itagItem .setQuality (formatData .getString ("quality" ));
1176- itagItem .setCodec (codec );
1177-
1178- urlAndItagsFromStreamingDataObject .put (streamUrl , itagItem );
1146+ final String streamUrl ;
1147+ if (formatData .has ("url" )) {
1148+ streamUrl = formatData .getString ("url" );
1149+ } else {
1150+ // This url has an obfuscated signature
1151+ final String cipherString = formatData .has ("cipher" )
1152+ ? formatData .getString ("cipher" )
1153+ : formatData .getString ("signatureCipher" );
1154+ final Map <String , String > cipher = Parser .compatParseMap (
1155+ cipherString );
1156+ streamUrl = cipher .get ("url" ) + "&" + cipher .get ("sp" ) + "="
1157+ + deobfuscateSignature (cipher .get ("s" ));
11791158 }
1180- } catch (final UnsupportedEncodingException | ParsingException ignored ) {
1159+
1160+ final JsonObject initRange = formatData .getObject ("initRange" );
1161+ final JsonObject indexRange = formatData .getObject ("indexRange" );
1162+ final String codec = mimeType .contains ("codecs" )
1163+ ? mimeType .split ("\" " )[1 ] : EMPTY_STRING ;
1164+
1165+ itagItem .setBitrate (formatData .getInt ("bitrate" ));
1166+ itagItem .setWidth (formatData .getInt ("width" ));
1167+ itagItem .setHeight (formatData .getInt ("height" ));
1168+ itagItem .setInitStart (Integer .parseInt (initRange .getString ("start" ,
1169+ "-1" )));
1170+ itagItem .setInitEnd (Integer .parseInt (initRange .getString ("end" ,
1171+ "-1" )));
1172+ itagItem .setIndexStart (Integer .parseInt (indexRange .getString ("start" ,
1173+ "-1" )));
1174+ itagItem .setIndexEnd (Integer .parseInt (indexRange .getString ("end" ,
1175+ "-1" )));
1176+ itagItem .fps = formatData .getInt ("fps" );
1177+ itagItem .setQuality (formatData .getString ("quality" ));
1178+ itagItem .setCodec (codec );
1179+
1180+ urlAndItagsFromStreamingDataObject .put (streamUrl , itagItem );
11811181 }
1182+ } catch (final UnsupportedEncodingException | ParsingException ignored ) {
11821183 }
11831184 }
11841185 }
0 commit comments