2017-12-10 10:43:45 +01:00
|
|
|
package org.moire.ultrasonic.api.subsonic
|
|
|
|
|
|
|
|
import okhttp3.ResponseBody
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_11_0
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_12_0
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_14_0
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_2_0
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_3_0
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_4_0
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_5_0
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_6_0
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_7_0
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_8_0
|
|
|
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions.V1_9_0
|
|
|
|
import org.moire.ultrasonic.api.subsonic.models.AlbumListType
|
|
|
|
import org.moire.ultrasonic.api.subsonic.models.JukeboxAction
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.BookmarksResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.ChatMessagesResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.GenresResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.GetAlbumList2Response
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.GetAlbumListResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.GetAlbumResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.GetArtistResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.GetArtistsResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.GetLyricsResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.GetPlaylistsResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.GetPodcastsResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.GetRandomSongsResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.GetSongsByGenreResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.GetStarredResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.GetStarredTwoResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.GetUserResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.JukeboxResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.SearchThreeResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.SearchTwoResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.SharesResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.SubsonicResponse
|
|
|
|
import org.moire.ultrasonic.api.subsonic.response.VideosResponse
|
|
|
|
import retrofit2.Call
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Special wrapper for [SubsonicAPIDefinition] that checks if [currentApiVersion] is suitable
|
|
|
|
* for this call.
|
|
|
|
*/
|
|
|
|
internal class ApiVersionCheckWrapper(
|
2018-03-24 19:47:55 +01:00
|
|
|
val api: SubsonicAPIDefinition,
|
|
|
|
var currentApiVersion: SubsonicAPIVersions
|
|
|
|
) : SubsonicAPIDefinition by api {
|
2017-12-16 22:14:01 +01:00
|
|
|
override fun getArtists(musicFolderId: String?): Call<GetArtistsResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_8_0)
|
|
|
|
return api.getArtists(musicFolderId)
|
|
|
|
}
|
|
|
|
|
2017-12-16 22:14:01 +01:00
|
|
|
override fun star(id: String?, albumId: String?, artistId: String?): Call<SubsonicResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_8_0)
|
|
|
|
return api.star(id, albumId, artistId)
|
|
|
|
}
|
|
|
|
|
2017-12-16 22:14:01 +01:00
|
|
|
override fun unstar(id: String?, albumId: String?, artistId: String?): Call<SubsonicResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_8_0)
|
|
|
|
return api.unstar(id, albumId, artistId)
|
|
|
|
}
|
|
|
|
|
2017-12-16 22:14:01 +01:00
|
|
|
override fun getArtist(id: String): Call<GetArtistResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_8_0)
|
|
|
|
return api.getArtist(id)
|
|
|
|
}
|
|
|
|
|
2017-12-16 22:14:01 +01:00
|
|
|
override fun getAlbum(id: String): Call<GetAlbumResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_8_0)
|
|
|
|
return api.getAlbum(id)
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:47:55 +01:00
|
|
|
override fun search2(
|
|
|
|
query: String,
|
|
|
|
artistCount: Int?,
|
|
|
|
artistOffset: Int?,
|
|
|
|
albumCount: Int?,
|
|
|
|
albumOffset: Int?,
|
|
|
|
songCount: Int?,
|
|
|
|
musicFolderId: String?
|
|
|
|
): Call<SearchTwoResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_4_0)
|
|
|
|
checkParamVersion(musicFolderId, V1_12_0)
|
|
|
|
return api.search2(query, artistCount, artistOffset, albumCount, albumOffset, songCount,
|
|
|
|
musicFolderId)
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:47:55 +01:00
|
|
|
override fun search3(
|
|
|
|
query: String,
|
|
|
|
artistCount: Int?,
|
|
|
|
artistOffset: Int?,
|
|
|
|
albumCount: Int?,
|
|
|
|
albumOffset: Int?,
|
|
|
|
songCount: Int?,
|
|
|
|
musicFolderId: String?
|
|
|
|
): Call<SearchThreeResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_8_0)
|
|
|
|
checkParamVersion(musicFolderId, V1_12_0)
|
|
|
|
return api.search3(query, artistCount, artistOffset, albumCount, albumOffset,
|
|
|
|
songCount, musicFolderId)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getPlaylists(username: String?): Call<GetPlaylistsResponse> {
|
|
|
|
checkParamVersion(username, V1_8_0)
|
|
|
|
return api.getPlaylists(username)
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:47:55 +01:00
|
|
|
override fun createPlaylist(
|
|
|
|
id: String?,
|
|
|
|
name: String?,
|
|
|
|
songIds: List<String>?
|
|
|
|
): Call<SubsonicResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_2_0)
|
|
|
|
return api.createPlaylist(id, name, songIds)
|
|
|
|
}
|
|
|
|
|
2017-12-16 22:14:01 +01:00
|
|
|
override fun deletePlaylist(id: String): Call<SubsonicResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_2_0)
|
|
|
|
return api.deletePlaylist(id)
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:47:55 +01:00
|
|
|
override fun updatePlaylist(
|
|
|
|
id: String,
|
|
|
|
name: String?,
|
|
|
|
comment: String?,
|
|
|
|
public: Boolean?,
|
|
|
|
songIdsToAdd: List<String>?,
|
|
|
|
songIndexesToRemove: List<Int>?
|
|
|
|
): Call<SubsonicResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_8_0)
|
|
|
|
return api.updatePlaylist(id, name, comment, public, songIdsToAdd, songIndexesToRemove)
|
|
|
|
}
|
|
|
|
|
2017-12-16 22:14:01 +01:00
|
|
|
override fun getPodcasts(includeEpisodes: Boolean?, id: String?): Call<GetPodcastsResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_6_0)
|
|
|
|
checkParamVersion(includeEpisodes, V1_9_0)
|
|
|
|
checkParamVersion(id, V1_9_0)
|
|
|
|
return api.getPodcasts(includeEpisodes, id)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getLyrics(artist: String?, title: String?): Call<GetLyricsResponse> {
|
|
|
|
checkVersion(V1_2_0)
|
|
|
|
return api.getLyrics(artist, title)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun scrobble(id: String, time: Long?, submission: Boolean?): Call<SubsonicResponse> {
|
|
|
|
checkVersion(V1_5_0)
|
|
|
|
checkParamVersion(time, V1_8_0)
|
|
|
|
return api.scrobble(id, time, submission)
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:47:55 +01:00
|
|
|
override fun getAlbumList(
|
|
|
|
type: AlbumListType,
|
|
|
|
size: Int?,
|
|
|
|
offset: Int?,
|
|
|
|
fromYear: Int?,
|
|
|
|
toYear: Int?,
|
|
|
|
genre: String?,
|
|
|
|
musicFolderId: String?
|
|
|
|
): Call<GetAlbumListResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_2_0)
|
|
|
|
checkParamVersion(musicFolderId, V1_11_0)
|
|
|
|
return api.getAlbumList(type, size, offset, fromYear, toYear, genre, musicFolderId)
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:47:55 +01:00
|
|
|
override fun getAlbumList2(
|
|
|
|
type: AlbumListType,
|
|
|
|
size: Int?,
|
|
|
|
offset: Int?,
|
|
|
|
fromYear: Int?,
|
|
|
|
toYear: Int?,
|
|
|
|
genre: String?,
|
|
|
|
musicFolderId: String?
|
|
|
|
): Call<GetAlbumList2Response> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_8_0)
|
|
|
|
checkParamVersion(musicFolderId, V1_12_0)
|
|
|
|
return api.getAlbumList2(type, size, offset, fromYear, toYear, genre, musicFolderId)
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:47:55 +01:00
|
|
|
override fun getRandomSongs(
|
|
|
|
size: Int?,
|
|
|
|
genre: String?,
|
|
|
|
fromYear: Int?,
|
|
|
|
toYear: Int?,
|
|
|
|
musicFolderId: String?
|
|
|
|
): Call<GetRandomSongsResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_2_0)
|
|
|
|
return api.getRandomSongs(size, genre, fromYear, toYear, musicFolderId)
|
|
|
|
}
|
|
|
|
|
2017-12-16 22:14:01 +01:00
|
|
|
override fun getStarred(musicFolderId: String?): Call<GetStarredResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_8_0)
|
|
|
|
checkParamVersion(musicFolderId, V1_12_0)
|
|
|
|
return api.getStarred(musicFolderId)
|
|
|
|
}
|
|
|
|
|
2017-12-16 22:14:01 +01:00
|
|
|
override fun getStarred2(musicFolderId: String?): Call<GetStarredTwoResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_8_0)
|
|
|
|
checkParamVersion(musicFolderId, V1_12_0)
|
|
|
|
return api.getStarred2(musicFolderId)
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:47:55 +01:00
|
|
|
override fun stream(
|
|
|
|
id: String,
|
|
|
|
maxBitRate: Int?,
|
|
|
|
format: String?,
|
|
|
|
timeOffset: Int?,
|
|
|
|
videoSize: String?,
|
|
|
|
estimateContentLength: Boolean?,
|
|
|
|
converted: Boolean?,
|
|
|
|
offset: Long?
|
|
|
|
): Call<ResponseBody> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkParamVersion(maxBitRate, V1_2_0)
|
|
|
|
checkParamVersion(format, V1_6_0)
|
|
|
|
checkParamVersion(videoSize, V1_6_0)
|
|
|
|
checkParamVersion(estimateContentLength, V1_8_0)
|
|
|
|
checkParamVersion(converted, V1_14_0)
|
|
|
|
return api.stream(id, maxBitRate, format, timeOffset, videoSize,
|
|
|
|
estimateContentLength, converted)
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:47:55 +01:00
|
|
|
override fun jukeboxControl(
|
|
|
|
action: JukeboxAction,
|
|
|
|
index: Int?,
|
|
|
|
offset: Int?,
|
|
|
|
ids: List<String>?,
|
|
|
|
gain: Float?
|
|
|
|
): Call<JukeboxResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_2_0)
|
|
|
|
checkParamVersion(offset, V1_7_0)
|
|
|
|
return api.jukeboxControl(action, index, offset, ids, gain)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getShares(): Call<SharesResponse> {
|
|
|
|
checkVersion(V1_6_0)
|
|
|
|
return api.getShares()
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:47:55 +01:00
|
|
|
override fun createShare(
|
|
|
|
idsToShare: List<String>,
|
|
|
|
description: String?,
|
|
|
|
expires: Long?
|
|
|
|
): Call<SharesResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_6_0)
|
|
|
|
return api.createShare(idsToShare, description, expires)
|
|
|
|
}
|
|
|
|
|
2017-12-16 22:14:01 +01:00
|
|
|
override fun deleteShare(id: String): Call<SubsonicResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_6_0)
|
|
|
|
return api.deleteShare(id)
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:47:55 +01:00
|
|
|
override fun updateShare(
|
|
|
|
id: String,
|
|
|
|
description: String?,
|
|
|
|
expires: Long?
|
|
|
|
): Call<SubsonicResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_6_0)
|
|
|
|
return api.updateShare(id, description, expires)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getGenres(): Call<GenresResponse> {
|
|
|
|
checkVersion(V1_9_0)
|
|
|
|
return api.getGenres()
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:47:55 +01:00
|
|
|
override fun getSongsByGenre(
|
|
|
|
genre: String,
|
|
|
|
count: Int,
|
|
|
|
offset: Int,
|
|
|
|
musicFolderId: String?
|
|
|
|
): Call<GetSongsByGenreResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_9_0)
|
|
|
|
checkParamVersion(musicFolderId, V1_12_0)
|
|
|
|
return api.getSongsByGenre(genre, count, offset, musicFolderId)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getUser(username: String): Call<GetUserResponse> {
|
|
|
|
checkVersion(V1_3_0)
|
|
|
|
return api.getUser(username)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getChatMessages(since: Long?): Call<ChatMessagesResponse> {
|
|
|
|
checkVersion(V1_2_0)
|
|
|
|
return api.getChatMessages(since)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun addChatMessage(message: String): Call<SubsonicResponse> {
|
|
|
|
checkVersion(V1_2_0)
|
|
|
|
return api.addChatMessage(message)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getBookmarks(): Call<BookmarksResponse> {
|
|
|
|
checkVersion(V1_9_0)
|
|
|
|
return api.getBookmarks()
|
|
|
|
}
|
|
|
|
|
2018-03-24 19:47:55 +01:00
|
|
|
override fun createBookmark(
|
|
|
|
id: String,
|
|
|
|
position: Long,
|
|
|
|
comment: String?
|
|
|
|
): Call<SubsonicResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_9_0)
|
|
|
|
return api.createBookmark(id, position, comment)
|
|
|
|
}
|
|
|
|
|
2017-12-16 22:14:01 +01:00
|
|
|
override fun deleteBookmark(id: String): Call<SubsonicResponse> {
|
2017-12-10 10:43:45 +01:00
|
|
|
checkVersion(V1_9_0)
|
|
|
|
return api.deleteBookmark(id)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getVideos(): Call<VideosResponse> {
|
|
|
|
checkVersion(V1_8_0)
|
|
|
|
return api.getVideos()
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun getAvatar(username: String): Call<ResponseBody> {
|
|
|
|
checkVersion(V1_8_0)
|
|
|
|
return api.getAvatar(username)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun checkVersion(expectedVersion: SubsonicAPIVersions) {
|
|
|
|
if (currentApiVersion < expectedVersion) throw ApiNotSupportedException(currentApiVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun checkParamVersion(param: Any?, expectedVersion: SubsonicAPIVersions) {
|
|
|
|
if (param != null) {
|
|
|
|
checkVersion(expectedVersion)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|