Skip to content

Commit

Permalink
Reuse youtube token
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakambda committed Oct 19, 2024
1 parent 6a1fc63 commit 66739de
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class AudioService implements ITrackSchedulerStatusListener, ITrackLoadLi
@Getter
private final ITrackScheduler trackScheduler;

public AudioService(@NotNull Guild guild, int volume){
public AudioService(@NotNull Guild guild, int volume, @Nullable String refreshToken){
this.guild = guild;

var youtubeAudioSourceManager = new YoutubeAudioSourceManager(true,
Expand All @@ -46,7 +46,12 @@ public AudioService(@NotNull Guild guild, int volume){
new AndroidTestsuiteWithThumbnail(),
new TvHtml5EmbeddedWithThumbnail()
);
youtubeAudioSourceManager.useOauth2(null, false);
if(Objects.nonNull(refreshToken)){
youtubeAudioSourceManager.useOauth2(refreshToken, true);
}
else{
youtubeAudioSourceManager.useOauth2(null, false);
}

audioPlayerManager = new DefaultAudioPlayerManager();
audioPlayerManager.registerSourceManager(youtubeAudioSourceManager);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.rakambda.rsndiscord.spring.audio;

import fr.rakambda.rsndiscord.spring.settings.ApplicationSettings;
import fr.rakambda.rsndiscord.spring.storage.repository.AudioRepository;
import lombok.extern.slf4j.Slf4j;
import net.dv8tion.jda.api.entities.Guild;
Expand All @@ -13,10 +14,12 @@
@Component
public class AudioServiceFactory{
private final AudioRepository audioRepository;
private final String refreshToken;
private final Map<Long, AudioService> services;

public AudioServiceFactory(AudioRepository audioRepository){
public AudioServiceFactory( AudioRepository audioRepository, ApplicationSettings applicationSettings){
this.audioRepository = audioRepository;
refreshToken = applicationSettings.getYoutubeRefreshToken();

services = new ConcurrentHashMap<>();
}
Expand All @@ -31,7 +34,7 @@ private AudioService buildService(@NotNull Guild guild){
var guildEntity = audioRepository.findByGuildId(guild.getIdLong()).orElseThrow();
var volume = Math.min(100, Math.max(0, guildEntity.getVolume()));

return new AudioService(guild, volume);
return new AudioService(guild, volume, refreshToken);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ApplicationSettings{
private boolean development;
private List<Long> developmentGuilds = new LinkedList<>();
private String botToken;
private String youtubeRefreshToken;
private String amqpPrefix;
@NestedConfigurationProperty
private AnilistSettings anilist;
Expand Down

0 comments on commit 66739de

Please sign in to comment.