|
12 | 12 | import dev.lavalink.youtube.cipher.SignatureCipherManager.CachedPlayerScript; |
13 | 13 | import dev.lavalink.youtube.clients.ClientConfig; |
14 | 14 | import dev.lavalink.youtube.track.TemporalInfo; |
| 15 | +import org.apache.http.HttpEntity; |
15 | 16 | import org.apache.http.client.methods.CloseableHttpResponse; |
16 | 17 | import org.apache.http.client.methods.HttpPost; |
17 | 18 | import org.apache.http.entity.StringEntity; |
| 19 | +import org.apache.http.util.EntityUtils; |
18 | 20 | import org.jetbrains.annotations.NotNull; |
19 | 21 | import org.jetbrains.annotations.Nullable; |
20 | 22 | import org.slf4j.Logger; |
21 | 23 | import org.slf4j.LoggerFactory; |
22 | 24 |
|
23 | 25 | import java.io.IOException; |
| 26 | +import java.nio.charset.StandardCharsets; |
24 | 27 | import java.util.ArrayList; |
25 | 28 | import java.util.List; |
26 | 29 | import java.util.Objects; |
@@ -54,13 +57,22 @@ public abstract class NonMusicClient implements Client { |
54 | 57 | protected JsonBrowser loadJsonResponse(@NotNull HttpInterface httpInterface, |
55 | 58 | @NotNull HttpPost request, |
56 | 59 | @NotNull String context) throws IOException { |
| 60 | + if (request.getEntity() instanceof StringEntity) { |
| 61 | + log.debug("Requesting {} ({}) with payload {}", request.getURI(), context, EntityUtils.toString(request.getEntity(), StandardCharsets.UTF_8)); |
| 62 | + } else { |
| 63 | + log.debug("Requesting {} ({})", context, request.getURI()); |
| 64 | + } |
| 65 | + |
57 | 66 | try (CloseableHttpResponse response = httpInterface.execute(request)) { |
58 | 67 | HttpClientTools.assertSuccessWithContent(response, context); |
59 | 68 | // todo: flag for checking json content type? |
60 | 69 | // from my testing, json is always returned so might not be necessary. |
61 | 70 | HttpClientTools.assertJsonContentType(response); |
62 | 71 |
|
63 | | - return JsonBrowser.parse(response.getEntity().getContent()); |
| 72 | + String json = EntityUtils.toString(response.getEntity()); |
| 73 | + log.trace("Response from {} ({}) {}", request.getURI(), context, json); |
| 74 | + |
| 75 | + return JsonBrowser.parse(json); |
64 | 76 | } |
65 | 77 | } |
66 | 78 |
|
@@ -89,8 +101,6 @@ protected JsonBrowser loadTrackInfoFromInnertube(@NotNull YoutubeAudioSourceMana |
89 | 101 | .setAttributes(httpInterface) |
90 | 102 | .toJsonString(); |
91 | 103 |
|
92 | | - log.debug("Requesting {} with payload {}", PLAYER_URL, payload); |
93 | | - |
94 | 104 | HttpPost request = new HttpPost(PLAYER_URL); |
95 | 105 | request.setEntity(new StringEntity(payload, "UTF-8")); |
96 | 106 |
|
@@ -131,13 +141,14 @@ protected JsonBrowser loadTrackInfoFromInnertube(@NotNull YoutubeAudioSourceMana |
131 | 141 | @NotNull |
132 | 142 | protected JsonBrowser loadSearchResults(@NotNull HttpInterface httpInterface, |
133 | 143 | @NotNull String searchQuery) { |
134 | | - ClientConfig clientConfig = getBaseClientConfig(httpInterface) |
| 144 | + String payload = getBaseClientConfig(httpInterface) |
135 | 145 | .withRootField("query", searchQuery) |
136 | 146 | .withRootField("params", SEARCH_PARAMS) |
137 | | - .setAttributes(httpInterface); |
| 147 | + .setAttributes(httpInterface) |
| 148 | + .toJsonString(); |
138 | 149 |
|
139 | 150 | HttpPost request = new HttpPost(SEARCH_URL); // This *had* a key parameter. Doesn't seem needed though. |
140 | | - request.setEntity(new StringEntity(clientConfig.toJsonString(), "UTF-8")); |
| 151 | + request.setEntity(new StringEntity(payload, "UTF-8")); |
141 | 152 |
|
142 | 153 | try { |
143 | 154 | return loadJsonResponse(httpInterface, request, "search response"); |
|
0 commit comments