@@ -592,13 +592,14 @@ public static boolean areHardcodedClientVersionAndKeyValid()
592592 .end ()
593593 .value ("fetchLiveState" , true )
594594 .end ()
595- .end ().done ().getBytes (UTF_8 );
595+ .end ().done ().getBytes (StandardCharsets . UTF_8 );
596596 // @formatter:on
597597
598598 final Map <String , List <String >> headers = new HashMap <>();
599599 headers .put ("X-YouTube-Client-Name" , singletonList ("1" ));
600600 headers .put ("X-YouTube-Client-Version" ,
601601 singletonList (HARDCODED_CLIENT_VERSION ));
602+ headers .put ("Content-Type" , Collections .singletonList ("application/json" ));
602603
603604 // This endpoint is fetched by the YouTube website to get the items of its main menu and is
604605 // pretty lightweight (around 30kB)
@@ -816,7 +817,7 @@ public static boolean isHardcodedYoutubeMusicKeyValid() throws IOException,
816817 .end ()
817818 .end ()
818819 .value ("input" , "" )
819- .end ().done ().getBytes (UTF_8 );
820+ .end ().done ().getBytes (StandardCharsets . UTF_8 );
820821 // @formatter:on
821822
822823 final Map <String , List <String >> headers = new HashMap <>();
@@ -825,7 +826,7 @@ public static boolean isHardcodedYoutubeMusicKeyValid() throws IOException,
825826 headers .put ("X-YouTube-Client-Version" , singletonList (
826827 HARDCODED_YOUTUBE_MUSIC_KEY [2 ]));
827828 headers .put ("Origin" , singletonList ("https://music.youtube.com" ));
828- headers .put ("Referer" , singletonList ("music.youtube.com" ));
829+ headers .put ("Referer" , singletonList ("https:// music.youtube.com" ));
829830 headers .put ("Content-Type" , singletonList ("application/json" ));
830831
831832 final Response response = getDownloader ().post (url , headers , json );
@@ -1062,13 +1063,12 @@ public static JsonObject getJsonPostResponse(final String endpoint,
10621063 final Localization localization )
10631064 throws IOException , ExtractionException {
10641065 final Map <String , List <String >> headers = new HashMap <>();
1065- addClientInfoHeaders (headers );
1066+ addYouTubeHeaders (headers );
10661067 headers .put ("Content-Type" , singletonList ("application/json" ));
10671068
1068- final Response response = getDownloader ().post (YOUTUBEI_V1_URL + endpoint + "?key="
1069- + getKey () + DISABLE_PRETTY_PRINT_PARAMETER , headers , body , localization );
1070-
1071- return JsonUtils .toJsonObject (getValidJsonResponseBody (response ));
1069+ return JsonUtils .toJsonObject (getValidJsonResponseBody (
1070+ getDownloader ().post (YOUTUBEI_V1_URL + endpoint + "?key=" + getKey ()
1071+ + DISABLE_PRETTY_PRINT_PARAMETER , headers , body , localization )));
10721072 }
10731073
10741074 public static JsonObject getJsonAndroidPostResponse (
@@ -1097,17 +1097,18 @@ private static JsonObject getMobilePostResponse(
10971097 @ Nonnull final String innerTubeApiKey ,
10981098 @ Nullable final String endPartOfUrlRequest ) throws IOException , ExtractionException {
10991099 final Map <String , List <String >> headers = new HashMap <>();
1100- headers .put ("Content-Type" , singletonList ("application/json" ));
11011100 headers .put ("User-Agent" , singletonList (userAgent ));
11021101 headers .put ("X-Goog-Api-Format-Version" , singletonList ("2" ));
1102+ headers .put ("Content-Type" , singletonList ("application/json" ));
11031103
11041104 final String baseEndpointUrl = YOUTUBEI_V1_GAPIS_URL + endpoint + "?key=" + innerTubeApiKey
11051105 + DISABLE_PRETTY_PRINT_PARAMETER ;
11061106
1107- final Response response = getDownloader ().post (isNullOrEmpty (endPartOfUrlRequest )
1108- ? baseEndpointUrl : baseEndpointUrl + endPartOfUrlRequest ,
1109- headers , body , localization );
1110- return JsonUtils .toJsonObject (getValidJsonResponseBody (response ));
1107+ return JsonUtils .toJsonObject (getValidJsonResponseBody (
1108+ getDownloader ().post (isNullOrEmpty (endPartOfUrlRequest )
1109+ ? baseEndpointUrl
1110+ : baseEndpointUrl + endPartOfUrlRequest ,
1111+ headers , body , localization )));
11111112 }
11121113
11131114 @ Nonnull
@@ -1285,6 +1286,17 @@ public static String getIosUserAgent(@Nullable final Localization localization)
12851286 + ")" ;
12861287 }
12871288
1289+ @ Nonnull
1290+ public static Map <String , List <String >> getYoutubeMusicHeaders () {
1291+ final Map <String , List <String >> headers = new HashMap <>();
1292+ headers .put ("X-YouTube-Client-Name" , Collections .singletonList (youtubeMusicKey [1 ]));
1293+ headers .put ("X-YouTube-Client-Version" , Collections .singletonList (youtubeMusicKey [2 ]));
1294+ headers .put ("Origin" , Collections .singletonList ("https://music.youtube.com" ));
1295+ headers .put ("Referer" , Collections .singletonList ("https://music.youtube.com" ));
1296+ headers .put ("Content-Type" , Collections .singletonList ("application/json" ));
1297+ return headers ;
1298+ }
1299+
12881300 /**
12891301 * Add required headers and cookies to an existing headers Map.
12901302 * @see #addClientInfoHeaders(Map)
0 commit comments