Skip to content

Commit

Permalink
Update README, update rest routes.
Browse files Browse the repository at this point in the history
  • Loading branch information
devoxin committed Aug 20, 2024
1 parent e3f00f4 commit 6658b80
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 17 deletions.
58 changes: 47 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,15 @@ of efficacy. You can instruct `youtube-source` to use OAuth with the following:
> This method may also trigger ratelimit errors if used in a high traffic environment.
> USE WITH CAUTION!

> [!NOTE]
> You may need to set your log level for `dev.lavalink.youtube.http.YoutubeOauth2Handler` to `INFO`, to see additional information
> within your terminal regarding completing the OAuth flow.

> [!NOTE]
> If you do not have a refresh token, then do not supply one. The source will output your refresh token into your terminal upon
> successfully completing the OAuth flow at least **once**. If you do not see your token, you may need to configure your
> logging (see above note).

### Lavaplayer
```java
YoutubeAudioSourceManager source = new YoutubeAudioSourceManager();
Expand All @@ -234,8 +243,6 @@ source.useOauth2(null, false);
source.useOauth2("your refresh token", true);
```

<!-- TODO document rest routes -->

### Lavalink
```yaml
plugins:
Expand All @@ -245,14 +252,15 @@ plugins:
# setting "enabled: true" is the bare minimum to get OAuth working.
enabled: true

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

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

## Using a `poToken`
Expand Down Expand Up @@ -285,8 +293,36 @@ plugins:
> [!NOTE]
> A `poToken` is not a silver bullet, and currently it only applies to requests made via the `WEB` client.
>
> At the time of writing, the most effective method for working around automated request blocking is to use IPv6 rotation.

## REST routes (`plugin` only)
`POST` `/youtube`

Body:
```json
{
"refreshToken": "your new refresh token",
"skipInitialization": true
}
```

Response:
`204 - No Content`

`GET` `/youtube`

Response:

If the YouTube source is not enabled:
`400 - Bad Request`

Otherwise:
```json
{
"refreshToken": "your current refresh token, or null"
}
```



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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,14 @@
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import java.util.Collections;
import java.util.Map;

@Service
@RestController
public class YoutubeRestHandler {
private static final Logger log = LoggerFactory.getLogger(YoutubeRestHandler.class);

Expand All @@ -25,7 +23,7 @@ public YoutubeRestHandler(AudioPlayerManager playerManager) {
this.playerManager = playerManager;
}

@GetMapping("/v4/youtube")
@GetMapping("/youtube")
public Map<String, String> getYoutubeConfig() {
YoutubeAudioSourceManager source = playerManager.source(YoutubeAudioSourceManager.class);

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

@PostMapping("/v4/youtube")
@PostMapping("/youtube")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateOauth(@RequestBody YoutubeOauthConfig config) {
YoutubeAudioSourceManager source = playerManager.source(YoutubeAudioSourceManager.class);
Expand Down

0 comments on commit 6658b80

Please sign in to comment.