diff --git a/README.md b/README.md index 2186772..10646c7 100644 --- a/README.md +++ b/README.md @@ -114,9 +114,9 @@ To print the response you can use the ```print_response(response_obj)``` functio ``` - You can also include the namespace: ```using namespace Spotify_types;```. These are some types used in the library eg. TYPES, SIZES of uris/ids
## Trouble Shooting -- If you have any problems with the library you can use the debug mode to print out the data to the serial monitor. I recommend not setting the baud rate lower than 115200 as the data printed can be quite large which can lead to crash if the Serial communication is too slow
+- If you have any problems with the library you can use the debug mode to print out the data to the serial monitor. I recommend not setting the baud rate lower than 115200 as the data printed can be quite large which can lead to crash if the Serial communication is too slow.
- If you have any problems with the library you can also use the [Spotify Web API Console](https://developer.spotify.com/console/) to test the endpoints.
- If there are still issues you can open an issue on this repository.
-### Working Devices +## Working Devices - ESP32 WROOM
- Should also work on ESP2866 and other ESP32 models(Untested).
diff --git a/Spotify_Esp32.code-workspace b/Spotify_Esp32.code-workspace new file mode 100644 index 0000000..c4c9818 --- /dev/null +++ b/Spotify_Esp32.code-workspace @@ -0,0 +1,12 @@ +{ + "folders": [ + { + "path": "." + }, + { + "name": "Spotify_v3", + "path": "Spotify_v3" + } + ], + "settings": {} +} \ No newline at end of file diff --git a/Spotify_v3/partitions.csv b/Spotify_v3/partitions.csv new file mode 100644 index 0000000..19a5f56 --- /dev/null +++ b/Spotify_v3/partitions.csv @@ -0,0 +1,7 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x5000, +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, \ No newline at end of file diff --git a/Spotify_v3/platformio.ini b/Spotify_v3/platformio.ini index 31474ca..aa216bd 100644 --- a/Spotify_v3/platformio.ini +++ b/Spotify_v3/platformio.ini @@ -12,10 +12,11 @@ platform = espressif32 board = esp32doit-devkit-v1 framework = arduino +board_build.partitions = partitions.csv lib_deps = plageoj/UrlEncode@^1.0.1 bblanchon/ArduinoJson@^7.0.3 esphome/AsyncTCP-esphome@^2.1.2 monitor_filters = esp32_exception_decoder monitor_speed = 115200 -build_flags = -w \ No newline at end of file +build_flags = -Og \ No newline at end of file diff --git a/Spotify_v3/src/SpotifyESP32.cpp b/Spotify_v3/src/SpotifyESP32.cpp index 1b1f8d1..0a6140e 100644 --- a/Spotify_v3/src/SpotifyESP32.cpp +++ b/Spotify_v3/src/SpotifyESP32.cpp @@ -173,7 +173,7 @@ response Spotify::RestApi(char* rest_url, char* type, int payload_size, char* pa if(payload_size>0){ http.addHeader("content-Length", String(payload_size)); } - int http_code; + int http_code = -1; if(strcmp(type, "GET") == 0){ http_code = http.GET(); } @@ -819,36 +819,37 @@ response Spotify::create_playlist(char* user_id, char* name, bool is_public, boo return RestApiPost(url, payload_size, payload); } -response Spotify::get_featured_playlists( int limit, int offset,char* timestamp,char* country, char* locale) { - char url[200]; - if(timestamp != nullptr){ - if((country == nullptr)&&(locale == nullptr)){ - snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?timestamp=%s&limit=%d&offset=%d", timestamp, limit, offset); +response Spotify::get_featured_playlists(int limit, int offset, char* timestamp, char* country, char* locale) { + char url[200]; + if (timestamp) { + if (!country && !locale) { + snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?timestamp=%s&limit=%d&offset=%d", timestamp, limit, offset); + } + else if (!country && locale) { + snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?locale=%s×tamp=%s&limit=%d&offset=%d", locale, timestamp, limit, offset); + } + else if (country && !locale) { + snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?country=%s×tamp=%s&limit=%d&offset=%d", country, timestamp, limit, offset); + } + else { + snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?country=%s&locale=%s×tamp=%s&limit=%d&offset=%d", country, locale, timestamp, limit, offset); + } } - else if((country == nullptr)&&(locale != nullptr)){ - snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?locale=%s×tamp=%s&limit=%d&offset=%d", locale, timestamp, limit, offset); + else { + if (!country && !locale) { + snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?limit=%d&offset=%d", limit, offset); + } + else if (!country && locale) { + snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?locale=%s&limit=%d&offset=%d", locale, limit, offset); + } + else if (country && !locale) { + snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?country=%s&limit=%d&offset=%d", country, limit, offset); + } + else { + snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?country=%s&locale=%s&limit=%d&offset=%d", country, locale, limit, offset); + } } - else if((country != nullptr)&&(locale == nullptr)){ - snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?country=%s×tamp=%s&limit=%d&offset=%d", country, timestamp, limit, offset); - } - else{ - snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?country=%s&locale=%s×tamp=%s&limit=%d&offset=%d", country, locale, timestamp, limit, offset); - } - }else{ - if((country == nullptr)&&(locale == nullptr)){ - snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?limit=%d&offset=%d", limit, offset); - } - else if((country == nullptr)&&(locale != nullptr)){ - snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?locale=%s&limit=%d&offset=%d", locale, limit, offset); - } - else if((country != nullptr)&&(locale == nullptr)){ - snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?country=%s&limit=%d&offset=%d", country, limit, offset); - } - else{ - snprintf(url, sizeof(url), "https://api.spotify.com/v1/browse/featured-playlists?country=%s&locale=%s&limit=%d&offset=%d", country, locale, limit, offset); - } - } - return RestApiGet(url); + return RestApiGet(url); } response Spotify::get_category_playlists(char* category_id, int limit, int offset, char* country) { char url[200]; @@ -880,7 +881,7 @@ response Spotify::add_custom_playlist_cover_image(char* playlist_id, char* data) response Spotify::search(char* q, int type_size, char** type, int limit, int offset, char* market){ char url[_max_char_size]; char arr[_max_char_size]; - if(market != nullptr){ + if(market){ if(type_size == 0){ snprintf(url, sizeof(url), "https://api.spotify.com/v1/search?q=%s&limit=%d&offset=%d&market=%s", q, limit, offset, market); } @@ -891,10 +892,10 @@ response Spotify::search(char* q, int type_size, char** type, int limit, int off } else{ if(type_size == 0){ - snprintf(url, sizeof(url), "https://api.spotify.com/v1/search?q=%s&limit=%d&offset=%d&market=%s", q, limit, offset, market); + snprintf(url, sizeof(url), "https://api.spotify.com/v1/search?q=%s&limit=%d&offset=%d", q, limit, offset); } else{ - snprintf(url, sizeof(url), "https://api.spotify.com/v1/search?q=%s&type=%s&limit=%d&offset=%d&market=%s", q, array_to_char(type_size, type, arr), limit, offset, market); + snprintf(url, sizeof(url), "https://api.spotify.com/v1/search?q=%s&type=%s&limit=%d&offset=%d", q, array_to_char(type_size, type, arr), limit, offset); } } @@ -1230,7 +1231,7 @@ response Spotify::unfollow_playlist(char* playlist_id) { return RestApiDelete(url); } -response Spotify::get_followed_artists(char* type, char* after, int limit) { +response Spotify::get_followed_artists(char* after, char* type, int limit) { char url[100]; snprintf(url, sizeof(url), "https://api.spotify.com/v1/me/following?type=%s&after=%s&limit=%d", type, after, limit); diff --git a/Spotify_v3/src/SpotifyESP32.h b/Spotify_v3/src/SpotifyESP32.h index 6064f4d..f5d85c1 100644 --- a/Spotify_v3/src/SpotifyESP32.h +++ b/Spotify_v3/src/SpotifyESP32.h @@ -139,8 +139,8 @@ class Spotify { void begin(); /// @brief handle client requests necessary for authentication void handle_client(); - ///@brief Check if user is authenticated - ///@return true if user is authenticated + /// @brief Check if user is authenticated + /// @return true if user is authenticated bool is_auth(); #ifdef ENABLE_PLAYER ///@brief Get information about the user's current playback state, including track, track progress, and active device. @@ -479,7 +479,7 @@ class Spotify { /// @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 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 to apply Track Relinking + /// @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); #endif