Skip to content

Commit 9221106

Browse files
committed
add documentation for remaining player models
1 parent cdcf1e4 commit 9221106

File tree

2 files changed

+149
-8
lines changed

2 files changed

+149
-8
lines changed

src/main/kotlin/com/adamratzman/spotify/models/ResultObjects.kt

Lines changed: 143 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package com.adamratzman.spotify.models
44
import com.adamratzman.spotify.endpoints.client.ClientPlaylistAPI
55
import com.adamratzman.spotify.main.SpotifyAPI
66
import com.adamratzman.spotify.main.SpotifyRestAction
7+
import com.adamratzman.spotify.utils.match
78
import com.beust.klaxon.Json
89

910
/**
@@ -608,6 +609,16 @@ data class Playlist(
608609
data class RecommendationResponse(val seeds: List<RecommendationSeed>, val tracks: List<SimpleTrack>)
609610

610611
/**
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+
*
611622
* @param bars The time intervals of the bars throughout the track. A bar (or measure) is a segment of time defined as
612623
* a given number of beats. Bar offsets also indicate downbeats, the first beat of the measure.
613624
* @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(
631642
val track: TrackAnalysis
632643
)
633644

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+
*/
634656
data class AudioAnalysisMeta(
635657
@Json(name = "analyzer_version") val analyzerVersion: String,
636658
val platform: String,
@@ -824,22 +846,55 @@ abstract class RelinkingAvailableResponse(@Json(ignored = true) val linkedTrack:
824846

825847
/**
826848
* @property addedAt The date and time the track was saved.
827-
* @property track Information about the track.
849+
* @property track The track object.
828850
*/
829851
data class SavedTrack(
830852
@Json(name = "added_at") val addedAt: String,
831853
val track: Track
832854
)
833855

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+
*/
834865
data class Device(
835-
val id: String,
866+
val id: String?,
836867
@Json(name = "is_active") val isActive: Boolean,
868+
@Json(name = "is_private_session") val isPrivateSession: Boolean,
837869
@Json(name = "is_restricted") val isRestricted: Boolean,
838870
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+
841875
)
842876

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+
843898
data class CurrentlyPlayingContext(
844899
val timestamp: Long?,
845900
val device: Device,
@@ -851,21 +906,102 @@ data class CurrentlyPlayingContext(
851906
val context: Context
852907
)
853908

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+
*/
854921
data class CurrentlyPlayingObject(
855922
val context: PlayHistoryContext?,
856923
val timestamp: Long,
857-
@Json(name = "progress_ms") val progressMs: Int,
924+
@Json(name = "progress_ms") val progressMs: Int?,
858925
@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
860930
)
861931

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+
*/
862990
data class PlayHistoryContext(
863991
val type: String,
864992
val href: String,
865993
@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)
867996
)
868997

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+
*/
8691005
data class PlayHistory(
8701006
val track: SimpleTrack,
8711007
@Json(name = "played_at") val playedAt: String,

src/main/kotlin/com/adamratzman/spotify/utils/MiscUtils.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22
package com.adamratzman.spotify.utils
33

44
import com.adamratzman.spotify.models.BadRequestException
5+
import com.adamratzman.spotify.models.ResultEnum
56

67
internal fun <T> catch(function: () -> T): T? {
78
return try {
89
function()
910
} catch (e: BadRequestException) {
1011
null
1112
}
12-
}
13+
}
14+
15+
16+
fun <T : ResultEnum> Array<T>.match(identifier: String)
17+
= firstOrNull { it.retrieveIdentifier().toString().equals(identifier, true) }

0 commit comments

Comments
 (0)