@@ -597,13 +597,14 @@ public static boolean areHardcodedClientVersionAndKeyValid()
597597 .end ()
598598 .value ("fetchLiveState" , true )
599599 .end ()
600- .end ().done ().getBytes (UTF_8 );
600+ .end ().done ().getBytes (StandardCharsets . UTF_8 );
601601 // @formatter:on
602602
603603 final Map <String , List <String >> headers = new HashMap <>();
604604 headers .put ("X-YouTube-Client-Name" , singletonList ("1" ));
605605 headers .put ("X-YouTube-Client-Version" ,
606606 singletonList (HARDCODED_CLIENT_VERSION ));
607+ headers .put ("Content-Type" , Collections .singletonList ("application/json" ));
607608
608609 // This endpoint is fetched by the YouTube website to get the items of its main menu and is
609610 // pretty lightweight (around 30kB)
@@ -842,7 +843,7 @@ public static boolean isHardcodedYoutubeMusicKeyValid() throws IOException,
842843 .end ()
843844 .end ()
844845 .value ("input" , "" )
845- .end ().done ().getBytes (UTF_8 );
846+ .end ().done ().getBytes (StandardCharsets . UTF_8 );
846847 // @formatter:on
847848
848849 final Map <String , List <String >> headers = new HashMap <>();
@@ -851,7 +852,7 @@ public static boolean isHardcodedYoutubeMusicKeyValid() throws IOException,
851852 headers .put ("X-YouTube-Client-Version" , singletonList (
852853 HARDCODED_YOUTUBE_MUSIC_KEY [2 ]));
853854 headers .put ("Origin" , singletonList ("https://music.youtube.com" ));
854- headers .put ("Referer" , singletonList ("music.youtube.com" ));
855+ headers .put ("Referer" , singletonList ("https:// music.youtube.com" ));
855856 headers .put ("Content-Type" , singletonList ("application/json" ));
856857
857858 final Response response = getDownloader ().post (url , headers , json );
@@ -1088,13 +1089,12 @@ public static JsonObject getJsonPostResponse(final String endpoint,
10881089 final Localization localization )
10891090 throws IOException , ExtractionException {
10901091 final Map <String , List <String >> headers = new HashMap <>();
1091- addClientInfoHeaders (headers );
1092+ addYouTubeHeaders (headers );
10921093 headers .put ("Content-Type" , singletonList ("application/json" ));
10931094
1094- final Response response = getDownloader ().post (YOUTUBEI_V1_URL + endpoint + "?key="
1095- + getKey () + DISABLE_PRETTY_PRINT_PARAMETER , headers , body , localization );
1096-
1097- return JsonUtils .toJsonObject (getValidJsonResponseBody (response ));
1095+ return JsonUtils .toJsonObject (getValidJsonResponseBody (
1096+ getDownloader ().post (YOUTUBEI_V1_URL + endpoint + "?key=" + getKey ()
1097+ + DISABLE_PRETTY_PRINT_PARAMETER , headers , body , localization )));
10981098 }
10991099
11001100 public static JsonObject getJsonAndroidPostResponse (
@@ -1123,17 +1123,18 @@ private static JsonObject getMobilePostResponse(
11231123 @ Nonnull final String innerTubeApiKey ,
11241124 @ Nullable final String endPartOfUrlRequest ) throws IOException , ExtractionException {
11251125 final Map <String , List <String >> headers = new HashMap <>();
1126- headers .put ("Content-Type" , singletonList ("application/json" ));
11271126 headers .put ("User-Agent" , singletonList (userAgent ));
11281127 headers .put ("X-Goog-Api-Format-Version" , singletonList ("2" ));
1128+ headers .put ("Content-Type" , singletonList ("application/json" ));
11291129
11301130 final String baseEndpointUrl = YOUTUBEI_V1_GAPIS_URL + endpoint + "?key=" + innerTubeApiKey
11311131 + DISABLE_PRETTY_PRINT_PARAMETER ;
11321132
1133- final Response response = getDownloader ().post (isNullOrEmpty (endPartOfUrlRequest )
1134- ? baseEndpointUrl : baseEndpointUrl + endPartOfUrlRequest ,
1135- headers , body , localization );
1136- return JsonUtils .toJsonObject (getValidJsonResponseBody (response ));
1133+ return JsonUtils .toJsonObject (getValidJsonResponseBody (
1134+ getDownloader ().post (isNullOrEmpty (endPartOfUrlRequest )
1135+ ? baseEndpointUrl
1136+ : baseEndpointUrl + endPartOfUrlRequest ,
1137+ headers , body , localization )));
11371138 }
11381139
11391140 @ Nonnull
@@ -1336,6 +1337,17 @@ public static String getIosUserAgent(@Nullable final Localization localization)
13361337 + ")" ;
13371338 }
13381339
1340+ @ Nonnull
1341+ public static Map <String , List <String >> getYoutubeMusicHeaders () {
1342+ final Map <String , List <String >> headers = new HashMap <>();
1343+ headers .put ("X-YouTube-Client-Name" , Collections .singletonList (youtubeMusicKey [1 ]));
1344+ headers .put ("X-YouTube-Client-Version" , Collections .singletonList (youtubeMusicKey [2 ]));
1345+ headers .put ("Origin" , Collections .singletonList ("https://music.youtube.com" ));
1346+ headers .put ("Referer" , Collections .singletonList ("https://music.youtube.com" ));
1347+ headers .put ("Content-Type" , Collections .singletonList ("application/json" ));
1348+ return headers ;
1349+ }
1350+
13391351 /**
13401352 * Add required headers and cookies to an existing headers Map.
13411353 * @see #addClientInfoHeaders(Map)
0 commit comments