mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-02 02:06:45 +01:00
Use new api getSongsByGenre call.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
5ea9eb7818
commit
3b91f41cbe
@ -71,6 +71,7 @@ import org.moire.ultrasonic.api.subsonic.response.GetPlaylistResponse;
|
||||
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.JukeboxResponse;
|
||||
@ -113,7 +114,6 @@ import org.moire.ultrasonic.service.parser.BookmarkParser;
|
||||
import org.moire.ultrasonic.service.parser.ChatMessageParser;
|
||||
import org.moire.ultrasonic.service.parser.ErrorParser;
|
||||
import org.moire.ultrasonic.service.parser.MusicDirectoryParser;
|
||||
import org.moire.ultrasonic.service.parser.RandomSongsParser;
|
||||
import org.moire.ultrasonic.service.parser.SubsonicRESTException;
|
||||
import org.moire.ultrasonic.service.parser.UserInfoParser;
|
||||
import org.moire.ultrasonic.service.ssl.SSLSocketFactory;
|
||||
@ -1208,33 +1208,24 @@ public class RESTMusicService implements MusicService
|
||||
}
|
||||
|
||||
@Override
|
||||
public MusicDirectory getSongsByGenre(String genre, int count, int offset, Context context, ProgressListener progressListener) throws Exception
|
||||
{
|
||||
checkServerVersion(context, "1.9", "Genres not supported.");
|
||||
|
||||
HttpParams params = new BasicHttpParams();
|
||||
HttpConnectionParams.setSoTimeout(params, SOCKET_READ_TIMEOUT_GET_RANDOM_SONGS);
|
||||
|
||||
List<String> parameterNames = new ArrayList<String>();
|
||||
List<Object> parameterValues = new ArrayList<Object>();
|
||||
|
||||
parameterNames.add("genre");
|
||||
parameterValues.add(genre);
|
||||
parameterNames.add("count");
|
||||
parameterValues.add(count);
|
||||
parameterNames.add("offset");
|
||||
parameterValues.add(offset);
|
||||
|
||||
Reader reader = getReader(context, progressListener, "getSongsByGenre", params, parameterNames, parameterValues);
|
||||
|
||||
try
|
||||
{
|
||||
return new RandomSongsParser(context).parse(reader, progressListener);
|
||||
}
|
||||
finally
|
||||
{
|
||||
Util.close(reader);
|
||||
public MusicDirectory getSongsByGenre(String genre,
|
||||
int count,
|
||||
int offset,
|
||||
Context context,
|
||||
ProgressListener progressListener) throws Exception {
|
||||
if (genre == null) {
|
||||
throw new IllegalArgumentException("Genre is null");
|
||||
}
|
||||
|
||||
updateProgressListener(progressListener, R.string.parser_reading);
|
||||
Response<GetSongsByGenreResponse> response = subsonicAPIClient.getApi()
|
||||
.getSongsByGenre(genre, count, offset, null)
|
||||
.execute();
|
||||
checkResponseSuccessful(response);
|
||||
|
||||
MusicDirectory result = new MusicDirectory();
|
||||
result.addAll(APIMusicDirectoryConverter.toDomainEntityList(response.body().getSongsList()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,72 +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 RandomSongsParser extends MusicDirectoryEntryParser
|
||||
{
|
||||
|
||||
public RandomSongsParser(Context context)
|
||||
{
|
||||
super(context);
|
||||
}
|
||||
|
||||
public MusicDirectory parse(Reader reader, ProgressListener progressListener) 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 ("song".equals(name))
|
||||
{
|
||||
dir.addChild(parseEntry("", false, 0));
|
||||
}
|
||||
else if ("error".equals(name))
|
||||
{
|
||||
handleError();
|
||||
}
|
||||
}
|
||||
} while (eventType != XmlPullParser.END_DOCUMENT);
|
||||
|
||||
validate();
|
||||
updateProgress(progressListener, R.string.parser_reading_done);
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user