16
16
17
17
package com .dunctebot .sourcemanagers .spotify ;
18
18
19
+ import com .dunctebot .sourcemanagers .AudioTrackInfoWithImage ;
20
+ import com .dunctebot .sourcemanagers .extra .LimitReachedException ;
19
21
import com .google .api .services .youtube .model .SearchResult ;
20
22
import com .google .api .services .youtube .model .Video ;
21
23
import com .sedmelluq .discord .lavaplayer .player .DefaultAudioPlayerManager ;
29
31
import com .wrapper .spotify .model_objects .credentials .ClientCredentials ;
30
32
import com .wrapper .spotify .model_objects .specification .*;
31
33
import 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 ;
37
34
import org .slf4j .Logger ;
38
35
import org .slf4j .LoggerFactory ;
39
36
51
48
import java .util .regex .Matcher ;
52
49
import java .util .regex .Pattern ;
53
50
54
- import static ml . duncte123 . skybot . utils .YoutubeUtils .*;
51
+ import static com . dunctebot . sourcemanagers . extra .YoutubeUtils .*;
55
52
56
- @ Author (nickname = "duncte123" , author = "Duncan Sterken" )
57
53
public class SpotifyAudioSourceManager implements AudioSourceManager {
58
54
59
55
private static final Logger logger = LoggerFactory .getLogger (SpotifyAudioSourceManager .class );
@@ -76,25 +72,29 @@ public class SpotifyAudioSourceManager implements AudioSourceManager {
76
72
private final SpotifyApi spotifyApi ;
77
73
private final YoutubeAudioSourceManager youtubeAudioSourceManager ;
78
74
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 ) {
89
89
logger .error ("Could not load Spotify keys" );
90
90
this .spotifyApi = null ;
91
91
this .service = null ;
92
92
this .youtubeAudioSourceManager = null ;
93
93
} else {
94
94
this .youtubeAudioSourceManager = youtubeAudioSourceManager ;
95
95
this .spotifyApi = new SpotifyApi .Builder ()
96
- .setClientId (clientId )
97
- .setClientSecret (clientSecret )
96
+ .setClientId (spotifyClientId )
97
+ .setClientSecret (spotifyClientSecret )
98
98
.build ();
99
99
100
100
this .service = Executors .newScheduledThreadPool (2 , (r ) -> new Thread (r , "Spotify-Token-Update-Thread" ));
@@ -177,8 +177,8 @@ private AudioItem getSpotifyPlaylist(AudioReference reference, boolean isPatron)
177
177
return null ;
178
178
}
179
179
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 );
182
182
}
183
183
184
184
for (final PlaylistTrack playlistTrack : playlistTracks ) {
@@ -227,7 +227,7 @@ private AudioItem getSpotifyTrack(AudioReference reference) {
227
227
return null ;
228
228
}
229
229
230
- final Video v = getVideoById (videoId , this .config . googl );
230
+ final Video v = getVideoById (videoId , this .youtubeApiKey );
231
231
232
232
return audioTrackFromVideo (v , track .getAlbum ().getImages ());
233
233
}
@@ -298,7 +298,7 @@ private Matcher getSpotifyPlaylistFromString(String input) {
298
298
299
299
private List <AudioTrack > getTrackListFromVideoIds (List <String > videoIds , Image [] images ) throws Exception {
300
300
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 );
302
302
final List <AudioTrack > playList = new ArrayList <>();
303
303
304
304
videosByIds .forEach ((video ) -> playList .add (audioTrackFromVideo (video , images )));
@@ -308,7 +308,7 @@ private List<AudioTrack> getTrackListFromVideoIds(List<String> videoIds, Image[]
308
308
309
309
@ Nullable
310
310
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 );
312
312
313
313
if (!results .isEmpty ()) {
314
314
return results .get (0 ).getId ().getVideoId ();
0 commit comments