Skip to content

Commit 9f70f2e

Browse files
committed
Log OAuth warning when using OAuth clients without token.
1 parent 04276a9 commit 9f70f2e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

common/src/main/java/dev/lavalink/youtube/YoutubeAudioSourceManager.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public class YoutubeAudioSourceManager implements AudioSourceManager {
5555
new Music(), new AndroidVr(), new Web(), new WebEmbedded()
5656
};
5757

58+
private static boolean loggedOauthClientNoAccountWarning = false;
59+
5860
private static final String PROTOCOL_REGEX = "(?:http://|https://|)";
5961
private static final String DOMAIN_REGEX = "(?:www\\.|m\\.|music\\.|)youtube\\.com";
6062
private static final String SHORT_DOMAIN_REGEX = "(?:www\\.|)youtu\\.be";
@@ -229,6 +231,14 @@ protected AudioItem loadItemOnce(@NotNull AudioReference reference) {
229231
continue;
230232
}
231233

234+
boolean shouldLogOauthWarning = client.supportsOAuth() && !loggedOauthClientNoAccountWarning &&
235+
!oauth2Handler.hasAccessToken() && client.getOptions().getPlayback();
236+
237+
if (shouldLogOauthWarning) {
238+
loggedOauthClientNoAccountWarning = true;
239+
log.warn("!!! You are using an OAuth-enabled client without a valid OAuth token! This client may not play videos!");
240+
}
241+
232242
log.debug("Attempting to load {} with client \"{}\"", reference.identifier, client.getIdentifier());
233243
httpInterface.getContext().setAttribute(Client.OAUTH_CLIENT_ATTRIBUTE, client.supportsOAuth());
234244

common/src/main/java/dev/lavalink/youtube/http/YoutubeOauth2Handler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public void setRefreshToken(@Nullable String refreshToken, boolean skipInitializ
6969
}
7070
}
7171

72+
public boolean hasAccessToken() {
73+
return accessToken != null;
74+
}
75+
7276
public boolean shouldRefreshAccessToken() {
7377
return enabled && !DataFormatTools.isNullOrEmpty(refreshToken) && (DataFormatTools.isNullOrEmpty(accessToken) || System.currentTimeMillis() >= tokenExpires);
7478
}

0 commit comments

Comments
 (0)