mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-19 21:20:52 +01:00
Merge pull request #50 from ultrasonic/add-get-album-list-2
Add get album list 2
This commit is contained in:
commit
69299c40df
@ -0,0 +1,113 @@
|
|||||||
|
package org.moire.ultrasonic.api.subsonic
|
||||||
|
|
||||||
|
import org.amshove.kluent.`should equal to`
|
||||||
|
import org.amshove.kluent.`should equal`
|
||||||
|
import org.junit.Test
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Album
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.AlbumListType
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.AlbumListType.STARRED
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Integration test for [SubsonicAPIClient] for getAlbumList2() call.
|
||||||
|
*/
|
||||||
|
@Suppress("NamingConventionViolation")
|
||||||
|
class SubsonicApiGetAlbumList2Test : SubsonicAPIClientTest() {
|
||||||
|
@Test
|
||||||
|
fun `Should handle error response`() {
|
||||||
|
val response = checkErrorCallParsed(mockWebServerRule) {
|
||||||
|
client.api.getAlbumList2(STARRED).execute()
|
||||||
|
}
|
||||||
|
|
||||||
|
response.albumList `should equal` emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should handle ok response`() {
|
||||||
|
mockWebServerRule.enqueueResponse("get_album_list_2_ok.json")
|
||||||
|
|
||||||
|
val response = client.api.getAlbumList2(STARRED).execute()
|
||||||
|
|
||||||
|
assertResponseSuccessful(response)
|
||||||
|
with(response.body().albumList) {
|
||||||
|
this.size `should equal to` 2
|
||||||
|
this[0] `should equal` Album(id = 962, name = "Fury", artist = "Sick Puppies",
|
||||||
|
artistId = 473, coverArt = "al-962", songCount = 13, duration = 2591,
|
||||||
|
created = parseDate("2017-09-02T17:34:51.000Z"), year = 2016,
|
||||||
|
genre = "Alternative Rock")
|
||||||
|
this[1] `should equal` Album(id = 961, name = "Endless Forms Most Beautiful",
|
||||||
|
artist = "Nightwish", artistId = 559, coverArt = "al-961", songCount = 22,
|
||||||
|
duration = 9469, created = parseDate("2017-09-02T16:22:47.000Z"),
|
||||||
|
year = 2015, genre = "Symphonic Metal")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should pass type in request params`() {
|
||||||
|
val type = AlbumListType.SORTED_BY_NAME
|
||||||
|
|
||||||
|
mockWebServerRule.assertRequestParam(responseResourceName = "get_album_list_2_ok.json",
|
||||||
|
expectedParam = "type=${type.typeName}") {
|
||||||
|
client.api.getAlbumList2(type = type).execute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should pass size in request param`() {
|
||||||
|
val size = 45
|
||||||
|
|
||||||
|
mockWebServerRule.assertRequestParam(responseResourceName = "get_album_list_2_ok.json",
|
||||||
|
expectedParam = "size=$size") {
|
||||||
|
client.api.getAlbumList2(STARRED, size = size).execute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should pass offset in request param`() {
|
||||||
|
val offset = 33
|
||||||
|
|
||||||
|
mockWebServerRule.assertRequestParam(responseResourceName = "get_album_list_2_ok.json",
|
||||||
|
expectedParam = "offset=$offset") {
|
||||||
|
client.api.getAlbumList2(STARRED, offset = offset).execute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should pass from year in request params`() {
|
||||||
|
val fromYear = 3030
|
||||||
|
|
||||||
|
mockWebServerRule.assertRequestParam(responseResourceName = "get_album_list_2_ok.json",
|
||||||
|
expectedParam = "fromYear=$fromYear") {
|
||||||
|
client.api.getAlbumList2(STARRED, fromYear = fromYear).execute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should pass toYear in request param`() {
|
||||||
|
val toYear = 2014
|
||||||
|
|
||||||
|
mockWebServerRule.assertRequestParam(responseResourceName = "get_album_list_2_ok.json",
|
||||||
|
expectedParam = "toYear=$toYear") {
|
||||||
|
client.api.getAlbumList2(STARRED, toYear = toYear).execute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should pass genre in request param`() {
|
||||||
|
val genre = "MathRock"
|
||||||
|
|
||||||
|
mockWebServerRule.assertRequestParam(responseResourceName = "get_album_list_2_ok.json",
|
||||||
|
expectedParam = "genre=$genre") {
|
||||||
|
client.api.getAlbumList2(STARRED, genre = genre).execute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should pass music folder id in request param`() {
|
||||||
|
val musicFolderId = 9422L
|
||||||
|
|
||||||
|
mockWebServerRule.assertRequestParam(responseResourceName = "get_album_list_2_ok.json",
|
||||||
|
expectedParam = "musicFolderId=$musicFolderId") {
|
||||||
|
client.api.getAlbumList2(STARRED, musicFolderId = musicFolderId).execute()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"subsonic-response" : {
|
||||||
|
"status" : "ok",
|
||||||
|
"version" : "1.15.0",
|
||||||
|
"albumList2" : {
|
||||||
|
"album" : [ {
|
||||||
|
"id" : "962",
|
||||||
|
"name" : "Fury",
|
||||||
|
"artist" : "Sick Puppies",
|
||||||
|
"artistId" : "473",
|
||||||
|
"coverArt" : "al-962",
|
||||||
|
"songCount" : 13,
|
||||||
|
"duration" : 2591,
|
||||||
|
"created" : "2017-09-02T17:34:51.000Z",
|
||||||
|
"year" : 2016,
|
||||||
|
"genre" : "Alternative Rock"
|
||||||
|
}, {
|
||||||
|
"id" : "961",
|
||||||
|
"name" : "Endless Forms Most Beautiful",
|
||||||
|
"artist" : "Nightwish",
|
||||||
|
"artistId" : "559",
|
||||||
|
"coverArt" : "al-961",
|
||||||
|
"songCount" : 22,
|
||||||
|
"duration" : 9469,
|
||||||
|
"created" : "2017-09-02T16:22:47.000Z",
|
||||||
|
"year" : 2015,
|
||||||
|
"genre" : "Symphonic Metal"
|
||||||
|
} ]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package org.moire.ultrasonic.api.subsonic
|
package org.moire.ultrasonic.api.subsonic
|
||||||
|
|
||||||
import org.moire.ultrasonic.api.subsonic.models.AlbumListType
|
import org.moire.ultrasonic.api.subsonic.models.AlbumListType
|
||||||
|
import org.moire.ultrasonic.api.subsonic.response.GetAlbumList2Response
|
||||||
import org.moire.ultrasonic.api.subsonic.response.GetAlbumListResponse
|
import org.moire.ultrasonic.api.subsonic.response.GetAlbumListResponse
|
||||||
import org.moire.ultrasonic.api.subsonic.response.GetAlbumResponse
|
import org.moire.ultrasonic.api.subsonic.response.GetAlbumResponse
|
||||||
import org.moire.ultrasonic.api.subsonic.response.GetArtistResponse
|
import org.moire.ultrasonic.api.subsonic.response.GetArtistResponse
|
||||||
@ -134,4 +135,13 @@ interface SubsonicAPIDefinition {
|
|||||||
@Query("toYear") toYear: Int? = null,
|
@Query("toYear") toYear: Int? = null,
|
||||||
@Query("genre") genre: String? = null,
|
@Query("genre") genre: String? = null,
|
||||||
@Query("musicFolderId") musicFolderId: Long? = null): Call<GetAlbumListResponse>
|
@Query("musicFolderId") musicFolderId: Long? = null): Call<GetAlbumListResponse>
|
||||||
|
|
||||||
|
@GET("getAlbumList2.view")
|
||||||
|
fun getAlbumList2(@Query("type") type: AlbumListType,
|
||||||
|
@Query("size") size: Int? = null,
|
||||||
|
@Query("offset") offset: Int? = null,
|
||||||
|
@Query("fromYear") fromYear: Int? = null,
|
||||||
|
@Query("toYear") toYear: Int? = null,
|
||||||
|
@Query("genre") genre: String? = null,
|
||||||
|
@Query("musicFolderId") musicFolderId: Long? = null): Call<GetAlbumList2Response>
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
package org.moire.ultrasonic.api.subsonic.response
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty
|
||||||
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIVersions
|
||||||
|
import org.moire.ultrasonic.api.subsonic.SubsonicError
|
||||||
|
import org.moire.ultrasonic.api.subsonic.models.Album
|
||||||
|
|
||||||
|
@Suppress("NamingConventionViolation")
|
||||||
|
class GetAlbumList2Response(status: Status,
|
||||||
|
version: SubsonicAPIVersions,
|
||||||
|
error: SubsonicError?)
|
||||||
|
: SubsonicResponse(status, version, error) {
|
||||||
|
@JsonProperty("albumList2") private val albumWrapper2 = AlbumWrapper2()
|
||||||
|
|
||||||
|
val albumList: List<Album>
|
||||||
|
get() = albumWrapper2.albumList
|
||||||
|
}
|
||||||
|
|
||||||
|
@Suppress("NamingConventionViolation")
|
||||||
|
private class AlbumWrapper2(
|
||||||
|
@JsonProperty("album") val albumList: List<Album> = emptyList())
|
@ -58,6 +58,7 @@ import org.moire.ultrasonic.R;
|
|||||||
import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient;
|
import org.moire.ultrasonic.api.subsonic.SubsonicAPIClient;
|
||||||
import org.moire.ultrasonic.api.subsonic.models.AlbumListType;
|
import org.moire.ultrasonic.api.subsonic.models.AlbumListType;
|
||||||
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild;
|
import org.moire.ultrasonic.api.subsonic.models.MusicDirectoryChild;
|
||||||
|
import org.moire.ultrasonic.api.subsonic.response.GetAlbumList2Response;
|
||||||
import org.moire.ultrasonic.api.subsonic.response.GetAlbumListResponse;
|
import org.moire.ultrasonic.api.subsonic.response.GetAlbumListResponse;
|
||||||
import org.moire.ultrasonic.api.subsonic.response.GetAlbumResponse;
|
import org.moire.ultrasonic.api.subsonic.response.GetAlbumResponse;
|
||||||
import org.moire.ultrasonic.api.subsonic.response.GetArtistResponse;
|
import org.moire.ultrasonic.api.subsonic.response.GetArtistResponse;
|
||||||
@ -98,7 +99,6 @@ import org.moire.ultrasonic.domain.SearchResult;
|
|||||||
import org.moire.ultrasonic.domain.Share;
|
import org.moire.ultrasonic.domain.Share;
|
||||||
import org.moire.ultrasonic.domain.UserInfo;
|
import org.moire.ultrasonic.domain.UserInfo;
|
||||||
import org.moire.ultrasonic.domain.Version;
|
import org.moire.ultrasonic.domain.Version;
|
||||||
import org.moire.ultrasonic.service.parser.AlbumListParser;
|
|
||||||
import org.moire.ultrasonic.service.parser.BookmarkParser;
|
import org.moire.ultrasonic.service.parser.BookmarkParser;
|
||||||
import org.moire.ultrasonic.service.parser.ChatMessageParser;
|
import org.moire.ultrasonic.service.parser.ChatMessageParser;
|
||||||
import org.moire.ultrasonic.service.parser.ErrorParser;
|
import org.moire.ultrasonic.service.parser.ErrorParser;
|
||||||
@ -678,21 +678,26 @@ public class RESTMusicService implements MusicService
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MusicDirectory getAlbumList2(String type, int size, int offset, Context context, ProgressListener progressListener) throws Exception
|
public MusicDirectory getAlbumList2(String type,
|
||||||
{
|
int size,
|
||||||
checkServerVersion(context, "1.8", "Album list by ID3 tag not supported.");
|
int offset,
|
||||||
|
Context context,
|
||||||
|
ProgressListener progressListener) throws Exception {
|
||||||
|
if (type == null) {
|
||||||
|
throw new IllegalArgumentException("Type is null!");
|
||||||
|
}
|
||||||
|
|
||||||
Reader reader = getReader(context, progressListener, "getAlbumList2", null, asList("type", "size", "offset"), Arrays.<Object>asList(type, size, offset));
|
updateProgressListener(progressListener, R.string.parser_reading);
|
||||||
try
|
Response<GetAlbumList2Response> response = subsonicAPIClient.getApi()
|
||||||
{
|
.getAlbumList2(AlbumListType.fromName(type), size, offset, null, null,
|
||||||
return new AlbumListParser(context).parse(reader, progressListener, true);
|
null, null).execute();
|
||||||
}
|
checkResponseSuccessful(response);
|
||||||
finally
|
|
||||||
{
|
MusicDirectory result = new MusicDirectory();
|
||||||
Util.close(reader);
|
result.addAll(APIAlbumConverter.toDomainEntityList(response.body().getAlbumList()));
|
||||||
}
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MusicDirectory getRandomSongs(int size, Context context, ProgressListener progressListener) throws Exception
|
public MusicDirectory getRandomSongs(int size, Context context, ProgressListener progressListener) throws Exception
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
/*
|
|
||||||
This file is part of Subsonic.
|
|
||||||
|
|
||||||
Subsonic is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
Subsonic is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Copyright 2009 (C) Sindre Mehus
|
|
||||||
*/
|
|
||||||
package org.moire.ultrasonic.service.parser;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import org.moire.ultrasonic.R;
|
|
||||||
import org.moire.ultrasonic.domain.MusicDirectory;
|
|
||||||
import org.moire.ultrasonic.util.ProgressListener;
|
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParser;
|
|
||||||
|
|
||||||
import java.io.Reader;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Sindre Mehus
|
|
||||||
*/
|
|
||||||
public class AlbumListParser extends MusicDirectoryEntryParser
|
|
||||||
{
|
|
||||||
public AlbumListParser(Context context)
|
|
||||||
{
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public MusicDirectory parse(Reader reader, ProgressListener progressListener, boolean useId3) throws Exception
|
|
||||||
{
|
|
||||||
|
|
||||||
updateProgress(progressListener, R.string.parser_reading);
|
|
||||||
init(reader);
|
|
||||||
|
|
||||||
MusicDirectory dir = new MusicDirectory();
|
|
||||||
int eventType;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
eventType = nextParseEvent();
|
|
||||||
if (eventType == XmlPullParser.START_TAG)
|
|
||||||
{
|
|
||||||
String name = getElementName();
|
|
||||||
if ("album".equals(name))
|
|
||||||
{
|
|
||||||
dir.addChild(parseEntry("", useId3, 0));
|
|
||||||
}
|
|
||||||
else if ("error".equals(name))
|
|
||||||
{
|
|
||||||
handleError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} while (eventType != XmlPullParser.END_DOCUMENT);
|
|
||||||
|
|
||||||
validate();
|
|
||||||
updateProgress(progressListener, R.string.parser_reading_done);
|
|
||||||
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
}
|
|
@ -23,3 +23,5 @@ fun Album.toDomainEntity(): MusicDirectory.Entry = MusicDirectory.Entry().apply
|
|||||||
fun Album.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory().apply {
|
fun Album.toMusicDirectoryDomainEntity(): MusicDirectory = MusicDirectory().apply {
|
||||||
addAll(this@toMusicDirectoryDomainEntity.songList.map { it.toDomainEntity() })
|
addAll(this@toMusicDirectoryDomainEntity.songList.map { it.toDomainEntity() })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun List<Album>.toDomainEntityList(): List<MusicDirectory.Entry> = this.map { it.toDomainEntity() }
|
||||||
|
@ -51,4 +51,18 @@ class APIAlbumConverterTest {
|
|||||||
children[0] `should equal` entity.songList[0].toDomainEntity()
|
children[0] `should equal` entity.songList[0].toDomainEntity()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `Should convert list of Album entities to domain list entities`() {
|
||||||
|
val entityList = listOf(Album(id = 455), Album(id = 1), Album(id = 1000))
|
||||||
|
|
||||||
|
val convertedList = entityList.toDomainEntityList()
|
||||||
|
|
||||||
|
with(convertedList) {
|
||||||
|
size `should equal to` entityList.size
|
||||||
|
forEachIndexed { index, entry ->
|
||||||
|
entry `should equal` entityList[index].toDomainEntity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user