1616
1717package com .dunctebot .sourcemanagers .spotify ;
1818
19+ import com .dunctebot .sourcemanagers .AudioTrackInfoWithImage ;
20+ import com .dunctebot .sourcemanagers .extra .LimitReachedException ;
1921import com .google .api .services .youtube .model .SearchResult ;
2022import com .google .api .services .youtube .model .Video ;
2123import com .sedmelluq .discord .lavaplayer .player .DefaultAudioPlayerManager ;
2931import com .wrapper .spotify .model_objects .credentials .ClientCredentials ;
3032import com .wrapper .spotify .model_objects .specification .*;
3133import com .wrapper .spotify .requests .authorization .client_credentials .ClientCredentialsRequest ;
32- import ml .duncte123 .skybot .Author ;
33- import ml .duncte123 .skybot .audio .TrackScheduler ;
34- import ml .duncte123 .skybot .audio .sourcemanagers .AudioTrackInfoWithImage ;
35- import ml .duncte123 .skybot .exceptions .LimitReachedException ;
36- import ml .duncte123 .skybot .objects .config .DunctebotConfig ;
3734import org .slf4j .Logger ;
3835import org .slf4j .LoggerFactory ;
3936
5148import java .util .regex .Matcher ;
5249import java .util .regex .Pattern ;
5350
54- import static ml . duncte123 . skybot . utils .YoutubeUtils .*;
51+ import static com . dunctebot . sourcemanagers . extra .YoutubeUtils .*;
5552
56- @ Author (nickname = "duncte123" , author = "Duncan Sterken" )
5753public class SpotifyAudioSourceManager implements AudioSourceManager {
5854
5955 private static final Logger logger = LoggerFactory .getLogger (SpotifyAudioSourceManager .class );
@@ -76,25 +72,29 @@ public class SpotifyAudioSourceManager implements AudioSourceManager {
7672 private final SpotifyApi spotifyApi ;
7773 private final YoutubeAudioSourceManager youtubeAudioSourceManager ;
7874 private final ScheduledExecutorService service ;
79- private final DunctebotConfig .Apis config ;
80-
81- public SpotifyAudioSourceManager (YoutubeAudioSourceManager youtubeAudioSourceManager , DunctebotConfig .Apis config ) {
82- this .config = config ;
83-
84- final String clientId = config .spotify .clientId ;
85- final String clientSecret = config .spotify .clientSecret ;
86- final String youtubeApiKey = config .googl ;
87-
88- if (clientId == null || clientSecret == null || youtubeApiKey == null ) {
75+ /*private final String spotifyClientId;
76+ private final String spotifyClientSecret;*/
77+ private final String youtubeApiKey ;
78+ private final int playlistLimit ;
79+
80+ public SpotifyAudioSourceManager (YoutubeAudioSourceManager youtubeAudioSourceManager ,
81+ String spotifyClientId , String spotifyClientSecret , String youtubeApiKey ,
82+ int playlistLimit ) {
83+ /*this.spotifyClientId = spotifyClientId;
84+ this.spotifyClientSecret = spotifyClientSecret;*/
85+ this .youtubeApiKey = youtubeApiKey ;
86+ this .playlistLimit = playlistLimit ;
87+
88+ if (spotifyClientId == null || spotifyClientSecret == null || youtubeApiKey == null ) {
8989 logger .error ("Could not load Spotify keys" );
9090 this .spotifyApi = null ;
9191 this .service = null ;
9292 this .youtubeAudioSourceManager = null ;
9393 } else {
9494 this .youtubeAudioSourceManager = youtubeAudioSourceManager ;
9595 this .spotifyApi = new SpotifyApi .Builder ()
96- .setClientId (clientId )
97- .setClientSecret (clientSecret )
96+ .setClientId (spotifyClientId )
97+ .setClientSecret (spotifyClientSecret )
9898 .build ();
9999
100100 this .service = Executors .newScheduledThreadPool (2 , (r ) -> new Thread (r , "Spotify-Token-Update-Thread" ));
@@ -177,8 +177,8 @@ private AudioItem getSpotifyPlaylist(AudioReference reference, boolean isPatron)
177177 return null ;
178178 }
179179
180- if (playlistTracks .length > TrackScheduler . QUEUE_SIZE && !isPatron ) {
181- throw new LimitReachedException ("The playlist is too big" , TrackScheduler . QUEUE_SIZE );
180+ if (playlistTracks .length > this . playlistLimit && !isPatron ) {
181+ throw new LimitReachedException ("The playlist is too big" , this . playlistLimit );
182182 }
183183
184184 for (final PlaylistTrack playlistTrack : playlistTracks ) {
@@ -227,7 +227,7 @@ private AudioItem getSpotifyTrack(AudioReference reference) {
227227 return null ;
228228 }
229229
230- final Video v = getVideoById (videoId , this .config . googl );
230+ final Video v = getVideoById (videoId , this .youtubeApiKey );
231231
232232 return audioTrackFromVideo (v , track .getAlbum ().getImages ());
233233 }
@@ -298,7 +298,7 @@ private Matcher getSpotifyPlaylistFromString(String input) {
298298
299299 private List <AudioTrack > getTrackListFromVideoIds (List <String > videoIds , Image [] images ) throws Exception {
300300 final String videoIdsJoined = String .join ("," , videoIds );
301- final List <Video > videosByIds = getVideosByIds (videoIdsJoined , this .config . googl );
301+ final List <Video > videosByIds = getVideosByIds (videoIdsJoined , this .youtubeApiKey );
302302 final List <AudioTrack > playList = new ArrayList <>();
303303
304304 videosByIds .forEach ((video ) -> playList .add (audioTrackFromVideo (video , images )));
@@ -308,7 +308,7 @@ private List<AudioTrack> getTrackListFromVideoIds(List<String> videoIds, Image[]
308308
309309 @ Nullable
310310 private String searchYoutube (String title , String author ) throws IOException {
311- final List <SearchResult > results = searchYoutubeIdOnly (title + " " + author , this .config . googl , 1L );
311+ final List <SearchResult > results = searchYoutubeIdOnly (title + " " + author , this .youtubeApiKey , 1L );
312312
313313 if (!results .isEmpty ()) {
314314 return results .get (0 ).getId ().getVideoId ();
0 commit comments