-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement YouTube OAuth2 login #1670
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
909b655
Update YouTube source manager
MichailiK 9d65845
Implement YouTube OAuth2 login
MichailiK 4a8392f
Catch potential exceptions thrown by the useOAuth2 call
MichailiK b80b0c8
Remove accidental HTML tag :)
MichailiK c95f224
Bump youtube-source to 1.8.2
MichailiK 348fc3c
DM the user when the YoutubeOauth2Handler is providing us a token
MichailiK 463bf75
Prepend "Google" to "accounts" in OAuth2 DM for clarification
MichailiK 88ce3e1
Stop logging the refresh token on startup
MichailiK 6094e49
Return early when failing to read the token file
MichailiK 844a1bb
Change youtubeoauth2 option description
MichailiK 96ffcd8
Handle specific track exceptions with a special message
MichailiK 58a9e76
Formatting changes
MichailiK 070938b
Add anothen message to onTrackError handler
MichailiK ea9a5da
Add another message to onTrackError
MichailiK cbe1723
Adjust onTrackError message formatting
MichailiK ac578ad
Swallow exception when failing to DM owner
MichailiK 7e1734a
Update youtube-source to 1.8.3
MichailiK 2444fe6
Initialize GUI earlier
MichailiK b6e9561
Update lavaplayer to 2.2.2
MichailiK 7b4ff3f
Switch out JDA-Utils dependency
MichailiK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
|
||
import com.dunctebot.sourcemanagers.DuncteBotSources; | ||
import com.jagrosh.jmusicbot.Bot; | ||
import com.jagrosh.jmusicbot.utils.OtherUtil; | ||
import com.sedmelluq.discord.lavaplayer.container.MediaContainerRegistry; | ||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; | ||
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; | ||
|
@@ -31,13 +32,19 @@ | |
import com.sedmelluq.discord.lavaplayer.source.vimeo.VimeoAudioSourceManager; | ||
import dev.lavalink.youtube.YoutubeAudioSourceManager; | ||
import net.dv8tion.jda.api.entities.Guild; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.NoSuchFileException; | ||
|
||
/** | ||
* | ||
* @author John Grosh ([email protected]) | ||
*/ | ||
public class PlayerManager extends DefaultAudioPlayerManager | ||
{ | ||
private final static Logger LOGGER = LoggerFactory.getLogger(PlayerManager.class); | ||
private final Bot bot; | ||
|
||
public PlayerManager(Bot bot) | ||
|
@@ -49,8 +56,7 @@ public void init() | |
{ | ||
TransformativeAudioSourceManager.createTransforms(bot.getConfig().getTransforms()).forEach(t -> registerSourceManager(t)); | ||
|
||
YoutubeAudioSourceManager yt = new YoutubeAudioSourceManager(true); | ||
yt.setPlaylistPageCount(bot.getConfig().getMaxYTPlaylistPages()); | ||
YoutubeAudioSourceManager yt = setupYoutubeAudioSourceManager(); | ||
registerSourceManager(yt); | ||
|
||
registerSourceManager(SoundCloudAudioSourceManager.createDefault()); | ||
|
@@ -66,7 +72,42 @@ public void init() | |
|
||
DuncteBotSources.registerAll(this, "en-US"); | ||
} | ||
|
||
|
||
private YoutubeAudioSourceManager setupYoutubeAudioSourceManager() | ||
{ | ||
YoutubeAudioSourceManager yt = new YoutubeAudioSourceManager(true); | ||
yt.setPlaylistPageCount(bot.getConfig().getMaxYTPlaylistPages()); | ||
|
||
// OAuth2 setup | ||
if (bot.getConfig().useYoutubeOauth2()) | ||
{ | ||
String token = null; | ||
try | ||
{ | ||
token = Files.readString(OtherUtil.getPath("youtubetoken.txt")); | ||
} | ||
catch (NoSuchFileException e) | ||
{ | ||
/* ignored */ | ||
} | ||
catch (IOException e) | ||
{ | ||
LOGGER.warn("Failed to read YouTube OAuth2 token file: {}", e.getMessage()); | ||
return yt; | ||
} | ||
LOGGER.debug("Read YouTube OAuth2 refresh token from youtubetoken.txt"); | ||
try | ||
{ | ||
yt.useOauth2(token, false); | ||
} | ||
catch (Exception e) | ||
{ | ||
LOGGER.warn("Failed to authorise with YouTube. If this issue persists, delete the youtubetoken.txt file to reauthorise.", e); | ||
} | ||
} | ||
return yt; | ||
} | ||
|
||
public Bot getBot() | ||
{ | ||
return bot; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Honestly a bit of a hacky way of going from the (Lavaplayer) youtube-source logging the details to JDA being ready & DM'ing the owner the details. Feel free to point out better solutions for this!