mirror of
https://github.com/sascha-hemi/SpotifyEsp32.git
synced 2026-03-21 00:04:00 +01:00
Fixed issues in Get Recommendations and added a
check all function to main.cpp
This commit is contained in:
2
Spotify_v3/.gitignore
vendored
2
Spotify_v3/.gitignore
vendored
@@ -3,3 +3,5 @@
|
||||
.vscode/c_cpp_properties.json
|
||||
.vscode/launch.json
|
||||
.vscode/ipch
|
||||
src/config.h
|
||||
TODO.txt
|
||||
@@ -4,4 +4,5 @@ otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x180000,
|
||||
app1, app, ota_1, 0x190000,0x180000,
|
||||
eeprom, data, 0x99, 0x310000,0x1000,
|
||||
spiffs, data, spiffs, 0x311000,0xEF000,
|
||||
coredump, data, coredump,0x311000,0x10000,
|
||||
spiffs, data, spiffs, 0x321000,0xDF000,
|
||||
|
@@ -9,6 +9,9 @@ namespace Spotify_types {
|
||||
char* TYPE_ARTIST = "artist";
|
||||
char* TYPE_TRACK = "track";
|
||||
char* TYPE_PLAYLIST = "playlist";
|
||||
char* TYPE_SHOW = "show";
|
||||
char* TYPE_EPISODE = "episode";
|
||||
char* TYPE_AUDIOBOOK = "audiobook";
|
||||
char* TOP_TYPE_ARTIST = "artists";
|
||||
char* TOP_TYPE_TRACKS = "tracks";
|
||||
char* GROUP_ALBUM = "album";
|
||||
@@ -18,6 +21,8 @@ namespace Spotify_types {
|
||||
char* TIME_RANGE_SHORT = "short_term";
|
||||
char* TIME_RANGE_MEDIUM = "medium_term";
|
||||
char* TIME_RANGE_LONG = "long_term";
|
||||
char* FOLLOW_TYPE_ARTIST = "artist";
|
||||
char* FOLLOW_TYPE_USER = "user";
|
||||
int SIZE_OF_ID = 40;
|
||||
int SIZE_OF_URI = 50;
|
||||
}
|
||||
@@ -170,17 +175,16 @@ response Spotify::RestApi(char* rest_url, char* type, int payload_size, char* pa
|
||||
http.addHeader("Accept", "application/json");
|
||||
http.addHeader("Content-Type", "application/json");
|
||||
http.addHeader("Authorization","Bearer "+_access_token);
|
||||
if(payload_size>0){
|
||||
http.addHeader("content-Length", String(payload_size));
|
||||
}
|
||||
int http_code = -1;
|
||||
if(strcmp(type, "GET") == 0){
|
||||
http_code = http.GET();
|
||||
}
|
||||
else if(strcmp(type, "PUT") == 0){
|
||||
http.addHeader("content-Length", String(payload_size));
|
||||
http_code = http.PUT(payload);
|
||||
}
|
||||
else if(strcmp(type, "POST") == 0){
|
||||
http.addHeader("content-Length", String(payload_size));
|
||||
http_code = http.POST(payload);
|
||||
}
|
||||
else if(strcmp(type, "DELETE") == 0){
|
||||
@@ -265,7 +269,7 @@ bool Spotify::get_token(){
|
||||
|
||||
void Spotify::init_response(response* response_obj){
|
||||
response_obj -> status_code = -1;
|
||||
response_obj -> reply ="If you see this something went wrong";
|
||||
response_obj -> reply ="If you see this something went wrong, if the issue persists please contact the developer";
|
||||
}
|
||||
char* Spotify::array_to_char(int size, char** array, char* result) {
|
||||
result[0] = '\0';
|
||||
@@ -285,7 +289,6 @@ void Spotify::array_to_json_array(int size, char** array, char* data, int data_s
|
||||
}
|
||||
serializeJson(json_array,data,data_size);
|
||||
}
|
||||
|
||||
const char* Spotify::extract_endpoint(const char* url){
|
||||
std::regex pattern(R"(https://api\.spotify\.com/v1/([^?]+))");
|
||||
std::cmatch match;
|
||||
@@ -1025,7 +1028,7 @@ response Spotify::get_recommendations(recommendations& recom, int limit){
|
||||
|
||||
for (const auto& param : char_params) {
|
||||
char value[100];
|
||||
snprintf(value, sizeof(value), "&%s%s",param.first, param.second);
|
||||
snprintf(value, sizeof(value), "&%s=%s",param.first, param.second);
|
||||
strcat(url, value);
|
||||
}
|
||||
for(const auto& param : float_params){
|
||||
@@ -1033,7 +1036,6 @@ response Spotify::get_recommendations(recommendations& recom, int limit){
|
||||
snprintf(value, sizeof(value), "&%s=%f",param.first, param.second);
|
||||
strcat(url, value);
|
||||
}
|
||||
|
||||
return RestApiGet(url);
|
||||
}
|
||||
bool Spotify::is_valid_value(float param) {
|
||||
|
||||
@@ -43,6 +43,9 @@ namespace Spotify_types {
|
||||
extern char* TYPE_ALBUM;
|
||||
extern char* TYPE_ARTIST;
|
||||
extern char* TYPE_TRACK;
|
||||
extern char* TYPE_SHOW;
|
||||
extern char* TYPE_EPISODE;
|
||||
extern char* TYPE_AUDIOBOOK;
|
||||
extern char* TYPE_PLAYLIST;
|
||||
extern char* TOP_TYPE_ARTIST;
|
||||
extern char* TOP_TYPE_TRACKS;
|
||||
@@ -53,6 +56,8 @@ namespace Spotify_types {
|
||||
extern char* TIME_RANGE_SHORT;
|
||||
extern char* TIME_RANGE_MEDIUM;
|
||||
extern char* TIME_RANGE_LONG;
|
||||
extern char* FOLLOW_TYPE_ARTIST;
|
||||
extern char* FOLLOW_TYPE_USER;
|
||||
extern int SIZE_OF_ID;
|
||||
extern int SIZE_OF_URI;
|
||||
|
||||
@@ -475,13 +480,13 @@ class Spotify {
|
||||
#ifdef ENABLE_SEARCH
|
||||
/// @brief Search for an item
|
||||
/// @param q Search query keywords and optional field filters and operators
|
||||
/// @param type_size Number of item types in type array,needs to e set to 0 if limit, offset or market is used and type is not used
|
||||
/// @param type A comma-separated list of item types to search across, needs to be set to nullptr if limit, offset or market is used and type is not used
|
||||
/// @param type_size Number of item types in type array
|
||||
/// @param type An array of item types to search across
|
||||
/// @param limit The maximum number of items to return
|
||||
/// @param offset The index of the first item to return
|
||||
/// @param market An ISO 3166-1 alpha-2 country code or the string from_token. Provide this parameter if you want the list of returned items to be relevant to a particular country.
|
||||
/// @return response object containing http status code and reply
|
||||
response search(char* q,int type_size = 0, char** type = nullptr, int limit = 10, int offset = 0, char* market = nullptr);
|
||||
response search(char* q,int type_size , char** type , int limit = 10, int offset = 0, char* market = nullptr);
|
||||
#endif
|
||||
#ifdef ENABLE_SHOWS
|
||||
/// @brief Get Spotify information for a single show
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
const char* SSID = "Rebweg10D";
|
||||
const char* PASSWORD = "Bitte_eintreten";
|
||||
/*const char* SSID = "rdv-66754";
|
||||
const char* PASSWORD = "1234567890";*/
|
||||
const char* CLIENT_ID = "4a60dc25e5eb43e29161a0b00d296ff7";
|
||||
const char* CLIENT_SECRET = "d65a695928b34a4ea3a0e66d9120b911";
|
||||
const char* REFRESH_TOKEN = "AQC_3lM_jUt1Zgag5UO4qtOZcqCHSprkjsq6tvamaH2nXjn5xSyU0yuFXpi1M1YTNPyHEaBHpe1nWTOA_PkalojPGY8XfxS0kxFjFaZxbE2B4sQvVvSfgi6JIZrwYIwWYuo";
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
using namespace Spotify_types;
|
||||
|
||||
void connect_to_wifi();
|
||||
|
||||
|
||||
Spotify sp(CLIENT_ID, CLIENT_SECRET,REFRESH_TOKEN);
|
||||
void check_all();
|
||||
void check_one(response r);
|
||||
Spotify sp(CLIENT_ID, CLIENT_SECRET,REFRESH_TOKEN, false);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
@@ -17,7 +17,8 @@ void setup() {
|
||||
sp.handle_client();
|
||||
}
|
||||
Serial.println("Authenticated");
|
||||
Serial.println(sp.current_artist_names());
|
||||
check_all();
|
||||
Serial.println("Done");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -32,3 +33,117 @@ void connect_to_wifi(){
|
||||
}
|
||||
Serial.printf("\nConnected to WiFi\n");
|
||||
}
|
||||
void check_all(){
|
||||
/*Serial.println("Player");
|
||||
check_one(sp.currently_playing());
|
||||
check_one(sp.start_resume_playback("spotify:track:6xaMXvpkmVow1RAinlthUT"));
|
||||
check_one(sp.pause_playback());
|
||||
check_one(sp.start_resume_playback());
|
||||
check_one(sp.skip());
|
||||
check_one(sp.previous());
|
||||
check_one(sp.available_devices());
|
||||
check_one(sp.current_playback_state());
|
||||
check_one(sp.recently_played_tracks());
|
||||
check_one(sp.seek_to_position(1000));
|
||||
check_one(sp.add_to_queue("spotify:track:6xaMXvpkmVow1RAinlthUT"));
|
||||
check_one(sp.get_queue());
|
||||
check_one(sp.repeat_mode(REPEAT_OFF));
|
||||
check_one(sp.shuffle(SHUFFLE_ON));
|
||||
check_one(sp.transfer_playback("956f01ff586ece9abaa152dd26bc5cc565be5a22"));
|
||||
check_one(sp.set_volume(100));
|
||||
Serial.println("Album");
|
||||
check_one(sp.get_album("22pMyI5Ra0xRPDpf21ZWNb"));
|
||||
char* albums[] = {"22pMyI5Ra0xRPDpf21ZWNb", "5AXd8wp7NNydXNzFAxlXmf"};
|
||||
check_one(sp.get_albums(2, albums));
|
||||
check_one(sp.get_album_tracks("22pMyI5Ra0xRPDpf21ZWNb"));
|
||||
check_one(sp.get_users_saved_albums());
|
||||
check_one(sp.remove_users_saved_albums(2, albums));
|
||||
check_one(sp.save_albums_for_current_user(2, albums));
|
||||
check_one(sp.check_useres_saved_albums(2, albums));
|
||||
check_one(sp.get_new_releases());
|
||||
Serial.println("Artist");
|
||||
check_one(sp.get_artist("7keGfmQR4X5w0two1xKZ7d"));
|
||||
char* artists[] = {"7keGfmQR4X5w0two1xKZ7d", "6LtXxYMIiKSy2EGHnz1f5j"};
|
||||
check_one(sp.get_several_artists(2, artists));
|
||||
char * group[] = {GROUP_ALBUM, GROUP_SINGLE, GROUP_APPEARS_ON, GROUP_COMPILATION};
|
||||
check_one(sp.get_artist_albums("7keGfmQR4X5w0two1xKZ7d", 4, group));
|
||||
check_one(sp.get_artist_top_tracks("7keGfmQR4X5w0two1xKZ7d", "DE"));
|
||||
check_one(sp.get_artist_related_artist("7keGfmQR4X5w0two1xKZ7d"));
|
||||
Serial.println("Browse");
|
||||
check_one(sp.get_several_browse_categories());
|
||||
check_one(sp.get_single_browse_category("dinner"));
|
||||
Serial.println("Episode");
|
||||
check_one(sp.get_episode("3mbWNOW6PwYGrXANw2JJDU"));
|
||||
char* episodes[] = {"3mbWNOW6PwYGrXANw2JJDU", "4hwEvITXPZvcvL8UCVEp6Q"};
|
||||
check_one(sp.get_several_episodes(2, episodes));
|
||||
check_one(sp.get_users_saved_episodes());
|
||||
check_one(sp.save_episodes_for_current_user(2, episodes));
|
||||
check_one(sp.remove_episodes_for_current_user(2, episodes));
|
||||
check_one(sp.check_users_saved_episodes(2, episodes));
|
||||
Serial.println("Markets and Genres");
|
||||
check_one(sp.get_available_genre_seeds());
|
||||
check_one(sp.get_available_markets());
|
||||
Serial.println("Playlists");
|
||||
check_one(sp.get_playlist("37i9dQZF1EQn4jwNIohw50"));
|
||||
check_one(sp.change_playlist_details("39Swnx8UEHw4FK9FlQHCov", "New Name", false, false, "New Description"));
|
||||
check_one(sp.get_playlist_items("37i9dQZF1EQn4jwNIohw50","items(added_by.id,track(name,href,album(name,href)))"));
|
||||
char* tracks[] = {"spotify:track:6xaMXvpkmVow1RAinlthUT", "spotify:track:6xaMXvpkmVow1RAinlthUT"};
|
||||
check_one(sp.update_playlist_items("39Swnx8UEHw4FK9FlQHCov", 2, tracks));
|
||||
check_one(sp.remove_playlist_items("39Swnx8UEHw4FK9FlQHCov", 2, tracks));
|
||||
check_one(sp.add_items_to_playlist("39Swnx8UEHw4FK9FlQHCov", 2, tracks));
|
||||
check_one(sp.get_current_users_playlists());
|
||||
check_one(sp.get_user_playlists("spotify"));
|
||||
check_one(sp.create_playlist("adix3gjuq0g570rwufhfcw89o","New Playlist", false,true, "New Description"));
|
||||
check_one(sp.get_featured_playlists());
|
||||
check_one(sp.get_category_playlists("dinner"));
|
||||
check_one(sp.get_playlist_cover_image("37i9dQZF1EQn4jwNIohw50"));
|
||||
check_one(sp.add_custom_playlist_cover_image("39Swnx8UEHw4FK9FlQHCov", "/9j/2wCEABoZGSccJz4lJT5CLy8vQkc9Ozs9R0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0cBHCcnMyYzPSYmPUc9Mj1HR0dEREdHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR0dHR//dAAQAAf/uAA5BZG9iZQBkwAAAAAH/wAARCAABAAEDACIAAREBAhEB/8QASwABAQAAAAAAAAAAAAAAAAAAAAYBAQAAAAAAAAAAAAAAAAAAAAAQAQAAAAAAAAAAAAAAAAAAAAARAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwAAARECEQA/AJgAH//Z"));
|
||||
Serial.println("Search");
|
||||
char* types[] = {TYPE_ALBUM, TYPE_ARTIST, TYPE_PLAYLIST, TYPE_TRACK};
|
||||
check_one(sp.search("remaster%2520track%3ADoxy%2520artist%3AMiles%2520Davis", 4, types));
|
||||
Serial.println("Shows");
|
||||
check_one(sp.get_show("5icRmO26ZsDWsNjUy5rssH"));
|
||||
char* shows[] = {"5icRmO26ZsDWsNjUy5rssH", "3wBfqov60qDZbEVjPHo0a8"};
|
||||
check_one(sp.get_several_shows(2, shows));
|
||||
check_one(sp.get_show_episodes("5icRmO26ZsDWsNjUy5rssH"));
|
||||
check_one(sp.get_users_saved_shows());
|
||||
check_one(sp.save_shows_for_current_user(2, shows));
|
||||
check_one(sp.remove_shows_for_current_user(2, shows));
|
||||
check_one(sp.check_users_saved_shows(2, shows));
|
||||
Serial.println("Tracks");
|
||||
check_one(sp.get_track("49A10weBfgwg4TUM3My7iv"));
|
||||
char* tracks[] = {"49A10weBfgwg4TUM3My7iv", "3qhlB30KknSejmIvZZLjOD"};
|
||||
check_one(sp.get_several_tracks(2, tracks));
|
||||
check_one(sp.get_user_saved_tracks());
|
||||
check_one(sp.save_tracks_for_current_user(2, tracks));
|
||||
check_one(sp.remove_user_saved_tracks(2, tracks));
|
||||
check_one(sp.check_user_saved_tracks(2, tracks));
|
||||
check_one(sp.get_tracks_audio_features(2, tracks));
|
||||
check_one(sp.get_track_audio_analysis("49A10weBfgwg4TUM3My7iv"));
|
||||
check_one(sp.get_track_audio_features("49A10weBfgwg4TUM3My7iv"));
|
||||
recommendations r;
|
||||
char* seed_artists[] = {"4NHQUGzhtTLFvgF5SZesLK"};
|
||||
r.seed_artists = seed_artists;
|
||||
r.seed_artists_size = 1;
|
||||
r.target_acousticness = 0.5;
|
||||
r.target_danceability = 0.5;
|
||||
check_one(sp.get_recommendations(r, 2));
|
||||
Serial.println("User");
|
||||
check_one(sp.get_current_user_profile());
|
||||
check_one(sp.get_user_profile("spotify"));
|
||||
check_one(sp.get_user_top_items(TOP_TYPE_ARTIST));
|
||||
check_one(sp.follow_playlist("37i9dQZF1EQn4jwNIohw50", false));
|
||||
check_one(sp.unfollow_playlist("37i9dQZF1EQn4jwNIohw50"));
|
||||
char* users[] = {"spotify"};
|
||||
check_one(sp.check_if_users_follow_playlist("37i9dQZF1EQn4jwNIohw50",1, users));
|
||||
check_one(sp.get_followed_artists(""));
|
||||
check_one(sp.follow_artists_or_users(FOLLOW_TYPE_USER, 1, users));
|
||||
check_one(sp.unfollow_artists_or_users(FOLLOW_TYPE_USER, 1, users));
|
||||
check_one(sp.check_if_user_follows_artists_or_users(FOLLOW_TYPE_USER, 1, users));*/
|
||||
}
|
||||
void check_one(response r){
|
||||
if(r.status_code < 200 or r.status_code > 300){
|
||||
Serial.printf("Error: %d\n", r.status_code);
|
||||
Serial.println(r.reply);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user