Skip to content

Commit 9981e45

Browse files
committed
Add more logging.
1 parent c5d0aab commit 9981e45

File tree

4 files changed

+28
-15
lines changed

4 files changed

+28
-15
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ Currently, the following clients are available for use:
184184

185185
- `MUSIC`
186186
- ✔ Provides support for searching YouTube music (`ytmsearch:`).
187-
- No playback support.
187+
- Cannot be used for playback, or playlist/mix/livestream loading.
188188
- `WEB`
189189
- ✔ Opus formats.
190190
- `WEBEMBEDDED`
@@ -194,13 +194,13 @@ Currently, the following clients are available for use:
194194
- ❌ Heavily restricted, frequently dysfunctional.
195195
- `ANDROID_TESTSUITE`
196196
- ✔ Opus formats.
197-
- ❌ No mix/playlist/livestream support. Advised to use in conjunction with other clients.
197+
- ❌ No mix/playlist/livestream support.
198198
- `ANDROID_LITE`
199199
- ❌ No Opus formats (requires transcoding).
200-
- Restricted similarly to `ANDROID_TESTSUITE` (except livestreams are playable).
200+
- No mix/playlist/livestream support.
201201
- `ANDROID_MUSIC`
202202
- ✔ Opus formats.
203-
- ❌ No playlist support.
203+
- ❌ No playlist/livestream support.
204204
- `MEDIA_CONNECT`
205205
- ❌ No Opus formats (requires transcoding).
206206
- ❌ No mix/playlist/search support.

common/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ dependencies {
2020
compileOnly(libs.annotations)
2121

2222
testImplementation(libs.lavaplayer.v1)
23+
testImplementation("org.apache.logging.log4j:log4j-core:2.19.0")
24+
testImplementation("org.apache.logging.log4j:log4j-slf4j2-impl:2.19.0")
2325
}
2426

2527
mavenPublishing {

common/src/main/java/dev/lavalink/youtube/clients/skeleton/Client.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727
public interface Client {
2828
String WATCH_URL = "https://www.youtube.com/watch?v=";
2929
String API_BASE_URL = "https://youtubei.googleapis.com/youtubei/v1";
30-
String PLAYER_URL = API_BASE_URL + "/player";
31-
String SEARCH_URL = API_BASE_URL + "/search";
32-
String NEXT_URL = API_BASE_URL + "/next";
33-
String BROWSE_URL = API_BASE_URL + "/browse";
30+
String PLAYER_URL = API_BASE_URL + "/player?prettyPrint=false";
31+
String SEARCH_URL = API_BASE_URL + "/search?prettyPrint=false";
32+
String NEXT_URL = API_BASE_URL + "/next?prettyPrint=false";
33+
String BROWSE_URL = API_BASE_URL + "/browse?prettyPrint=false";
3434

3535
String MUSIC_API_BASE_URL = "https://music.youtube.com/youtubei/v1";
36-
String MUSIC_SEARCH_URL = MUSIC_API_BASE_URL + "/search";
36+
String MUSIC_SEARCH_URL = MUSIC_API_BASE_URL + "/search?prettyPrint=false";
3737

3838
// Should be videos only, whilst also bypassing YouTube's filter
3939
// for queries that trigger the suicide/self-harm warning.

common/src/main/java/dev/lavalink/youtube/clients/skeleton/NonMusicClient.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
import dev.lavalink.youtube.cipher.SignatureCipherManager.CachedPlayerScript;
1313
import dev.lavalink.youtube.clients.ClientConfig;
1414
import dev.lavalink.youtube.track.TemporalInfo;
15+
import org.apache.http.HttpEntity;
1516
import org.apache.http.client.methods.CloseableHttpResponse;
1617
import org.apache.http.client.methods.HttpPost;
1718
import org.apache.http.entity.StringEntity;
19+
import org.apache.http.util.EntityUtils;
1820
import org.jetbrains.annotations.NotNull;
1921
import org.jetbrains.annotations.Nullable;
2022
import org.slf4j.Logger;
2123
import org.slf4j.LoggerFactory;
2224

2325
import java.io.IOException;
26+
import java.nio.charset.StandardCharsets;
2427
import java.util.ArrayList;
2528
import java.util.List;
2629
import java.util.Objects;
@@ -54,13 +57,22 @@ public abstract class NonMusicClient implements Client {
5457
protected JsonBrowser loadJsonResponse(@NotNull HttpInterface httpInterface,
5558
@NotNull HttpPost request,
5659
@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+
5766
try (CloseableHttpResponse response = httpInterface.execute(request)) {
5867
HttpClientTools.assertSuccessWithContent(response, context);
5968
// todo: flag for checking json content type?
6069
// from my testing, json is always returned so might not be necessary.
6170
HttpClientTools.assertJsonContentType(response);
6271

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);
6476
}
6577
}
6678

@@ -89,8 +101,6 @@ protected JsonBrowser loadTrackInfoFromInnertube(@NotNull YoutubeAudioSourceMana
89101
.setAttributes(httpInterface)
90102
.toJsonString();
91103

92-
log.debug("Requesting {} with payload {}", PLAYER_URL, payload);
93-
94104
HttpPost request = new HttpPost(PLAYER_URL);
95105
request.setEntity(new StringEntity(payload, "UTF-8"));
96106

@@ -131,13 +141,14 @@ protected JsonBrowser loadTrackInfoFromInnertube(@NotNull YoutubeAudioSourceMana
131141
@NotNull
132142
protected JsonBrowser loadSearchResults(@NotNull HttpInterface httpInterface,
133143
@NotNull String searchQuery) {
134-
ClientConfig clientConfig = getBaseClientConfig(httpInterface)
144+
String payload = getBaseClientConfig(httpInterface)
135145
.withRootField("query", searchQuery)
136146
.withRootField("params", SEARCH_PARAMS)
137-
.setAttributes(httpInterface);
147+
.setAttributes(httpInterface)
148+
.toJsonString();
138149

139150
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"));
141152

142153
try {
143154
return loadJsonResponse(httpInterface, request, "search response");

0 commit comments

Comments
 (0)