Skip to content

Commit

Permalink
Add tracks API
Browse files Browse the repository at this point in the history
  • Loading branch information
warriorzz committed May 7, 2024
1 parent 4d2a60a commit ca14469
Show file tree
Hide file tree
Showing 16 changed files with 581 additions and 103 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
}

group = "ee.bjarn"
version = "0.1"
version = "0.1.1"

repositories {
mavenCentral()
Expand Down
11 changes: 0 additions & 11 deletions src/main/kotlin/ee/bjarn/ktify/model/Episode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,6 @@ data class Episode(
val uri: String,
) : KtifyObject()

@Serializable
data class EpisodePagingObject(
val href: String,
val items: List<Episode>,
val limit: Int,
val next: String? = null,
val offset: Int,
val previous: String? = null,
val total: Int,
)

@Serializable
data class SavedEpisodeObject(
@SerialName("added_at")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/ee/bjarn/ktify/model/KtifyObject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ data class RawKtifyObject(
) : KtifyObject()

object KtifyObjectSerializer : JsonContentPolymorphicSerializer<KtifyObject>(KtifyObject::class) {
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<out KtifyObject> {
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<KtifyObject> {
return when (element.jsonObject["item"]?.jsonObject?.get("type")?.jsonPrimitive?.content) {
"track" -> Track.serializer()
"album" -> Album.serializer()
Expand Down
14 changes: 14 additions & 0 deletions src/main/kotlin/ee/bjarn/ktify/model/PaginationObject.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ee.bjarn.ktify.model

import kotlinx.serialization.Serializable

@Serializable
data class PaginationObject<T>(
val href: String,
val limit: Int,
val offset: Int,
val total: Int,
val items: List<T>,
val previous: String? = null,
val next: String? = null,
)
2 changes: 1 addition & 1 deletion src/main/kotlin/ee/bjarn/ktify/model/Playlist.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ sealed class PlaylistTrackObject {
}

object PlaylistTrackObjectSerializer : JsonContentPolymorphicSerializer<PlaylistTrackObject>(PlaylistTrackObject::class) {
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<out PlaylistTrackObject> {
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<PlaylistTrackObject> {
return if (element.jsonObject["track"] != null) PlaylistTrack.serializer() else PlaylistTrackRef.serializer()
}
}
70 changes: 3 additions & 67 deletions src/main/kotlin/ee/bjarn/ktify/model/Track.kt
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package ee.bjarn.ktify.model

import ee.bjarn.ktify.model.external.ExternalId
import ee.bjarn.ktify.model.external.ExternalUrl
import ee.bjarn.ktify.model.track.LinkedTrack
import ee.bjarn.ktify.model.track.TrackRestriction
import ee.bjarn.ktify.model.util.ObjectType
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down Expand Up @@ -42,70 +44,4 @@ data class Track(
val trackNumber: Int,
override val type: ObjectType = ObjectType.TRACK,
val uri: String,
) : KtifyObject()

@Serializable
data class LinkedTrack(
@SerialName("external_urls")
val externalUrls: ExternalUrl,
val href: String,
val id: String,
val type: ObjectType = ObjectType.TRACK,
val uri: String,
)

@Serializable
data class TuneableTrack(
val acousticness: Float,
val danceability: Float,
@SerialName("duration_ms")
val durationMs: Int,
val energy: Float,
val instrumentalness: Float,
val key: Int,
val liveness: Float,
val loudness: Float,
val mode: Int,
val popularity: Float,
val speechiness: Float,
val tempo: Float,
@SerialName("time_signature")
val timeSignature: Int,
val valence: Float
)

@Serializable
data class SavedTrack(
@SerialName("added_at")
val addedAt: String,
val track: Track,
)

@Serializable
data class TrackPagingObject(
val href: String,
val items: List<Track>,
val limit: Int,
val next: String? = null,
val offset: Int,
val previous: String? = null,
val total: Int,
)

@Serializable
data class TrackActions(
@SerialName("is_playing")
val isPlaying: Boolean? = null,
val disallows: TrackActionsDisallows
)

@Serializable
data class TrackActionsDisallows(
val pausing: Boolean? = null,
val resuming: Boolean? = null
)

@Serializable
data class TrackRestriction(
val reason: RestrictionType
)
) : KtifyObject()
11 changes: 0 additions & 11 deletions src/main/kotlin/ee/bjarn/ktify/model/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@ data class PublicUser(
val uri: String
) : KtifyObject()

@Serializable
data class UserPagingObject(
val href: String,
val items: List<PublicUser>,
val limit: Int,
val next: String? = null,
val offset: Int,
val previous: String? = null,
val total: Int,
)

@Serializable
data class ExplicitContentSettings(
@SerialName("filter_enabled")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ee.bjarn.ktify.model.player

import ee.bjarn.ktify.model.Episode
import ee.bjarn.ktify.model.Track
import ee.bjarn.ktify.model.TrackActions
import ee.bjarn.ktify.model.track.TrackActions
import ee.bjarn.ktify.model.util.Context
import kotlinx.serialization.*
import kotlinx.serialization.descriptors.PrimitiveKind
Expand Down Expand Up @@ -94,7 +94,7 @@ class CurrentPlaybackNull(
) : CurrentPlayback()

object CurrentPlaybackSerializer : JsonContentPolymorphicSerializer<CurrentPlayback>(CurrentPlayback::class) {
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<out CurrentPlayback> {
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<CurrentPlayback> {
return when (element.jsonObject["item"]?.jsonObject?.get("type")?.jsonPrimitive?.content) {
"track" -> CurrentPlayingTrack.serializer()
"episode" -> CurrentPlayingEpisode.serializer()
Expand Down
13 changes: 7 additions & 6 deletions src/main/kotlin/ee/bjarn/ktify/model/search/SearchResult.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package ee.bjarn.ktify.model.search

import ee.bjarn.ktify.model.*
import ee.bjarn.ktify.model.Track
import kotlinx.serialization.Serializable

@Serializable
data class SearchResult(
val tracks: TrackPagingObject? = null,
val episodes: EpisodePagingObject? = null,
val albums: AlbumPagingObject? = null,
val artists: ArtistPagingObject? = null,
val shows: ShowPagingObject? = null,
val users: UserPagingObject? = null,
val tracks: PaginationObject<Track>? = null,
val episodes: PaginationObject<Episode>? = null,
val albums: PaginationObject<Album>? = null,
val artists: PaginationObject<Artist>? = null,
val shows: PaginationObject<Show>? = null,
val users: PaginationObject<PublicUser>? = null,
)
163 changes: 163 additions & 0 deletions src/main/kotlin/ee/bjarn/ktify/model/track/Audio.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
package ee.bjarn.ktify.model.track

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class AudioFeatures(
val acousticness: Float,
@SerialName("analysis_url")
val analysisUrl: String,
val danceability: Float,
@SerialName("duration_ms")
val durationMs: Int,
val energy: Float,
val id: String,
val instrumentalness: Float,
val key: Int,
val liveness: Float,
val loudness: Float,
val mode: Int,
val speechiness: Float,
val tempo: Float,
@SerialName("time_signature")
val timeSignature: Int,
@SerialName("track_href")
val trackHref: String,
val type: String,
val url: String,
val valence: Float
)

@Serializable
data class AudioAnalysis(
val meta: AudioAnalysisMeta,
val track: AudioAnalysisTrack,
val bars: List<AudioAnalysisBar>,
val beats: List<AudioAnalysisBeat>,
val sections: List<AudioAnalysisSection>,
val segments: List<AudioAnalysisSegment>,
val tatums: List<AudioAnalysisTatum>,
)

@Serializable
data class AudioAnalysisMeta(
@SerialName("analyzer_version")
val analyzerVersion: String,
val platform: String,
@SerialName("detailed_status")
val detailedStatus: String,
@SerialName("status_code")
val statusCode: Int,
val timestamp: Int,
@SerialName("analysis_time")
val analysisTime: Double,
@SerialName("input_process")
val inputProcess: String,
)

@Serializable
data class AudioAnalysisTrack(
@SerialName("num_samples")
val numSamples: Int,
val duration: Double,
@SerialName("sample_md5")
val sampleMd5: String = "",
@SerialName("offset_seconds")
val offsetSeconds: Int,
@SerialName("window_seconds")
val windowSeconds: Int,
@SerialName("analysis_sample_rate")
val analysisSampleRate: Int,
@SerialName("analysis_channel")
val analysisChannel: Int,
@SerialName("end_of_fade_in")
val endOfFaseIn: Int,
@SerialName("start_of_fade_out")
val startOfFadeOut: Int,
val loudness: Float,
val tempo: Float,
@SerialName("tempo_confidence")
val tempoConfidence: Double,
@SerialName("time_signature")
val timeSignature: Int,
@SerialName("time_signature_confidence")
val timeSignatureConfidence: Double,
val key: Int,
@SerialName("key_confidence")
val keyConfidence: Double,
val mode: Int,
@SerialName("mode_confidence")
val modeConfidence: Double,
val codestring: String,
@SerialName("code_version")
val codeVersion: Double,
val echoprintstring: String,
@SerialName("echoprint_version")
val echoprintVersion: Double,
val synchstring: String,
@SerialName("synch_version")
val synchVersion: Double,
val rhythmstring: String,
@SerialName("rhythm_version")
val rhythmVersion: Double,
)

@Serializable
data class AudioAnalysisBar(
val start: Double,
val duration: Double,
val confidence: Double,
)

@Serializable
data class AudioAnalysisBeat(
val start: Double,
val duration: Double,
val confidence: Double,
)

@Serializable
data class AudioAnalysisSection(
val start: Double,
val duration: Double,
val confidence: Double,
val loudness: Double,
val tempo: Double,
@SerialName("tempo_confidence")
val tempoConfidence: Double,
val key: Int,
@SerialName("key_confidence")
val keyConfidence: Double,
val mode: Double,
@SerialName("mode_confidence")
val modeConfidence: Double,
@SerialName("time_signature")
val timeSignature: Int,
@SerialName("time_signature_confidence")
val timeSignatureConfidence: Double,
)

@Serializable
data class AudioAnalysisSegment(
val start: Double,
val duration: Double,
val confidence: Double,
@SerialName("loudness_start")
val loudnessStart: Double,
@SerialName("loudness_max")
val loudnessMax: Double,
@SerialName("loudness_max_time")
val loudnessMaxTime: Double,
@SerialName("loudness_end")
val loudnessEnd: Double,
val pitches: List<Double>,
val timbre: List<Double>,
)

@Serializable
data class AudioAnalysisTatum(
val start: Double,
val duration: Double,
val confidence: Double,
)
20 changes: 20 additions & 0 deletions src/main/kotlin/ee/bjarn/ktify/model/track/Recommendation.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ee.bjarn.ktify.model.track

import ee.bjarn.ktify.model.Track
import kotlinx.serialization.Serializable

@Serializable
data class RecommendationSeed(
val afterFilteringSize: Int,
val afterRelinkingSize: Int,
val href: String,
val id: String,
val initialPoolSize: Int,
val type: String,
)

@Serializable
data class Recommendations(
val seeds: List<RecommendationSeed>,
val tracks: List<Track>,
)
Loading

0 comments on commit ca14469

Please sign in to comment.