From 6658b80b2b601dc02442ecd3c436347790c51af0 Mon Sep 17 00:00:00 2001 From: Devoxin Date: Tue, 20 Aug 2024 13:09:15 +0100 Subject: [PATCH] Update README, update rest routes. --- README.md | 58 +++++++++++++++---- .../youtube/plugin/YoutubeRestHandler.java | 10 ++-- 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index aa9cd0e..21dd038 100644 --- a/README.md +++ b/README.md @@ -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(); @@ -234,8 +243,6 @@ source.useOauth2(null, false); source.useOauth2("your refresh token", true); ``` - - ### Lavalink ```yaml plugins: @@ -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` @@ -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 diff --git a/plugin/src/main/java/dev/lavalink/youtube/plugin/YoutubeRestHandler.java b/plugin/src/main/java/dev/lavalink/youtube/plugin/YoutubeRestHandler.java index 006312d..3081ab9 100644 --- a/plugin/src/main/java/dev/lavalink/youtube/plugin/YoutubeRestHandler.java +++ b/plugin/src/main/java/dev/lavalink/youtube/plugin/YoutubeRestHandler.java @@ -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); @@ -25,7 +23,7 @@ public YoutubeRestHandler(AudioPlayerManager playerManager) { this.playerManager = playerManager; } - @GetMapping("/v4/youtube") + @GetMapping("/youtube") public Map getYoutubeConfig() { YoutubeAudioSourceManager source = playerManager.source(YoutubeAudioSourceManager.class); @@ -36,7 +34,7 @@ public Map 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);