Skip to content

Commit 6658b80

Browse files
committed
Update README, update rest routes.
1 parent e3f00f4 commit 6658b80

File tree

2 files changed

+51
-17
lines changed

2 files changed

+51
-17
lines changed

README.md

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,15 @@ of efficacy. You can instruct `youtube-source` to use OAuth with the following:
220220
> This method may also trigger ratelimit errors if used in a high traffic environment.
221221
> USE WITH CAUTION!
222222

223+
> [!NOTE]
224+
> You may need to set your log level for `dev.lavalink.youtube.http.YoutubeOauth2Handler` to `INFO`, to see additional information
225+
> within your terminal regarding completing the OAuth flow.
226+
227+
> [!NOTE]
228+
> If you do not have a refresh token, then do not supply one. The source will output your refresh token into your terminal upon
229+
> successfully completing the OAuth flow at least **once**. If you do not see your token, you may need to configure your
230+
> logging (see above note).
231+
223232
### Lavaplayer
224233
```java
225234
YoutubeAudioSourceManager source = new YoutubeAudioSourceManager();
@@ -234,8 +243,6 @@ source.useOauth2(null, false);
234243
source.useOauth2("your refresh token", true);
235244
```
236245

237-
<!-- TODO document rest routes -->
238-
239246
### Lavalink
240247
```yaml
241248
plugins:
@@ -245,14 +252,15 @@ plugins:
245252
# setting "enabled: true" is the bare minimum to get OAuth working.
246253
enabled: true
247254

248-
# you may optionally set your refresh token if you have one, which skips the OAuth flow entirely.
249-
# once you have completed the oauth flow at least once, you should see your refresh token within your
250-
# lavalink logs, which can be used here.
251-
refreshToken: "your refresh token, only supply this if you have one!"
255+
# if you have a refresh token, you may set it below (make sure to uncomment the line to apply it).
256+
# setting a valid refresh token will skip the OAuth flow entirely. See above note on how to retrieve
257+
# your refreshToken.
258+
# refreshToken: "paste your refresh token here if applicable"
252259

253-
# Set this if you don't want the OAuth flow to be triggered, if you intend to supply a refresh token
254-
# later on via REST routes. Initialization is skipped automatically if a valid refresh token is supplied.
255-
skipInitialization: true
260+
# Set this if you don't want the OAuth flow to be triggered, if you intend to supply a refresh token later.
261+
# Initialization is skipped automatically if a valid refresh token is supplied. Leave this commented if you're
262+
# completing the OAuth flow for the first time/do not have a refresh token.
263+
# skipInitialization: true
256264
```
257265

258266
## Using a `poToken`
@@ -285,8 +293,36 @@ plugins:
285293
286294
> [!NOTE]
287295
> A `poToken` is not a silver bullet, and currently it only applies to requests made via the `WEB` client.
288-
>
289-
> At the time of writing, the most effective method for working around automated request blocking is to use IPv6 rotation.
296+
297+
## REST routes (`plugin` only)
298+
`POST` `/youtube`
299+
300+
Body:
301+
```json
302+
{
303+
"refreshToken": "your new refresh token",
304+
"skipInitialization": true
305+
}
306+
```
307+
308+
Response:
309+
`204 - No Content`
310+
311+
`GET` `/youtube`
312+
313+
Response:
314+
315+
If the YouTube source is not enabled:
316+
`400 - Bad Request`
317+
318+
Otherwise:
319+
```json
320+
{
321+
"refreshToken": "your current refresh token, or null"
322+
}
323+
```
324+
325+
290326

291327
## Migration from Lavaplayer's built-in YouTube source
292328

plugin/src/main/java/dev/lavalink/youtube/plugin/YoutubeRestHandler.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,14 @@
66
import org.slf4j.LoggerFactory;
77
import org.springframework.http.HttpStatus;
88
import org.springframework.stereotype.Service;
9-
import org.springframework.web.bind.annotation.GetMapping;
10-
import org.springframework.web.bind.annotation.PostMapping;
11-
import org.springframework.web.bind.annotation.RequestBody;
12-
import org.springframework.web.bind.annotation.ResponseStatus;
9+
import org.springframework.web.bind.annotation.*;
1310
import org.springframework.web.server.ResponseStatusException;
1411

1512
import java.util.Collections;
1613
import java.util.Map;
1714

1815
@Service
16+
@RestController
1917
public class YoutubeRestHandler {
2018
private static final Logger log = LoggerFactory.getLogger(YoutubeRestHandler.class);
2119

@@ -25,7 +23,7 @@ public YoutubeRestHandler(AudioPlayerManager playerManager) {
2523
this.playerManager = playerManager;
2624
}
2725

28-
@GetMapping("/v4/youtube")
26+
@GetMapping("/youtube")
2927
public Map<String, String> getYoutubeConfig() {
3028
YoutubeAudioSourceManager source = playerManager.source(YoutubeAudioSourceManager.class);
3129

@@ -36,7 +34,7 @@ public Map<String, String> getYoutubeConfig() {
3634
return Collections.singletonMap("refreshToken", source.getOauth2RefreshToken());
3735
}
3836

39-
@PostMapping("/v4/youtube")
37+
@PostMapping("/youtube")
4038
@ResponseStatus(HttpStatus.NO_CONTENT)
4139
public void updateOauth(@RequestBody YoutubeOauthConfig config) {
4240
YoutubeAudioSourceManager source = playerManager.source(YoutubeAudioSourceManager.class);

0 commit comments

Comments
 (0)