mirror of
https://github.com/sascha-hemi/SpotifyEsp32.git
synced 2026-03-21 05:06:29 +01:00
all functions working
This commit is contained in:
@@ -94,6 +94,8 @@ response Spotify::RestApiPut(char rest_url[_size_of_possibly_large_char], String
|
||||
//TODO: Add rexex ([^\/]+$) to extract last text (pause/play etc.) from uri and put into debug info
|
||||
Serial.print("URL: ");
|
||||
Serial.println(rest_url);
|
||||
Serial.print("Payload: ");
|
||||
Serial.println(payload);
|
||||
Serial.print("PUT status: ");
|
||||
Serial.println(http_code);
|
||||
Serial.print(" Reply: ");
|
||||
@@ -107,7 +109,7 @@ response Spotify::RestApiPut(char rest_url[_size_of_possibly_large_char], String
|
||||
if(message == "Only valid bearer authentication supported"){
|
||||
_retry++;
|
||||
if(get_token()){
|
||||
response_obj = RestApiPut(rest_url);
|
||||
response_obj = RestApiPut(rest_url, payload);
|
||||
}
|
||||
}
|
||||
else{
|
||||
@@ -146,6 +148,8 @@ response Spotify::RestApiPost(char rest_url[100], String payload){
|
||||
//TODO: Add rexex ([^\/]+$) to extract last text (pause/play etc.) from uri and put into debug info
|
||||
Serial.print("URL: ");
|
||||
Serial.println(rest_url);
|
||||
Serial.print("Payload: ");
|
||||
Serial.println(payload);
|
||||
Serial.print("POST status: ");
|
||||
Serial.println(http_code);
|
||||
Serial.print(" Reply: ");
|
||||
@@ -159,7 +163,7 @@ response Spotify::RestApiPost(char rest_url[100], String payload){
|
||||
if(message == "Only valid bearer authentication supported"){
|
||||
_retry++;
|
||||
if(get_token()){
|
||||
response_obj = RestApiPost(rest_url);
|
||||
response_obj = RestApiPost(rest_url, payload);
|
||||
}
|
||||
}
|
||||
else{
|
||||
@@ -196,6 +200,8 @@ response Spotify::RestApiDelete(char rest_url[100], String payload){
|
||||
// TODO: Add regex ([^\/]+$) to extract last text (pause/play etc.) from uri and put into debug info
|
||||
Serial.print("URL: ");
|
||||
Serial.println(rest_url);
|
||||
Serial.print("Payload: ");
|
||||
Serial.println(payload);
|
||||
Serial.print("DELETE status: ");
|
||||
Serial.println(http_code);
|
||||
Serial.print(" Reply: ");
|
||||
@@ -209,7 +215,7 @@ response Spotify::RestApiDelete(char rest_url[100], String payload){
|
||||
if (message == "Only valid bearer authentication supported") {
|
||||
_retry++;
|
||||
if (get_token()) {
|
||||
response_obj = RestApiDelete(rest_url);
|
||||
response_obj = RestApiDelete(rest_url, payload);
|
||||
}
|
||||
} else {
|
||||
response_obj.reply = message;
|
||||
@@ -548,15 +554,14 @@ response Spotify::get_playlist(String playlist_id, String fields) {
|
||||
response Spotify::change_playlist_details(String playlist_id, String name, bool is_public, bool is_collaborative, String description) {
|
||||
String url = "https://api.spotify.com/v1/playlists/";
|
||||
url += playlist_id;
|
||||
|
||||
DynamicJsonDocument doc(400);
|
||||
if (is_public && is_collaborative){
|
||||
is_collaborative = false;
|
||||
}
|
||||
DynamicJsonDocument doc(400);
|
||||
|
||||
}
|
||||
doc["collaborative"] = is_collaborative;
|
||||
doc["name"] = name;
|
||||
doc["public"] = is_public;
|
||||
doc["collaborative"] = is_collaborative;
|
||||
doc["description"] = description;
|
||||
|
||||
String payload;
|
||||
@@ -573,7 +578,15 @@ response Spotify::get_playlist_items(String playlist_id, String fields, int limi
|
||||
response Spotify::update_playlist_items(String playlist_id, String uris, int range_start, int insert_before, int range_length) {
|
||||
String url = "https://api.spotify.com/v1/playlists/";
|
||||
url += playlist_id + "/tracks";
|
||||
String payload = "{\"uris\":\"" + uris + "\",\"range_start\":" + String(range_start) + ",\"insert_before\":" + String(insert_before) + ",\"range_length\":\"" + String(range_length) + "\"}";
|
||||
|
||||
DynamicJsonDocument doc(800);
|
||||
doc["uris"] = uris;
|
||||
doc["range_start"] = range_start;
|
||||
doc["insert_before"] = insert_before;
|
||||
doc["range_length"] = range_length;
|
||||
|
||||
String payload;
|
||||
serializeJson(doc, payload);
|
||||
|
||||
return RestApiPut(const_cast<char*>(url.c_str()), payload);
|
||||
}
|
||||
@@ -610,7 +623,19 @@ response Spotify::get_user_playlists(String user_id, int limit, int offset) {
|
||||
response Spotify::create_playlist(String user_id, String name, bool is_public, bool is_collaborative, String description) {
|
||||
String url = "https://api.spotify.com/v1/users/";
|
||||
url += user_id + "/playlists";
|
||||
String payload = "{\"name\":\"" + name + "\",\"public\":" + (is_public ? "true" : "false") + ",\"collaborative\":" + (is_collaborative ? "true" : "false")+"\",\"public\":"+description +"\"}";
|
||||
|
||||
if (is_public && is_collaborative){
|
||||
is_collaborative = false;
|
||||
}
|
||||
|
||||
DynamicJsonDocument doc(256);
|
||||
doc["name"] = name;
|
||||
doc["public"] = is_public;
|
||||
doc["collaborative"] = is_collaborative;
|
||||
doc["description"] = description;
|
||||
String payload;
|
||||
serializeJson(doc, payload);
|
||||
|
||||
return RestApiPost(const_cast<char*>(url.c_str()),payload);
|
||||
}
|
||||
response Spotify::get_featured_playlists(String country, String locale, String timestamp, int limit, int offset) {
|
||||
@@ -810,8 +835,8 @@ void Spotify::init_response(response* response_obj){
|
||||
void print_response(response response_obj){
|
||||
Serial.print("Status: ");
|
||||
Serial.println(response_obj.status_code);
|
||||
//Serial.print("Reply: ");
|
||||
//Serial.println(response_obj.reply);
|
||||
Serial.print("Reply: ");
|
||||
Serial.println(response_obj.reply);
|
||||
}
|
||||
bool Spotify::get_token(){
|
||||
bool reply = false;
|
||||
|
||||
@@ -37,11 +37,11 @@ String category_id = "dinner";
|
||||
String episode_id = "3UHFkXFDAHr7cBlRoUmdiY";
|
||||
String episode_ids = "4H4ZXQ07SehfQDAImiHOXF,3UHFkXFDAHr7cBlRoUmdiY";
|
||||
|
||||
String playlist_id = "6lGlX7KRHmy6AuF5NFT0TW";
|
||||
String playlist_id = "5ZJAomiAtiow9nTloNl01E";
|
||||
String fields = "items(track(name,href,album(name,href)))";
|
||||
String uris_array = "";
|
||||
|
||||
String user_id = "chaerne";
|
||||
String user_id = "adix3gjuq0g570rwufhfcw89o";
|
||||
|
||||
String show_id = "5CfCWKI5pZ28U0uOzXkDHe";
|
||||
String show_ids = "5CfCWKI5pZ28U0uOzXkDHe,5as3aKmN2k11yfDDDSrvaZ";
|
||||
@@ -51,6 +51,9 @@ String artist_user_ids = "2CIMQHirSU0MQqyYHq0eOx,57dN52uHvrHOxijzpIgu3E,1vCWHaC5
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
connectToWifi();
|
||||
|
||||
Serial.println("change_playlist_details: ");
|
||||
print_response(sp.change_playlist_details(playlist_id, "Hello", false, false, "WTF!!"));
|
||||
}
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
@@ -224,12 +227,13 @@ void test_markets(){
|
||||
void test_playlist(){
|
||||
Serial.println("get_playlist: ");
|
||||
print_response(sp.get_playlist(playlist_id, fields));
|
||||
//Not working JSON parsing error
|
||||
|
||||
Serial.println("change_playlist_details: ");
|
||||
print_response(sp.change_playlist_details(playlist_id, "Hello", false, false, "WTF!!"));
|
||||
|
||||
Serial.println("get_playlist_items: ");
|
||||
print_response(sp.get_playlist_items(playlist_id, fields));
|
||||
|
||||
//Not working (missing part of implementation)
|
||||
Serial.println("update_playlist_items: ");
|
||||
print_response(sp.update_playlist_items(playlist_id, sp.convert_id_to_uri(song_id,TYPE_TRACK)));
|
||||
@@ -245,7 +249,7 @@ void test_playlist(){
|
||||
|
||||
Serial.println("get_user_playlists: ");
|
||||
print_response(sp.get_user_playlists(user_id));
|
||||
//Not Working JSON parsing error
|
||||
|
||||
Serial.println("create_playlist: ");
|
||||
print_response(sp.create_playlist(user_id, "Test", true, false, "no"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user