Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"axios": "^1.6.2",
"axios": "^1.6.8",
"bootstrap-vue": "^2.23.1",
"core-js": "^3.8.3",
"sweetalert": "^2.1.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.yen.SpotifyPlayList.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/** Enable multi thread in spring boot */

@Configuration
public class AppConfig {

private final int THREAD_COUNT = 5;

@Bean
public ExecutorService executorService() {
// Create a fixed thread pool with 5 threads
return Executors.newFixedThreadPool(THREAD_COUNT);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//package com.yen.SpotifyPlayList.config;
//
//import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
//import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
//import org.apache.http.impl.client.HttpClientBuilder;
//import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
//import org.springframework.web.client.RestTemplate;
//
//@Configuration
//public class HttpClientConfig {
//
// @Bean
// public RestTemplate restTemplate() {
//
// PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
// connectionManager.setMaxTotal(100); // Set the maximum number of connections
// connectionManager.setDefaultMaxPerRoute(20); // Set the maximum number of connections per route
//
// HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
// httpClientBuilder.setConnectionManager(connectionManager);
//
// HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build());
// return new RestTemplate(factory);
// }
//}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//package com.yen.SpotifyPlayList.config;
//
//// https://www.cnblogs.com/zjdxr-up/p/14530875.html
//
//import lombok.Data;
//import org.springframework.stereotype.Component;
//
//@Component
////@ConfigurationProperties(prefix = "http.pool.conn") // 可在配置文件中进行配置
//@Data
//public class HttpPoolProperties {
// // 最大连接数
// private Integer maxTotal = 20;
// // 同路由并发数
// private Integer defaultMaxPerRoute =20 ;
// private Integer connectTimeout = 2000;
// private Integer connectionRequestTimeout=2000;
// private Integer socketTimeout= 2000;
// // 线程空闲多久后进行校验
// private Integer validateAfterInactivity= 2000;
// // 重试次数
// private Integer retryTimes = 2;
//
// // 是否开启充实
// private boolean enableRetry = true;
// // 重试的间隔:可实现 ServiceUnavailableRetryStrategy 接口
// private Integer retryInterval= 2000;
//}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
import org.springframework.web.bind.annotation.*;

import se.michaelthelin.spotify.model_objects.special.SnapshotResult;
import se.michaelthelin.spotify.model_objects.specification.Paging;
import se.michaelthelin.spotify.model_objects.specification.Playlist;
import se.michaelthelin.spotify.model_objects.specification.PlaylistSimplified;

import java.util.Arrays;

Expand Down Expand Up @@ -58,7 +60,7 @@ public ResponseEntity addSongToList(@RequestBody AddSongToPlayListDto addSongToP

try{
log.info("received addSongToPlayListDto = " + addSongToPlayListDto);
addSongToPlayListDto.setPlaylistId("2cUyRMtc9AsinCLXFy0gcC");
//addSongToPlayListDto.setPlaylistId("2cUyRMtc9AsinCLXFy0gcC");
String[] trackList = addSongToPlayListDto.getSongUris().split(",");
log.info("received trackList = " + trackList.toString());
for (String x : trackList){
Expand All @@ -73,4 +75,16 @@ public ResponseEntity addSongToList(@RequestBody AddSongToPlayListDto addSongToP
}
}

@GetMapping("/userPlayList")
public ResponseEntity getUserPlayList(){

try{
Paging<PlaylistSimplified> userPlayList = playListService.getUserPlayList();
return ResponseEntity.status(HttpStatus.OK).body(userPlayList);
}catch (Exception e){
log.error("getUserPlayList error : " + e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public ResponseEntity getRecommendation(@RequestBody GetRecommendationsDto getRe
log.info("(getRecommendation) getRecommendationsDto = " + getRecommendationsDto.toString());
Recommendations recommendations = recommendationsService.getRecommendation(getRecommendationsDto);
return ResponseEntity.status(HttpStatus.OK).body(recommendations);

}catch (Exception e){
log.error("getRecommendation error : " + e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public SpotifyApi getBasicSpotifyClient(){
.build();
}

public SpotifyApi getBasicSpotifyClientWithToken(){

return new SpotifyApi.Builder()
.setAccessToken(accessToken)
.build();
}

public SpotifyApi getSpotifyClient(){

final URI redirectUri = SpotifyHttpManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.hc.core5.http.ParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import se.michaelthelin.spotify.SpotifyApi;
import se.michaelthelin.spotify.exceptions.SpotifyWebApiException;
import se.michaelthelin.spotify.model_objects.credentials.AuthorizationCodeCredentials;
import se.michaelthelin.spotify.model_objects.special.SnapshotResult;
import se.michaelthelin.spotify.model_objects.specification.Paging;
import se.michaelthelin.spotify.model_objects.specification.Playlist;
import se.michaelthelin.spotify.model_objects.specification.PlaylistSimplified;
import se.michaelthelin.spotify.requests.authorization.authorization_code.AuthorizationCodeRequest;
import se.michaelthelin.spotify.requests.data.playlists.AddItemsToPlaylistRequest;
import se.michaelthelin.spotify.requests.data.playlists.CreatePlaylistRequest;
import se.michaelthelin.spotify.requests.data.playlists.GetListOfUsersPlaylistsRequest;
import se.michaelthelin.spotify.requests.data.playlists.GetPlaylistRequest;

import java.io.IOException;
Expand All @@ -34,6 +38,9 @@ public class PlayListService {

private SpotifyApi spotifyApi;

@Value("${spotify.userId}")
private String userId;


public PlayListService(){

Expand Down Expand Up @@ -112,7 +119,8 @@ public SnapshotResult addSongToPlayList(AddSongToPlayListDto addSongToPlayListDt
final String playlistId = "7r3ntST7zTXRiTOFhkweIQ";
final String[] uris = new String[]{"spotify:track:0Sxq05leQaZXCktX05Kr7b"};

addSongToPlayListDto.setPlaylistId(playlistId);
//addSongToPlayListDto.setPlaylistId(playlistId);
addSongToPlayListDto.setPlaylistId(addSongToPlayListDto.getPlaylistId());
//addSongToPlayListDto.setSongUris(addSongToPlayListDto.getSongUris());
log.info("(addSongToPlayList) addSongToPlayListDto = " + addSongToPlayListDto);

Expand Down Expand Up @@ -141,4 +149,28 @@ public SnapshotResult addSongToPlayList(AddSongToPlayListDto addSongToPlayListDt
return snapshotResult;
}

public Paging<PlaylistSimplified> getUserPlayList(){

this.spotifyApi = authService.getSpotifyClient();
Paging<PlaylistSimplified> playlistSimplifiedPaging = null;
final GetListOfUsersPlaylistsRequest getListOfUsersPlaylistsRequest = spotifyApi
.getListOfUsersPlaylists(userId)
// .limit(10)
// .offset(0)
.build();

try {
playlistSimplifiedPaging = getListOfUsersPlaylistsRequest.execute();
PlaylistSimplified[] items = playlistSimplifiedPaging.getItems();
for (PlaylistSimplified item : items){
log.info("playList = " + item.getName() + " id = " + item.getId());
}
log.info("getUserPlayList OK");
} catch (IOException | SpotifyWebApiException | org.apache.hc.core5.http.ParseException e) {
log.error("getUserPlayList Error: " + e.getMessage());
}

return playlistSimplifiedPaging;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
server.port=8888

# Set the maximum total connections
spring.httpclient.max-connections=100
# Set the maximum connections per route
spring.httpclient.max-connections-per-route=20


spring.application.name=SpotifyPlayList
spotify.userId=62kytpy7jswykfjtnjn9zv3ou

spotify.clientId=
spotify.clientSecret=
spotify.redirectURL=http://localhost:8080/playlist
spotify.authorize.scope=playlist-modify-public,playlist-modify-private,user-read-private,user-read-email
#spotify.redirectURL=http://localhost:8080/recommendation
spotify.authorize.scope=playlist-modify-public,playlist-modify-private,user-read-private,user-read-email,streaming,user-modify-playback-state
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.yen.SpotifyPlayList;

import org.junit.jupiter.api.Test;
import se.michaelthelin.spotify.SpotifyApi;
import se.michaelthelin.spotify.exceptions.SpotifyWebApiException;
import se.michaelthelin.spotify.model_objects.specification.Paging;
import se.michaelthelin.spotify.model_objects.specification.PlaylistSimplified;
import se.michaelthelin.spotify.requests.data.playlists.GetListOfUsersPlaylistsRequest;

import java.io.IOException;
import java.text.ParseException;

public class GetListOfUsersPlaylistsTest {

// https://github.com/spotify-web-api-java/spotify-web-api-java/blob/master/examples/data/playlists/GetListOfUsersPlaylistsExample.java
@Test
public void getUserPlayList(){

// replace below with yours
final String accessToken = "BQBwj40F-tTXYd5EgeI7wB2nawCRGIci_SlLiam-Z5FTwOImU2-kIS6hwMs_L2pwpqaoHUbuKPHvq85ZxXIDJOYIblidKo9VnMlr7WpP7YqJqLjLY48";
final String userId = "62kytpy7jswykfjtnjn9zv3ou";

final SpotifyApi spotifyApi = new SpotifyApi.Builder()
.setAccessToken(accessToken)
.build();

final GetListOfUsersPlaylistsRequest getListOfUsersPlaylistsRequest = spotifyApi
.getListOfUsersPlaylists(userId)
// .limit(10)
// .offset(0)
.build();

try {
final Paging<PlaylistSimplified> playlistSimplifiedPaging = getListOfUsersPlaylistsRequest.execute();

PlaylistSimplified[] items = playlistSimplifiedPaging.getItems();
for (PlaylistSimplified item : items){
System.out.println("playList = " + item.getName() + " id = " + item.getId());
}


System.out.println("Total: " + playlistSimplifiedPaging.getTotal());
System.out.println("getUserPlayList OK");
} catch (IOException | SpotifyWebApiException | org.apache.hc.core5.http.ParseException e) {
System.out.println("getUserPlayList Error: " + e.getMessage());
}

}

}
Loading