@@ -4,6 +4,7 @@ package com.adamratzman.spotify.models
4
4
import com.adamratzman.spotify.endpoints.client.ClientPlaylistAPI
5
5
import com.adamratzman.spotify.main.SpotifyAPI
6
6
import com.adamratzman.spotify.main.SpotifyRestAction
7
+ import com.adamratzman.spotify.utils.match
7
8
import com.beust.klaxon.Json
8
9
9
10
/* *
@@ -608,6 +609,16 @@ data class Playlist(
608
609
data class RecommendationResponse (val seeds : List <RecommendationSeed >, val tracks : List <SimpleTrack >)
609
610
610
611
/* *
612
+ * The Audio Analysis endpoint provides low-level audio analysis for all of the tracks
613
+ * in the Spotify catalog. The Audio Analysis describes the track’s structure
614
+ * and musical content, including rhythm, pitch, and timbre. All information is
615
+ * precise to the audio sample. Many elements of analysis include confidence values,
616
+ * a floating-point number ranging from 0.0 to 1.0. Confidence indicates the reliability
617
+ * of its corresponding attribute. Elements carrying a small confidence value should
618
+ * be considered speculative. There may not be sufficient data in the audio to
619
+ * compute the attribute with high certainty.
620
+ *
621
+ *
611
622
* @param bars The time intervals of the bars throughout the track. A bar (or measure) is a segment of time defined as
612
623
* a given number of beats. Bar offsets also indicate downbeats, the first beat of the measure.
613
624
* @param beats The time intervals of beats throughout the track. A beat is the basic time unit of a piece of music;
@@ -631,6 +642,17 @@ data class AudioAnalysis(
631
642
val track : TrackAnalysis
632
643
)
633
644
645
+ /* *
646
+ * Information about the analysis run
647
+ *
648
+ * @param analyzerVersion Which version of the Spotify analyzer the analysis was run on
649
+ * @param platform The OS the analysis was run on
650
+ * @param detailedStatus Whether there was an error in the analysis or "OK"
651
+ * @param statusCode 0 on success, any other integer on error
652
+ * @param timestamp When this analysis was completed
653
+ * @param analysisTime How long, in milliseconds, this analysis took to run
654
+ * @param inputProcess The process used in the analysis
655
+ */
634
656
data class AudioAnalysisMeta (
635
657
@Json(name = " analyzer_version" ) val analyzerVersion : String ,
636
658
val platform : String ,
@@ -824,22 +846,55 @@ abstract class RelinkingAvailableResponse(@Json(ignored = true) val linkedTrack:
824
846
825
847
/* *
826
848
* @property addedAt The date and time the track was saved.
827
- * @property track Information about the track.
849
+ * @property track The track object .
828
850
*/
829
851
data class SavedTrack (
830
852
@Json(name = " added_at" ) val addedAt : String ,
831
853
val track : Track
832
854
)
833
855
856
+ /* *
857
+ * @param id The device ID. This may be null.
858
+ * @param isActive If this device is the currently active device.
859
+ * @param isPrivateSession If this device is currently in a private session.
860
+ * @param isRestricted Whether controlling this device is restricted. At present
861
+ * if this is “true” then no Web API commands will be accepted by this device.
862
+ * @param name The name of the device.
863
+ * @param type Device type, such as “Computer”, “Smartphone” or “Speaker”.
864
+ */
834
865
data class Device (
835
- val id : String ,
866
+ val id : String? ,
836
867
@Json(name = " is_active" ) val isActive : Boolean ,
868
+ @Json(name = " is_private_session" ) val isPrivateSession : Boolean ,
837
869
@Json(name = " is_restricted" ) val isRestricted : Boolean ,
838
870
val name : String ,
839
- val type : String ,
840
- @Json(name = " volume_percent" ) val volumePercent : Int
871
+ val _type : String ,
872
+ @Json(name = " volume_percent" ) val volumePercent : Int ,
873
+ val type : DeviceType = DeviceType .values().first { it.identifier.equals(_type , true) }
874
+
841
875
)
842
876
877
+ /* *
878
+ * Electronic type of registered Spotify device
879
+ *
880
+ * @param identifier readable name
881
+ */
882
+ enum class DeviceType (val identifier : String ) {
883
+ COMPUTER (" Computer" ),
884
+ TABLET (" Tablet" ),
885
+ SMARTPHONE (" Smartphone" ),
886
+ SPEAKER (" Speaker" ),
887
+ TV (" TV" ),
888
+ AVR (" AVR" ),
889
+ STB (" STB" ),
890
+ AUDIO_DONGLE (" AudioDongle" ),
891
+ GAME_CONSOLE (" GameConsole" ),
892
+ CAST_VIDEO (" CastVideo" ),
893
+ CAST_AUDIO (" CastAudio" ),
894
+ AUTOMOBILE (" Automobile" ),
895
+ UNKNOWN (" Unknown" )
896
+ }
897
+
843
898
data class CurrentlyPlayingContext (
844
899
val timestamp : Long? ,
845
900
val device : Device ,
@@ -851,21 +906,102 @@ data class CurrentlyPlayingContext(
851
906
val context : Context
852
907
)
853
908
909
+ /* *
910
+ * Information about the currently playing track and context
911
+ *
912
+ * @param context A Context Object. Can be null.
913
+ * @param timestamp Unix Millisecond Timestamp when data was fetched
914
+ * @param progressMs Progress into the currently playing track. Can be null.
915
+ * @param isPlaying If something is currently playing.
916
+ * @param track The currently playing track. Can be null.
917
+ * @param currentlyPlayingType The object type of the currently playing item. Can be one of track, episode, ad or unknown.
918
+ * @param actions Allows to update the user interface based on which playback actions are available within the current context
919
+ *
920
+ */
854
921
data class CurrentlyPlayingObject (
855
922
val context : PlayHistoryContext ? ,
856
923
val timestamp : Long ,
857
- @Json(name = " progress_ms" ) val progressMs : Int ,
924
+ @Json(name = " progress_ms" ) val progressMs : Int? ,
858
925
@Json(name = " is_playing" ) val isPlaying : Boolean ,
859
- val item : Track
926
+ @Json(name = " item" ) val track : Track ,
927
+ @Json(name = " currently_playing_type" ) private val _currentlyPlayingType : String ,
928
+ @Json(ignored = true ) val currentlyPlayingType : CurrentlyPlayingType = CurrentlyPlayingType .values().match(_currentlyPlayingType )!!,
929
+ val actions : PlaybackActions
860
930
)
861
931
932
+ data class PlaybackActions (
933
+ @Json(name = " disallows" ) val _disallows : Map <String , Boolean ?>,
934
+ @Json(ignored = true ) val disallows : List <DisallowablePlaybackAction > = _disallows .map {
935
+ DisallowablePlaybackAction (
936
+ PlaybackAction .values().match(it.key)!!,
937
+ it.value ? : false
938
+ )
939
+ }
940
+ )
941
+
942
+ data class DisallowablePlaybackAction (val action : PlaybackAction , val disallowed : Boolean )
943
+
944
+ /* *
945
+ * Action a user takes that will affect current playback
946
+ */
947
+ enum class PlaybackAction (private val identifier : String ) : ResultEnum {
948
+ INTERRUPTING_PLAYBACK (" interrupting_playback" ),
949
+ PAUSING (" pausing" ),
950
+ PLAYING (" playing" ),
951
+ RESUMING (" resuming" ),
952
+ SEEKING (" seeking" ),
953
+ SKIPPING_NEXT (" skipping_next" ),
954
+ SKIPPING_PREV (" skipping_prev" ),
955
+ STOPPING (" stopping" ),
956
+ TOGGLING_REPEAT_CONTEXT (" toggling_repeat_context" ),
957
+ TOGGLING_SHUFFLE (" toggling_shuffle" ),
958
+ TOGGLING_REPEAT_TRACK (" toggling_repeat_track" ),
959
+ TRANSFERRING_PLAYBACK (" transferring_playback" )
960
+ ;
961
+
962
+ override fun retrieveIdentifier () = identifier
963
+ }
964
+
965
+ /* *
966
+ * The object type of the currently playing item
967
+ */
968
+ enum class CurrentlyPlayingType (val identifier : String ) : ResultEnum {
969
+ TRACK (" track" ),
970
+ EPISODE (" episode" ),
971
+ AD (" ad" ),
972
+ UNKNOWN (" unknown" );
973
+
974
+ override fun retrieveIdentifier () = identifier
975
+
976
+ }
977
+
978
+ interface ResultEnum {
979
+ fun retrieveIdentifier (): Any
980
+ }
981
+
982
+ /* *
983
+ * Context in which a track was played
984
+ *
985
+ * @param type The object type, e.g. “artist”, “playlist”, “album”.
986
+ * @param href A link to the Web API endpoint providing full details of the track.
987
+ * @param externalUrls External URLs for this context.
988
+ * @param uri The Spotify URI for the context.
989
+ */
862
990
data class PlayHistoryContext (
863
991
val type : String ,
864
992
val href : String ,
865
993
@Json(name = " external_urls" ) val externalUrls : Map <String , String >,
866
- val uri : String
994
+ @Json(name = " uri" ) private val _uri : String ,
995
+ @Json(ignored = true ) val uri : TrackURI = TrackURI (_uri )
867
996
)
868
997
998
+ /* *
999
+ * Information about a previously-played track
1000
+ *
1001
+ * @param track The track the user listened to.
1002
+ * @param playedAt The date and time the track was played.
1003
+ * @param context The context the track was played from.
1004
+ */
869
1005
data class PlayHistory (
870
1006
val track : SimpleTrack ,
871
1007
@Json(name = " played_at" ) val playedAt : String ,
0 commit comments