mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-18 04:30:48 +01:00
Use new subsonic api getCoverArt call.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
48e6788224
commit
4ef8507353
@ -77,6 +77,7 @@ import org.moire.ultrasonic.api.subsonic.response.MusicFoldersResponse;
|
|||||||
import org.moire.ultrasonic.api.subsonic.response.SearchResponse;
|
import org.moire.ultrasonic.api.subsonic.response.SearchResponse;
|
||||||
import org.moire.ultrasonic.api.subsonic.response.SearchThreeResponse;
|
import org.moire.ultrasonic.api.subsonic.response.SearchThreeResponse;
|
||||||
import org.moire.ultrasonic.api.subsonic.response.SearchTwoResponse;
|
import org.moire.ultrasonic.api.subsonic.response.SearchTwoResponse;
|
||||||
|
import org.moire.ultrasonic.api.subsonic.response.StreamResponse;
|
||||||
import org.moire.ultrasonic.api.subsonic.response.SubsonicResponse;
|
import org.moire.ultrasonic.api.subsonic.response.SubsonicResponse;
|
||||||
import org.moire.ultrasonic.data.APIAlbumConverter;
|
import org.moire.ultrasonic.data.APIAlbumConverter;
|
||||||
import org.moire.ultrasonic.data.APIArtistConverter;
|
import org.moire.ultrasonic.data.APIArtistConverter;
|
||||||
@ -110,6 +111,7 @@ import org.moire.ultrasonic.service.parser.JukeboxStatusParser;
|
|||||||
import org.moire.ultrasonic.service.parser.MusicDirectoryParser;
|
import org.moire.ultrasonic.service.parser.MusicDirectoryParser;
|
||||||
import org.moire.ultrasonic.service.parser.RandomSongsParser;
|
import org.moire.ultrasonic.service.parser.RandomSongsParser;
|
||||||
import org.moire.ultrasonic.service.parser.ShareParser;
|
import org.moire.ultrasonic.service.parser.ShareParser;
|
||||||
|
import org.moire.ultrasonic.service.parser.SubsonicRESTException;
|
||||||
import org.moire.ultrasonic.service.parser.UserInfoParser;
|
import org.moire.ultrasonic.service.parser.UserInfoParser;
|
||||||
import org.moire.ultrasonic.service.ssl.SSLSocketFactory;
|
import org.moire.ultrasonic.service.ssl.SSLSocketFactory;
|
||||||
import org.moire.ultrasonic.service.ssl.TrustSelfSignedStrategy;
|
import org.moire.ultrasonic.service.ssl.TrustSelfSignedStrategy;
|
||||||
@ -757,75 +759,64 @@ public class RESTMusicService implements MusicService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Bitmap getCoverArt(Context context, final MusicDirectory.Entry entry, int size, boolean saveToFile, boolean highQuality, ProgressListener progressListener) throws Exception
|
public Bitmap getCoverArt(Context context,
|
||||||
{
|
final MusicDirectory.Entry entry,
|
||||||
|
int size,
|
||||||
|
boolean saveToFile,
|
||||||
|
boolean highQuality,
|
||||||
|
ProgressListener progressListener) throws Exception {
|
||||||
// Synchronize on the entry so that we don't download concurrently for
|
// Synchronize on the entry so that we don't download concurrently for
|
||||||
// the same song.
|
// the same song.
|
||||||
if (entry == null)
|
if (entry == null) {
|
||||||
{
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (entry)
|
synchronized (entry) {
|
||||||
{
|
|
||||||
// Use cached file, if existing.
|
// Use cached file, if existing.
|
||||||
Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, entry, size, highQuality);
|
Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, entry, size, highQuality);
|
||||||
boolean serverScaling = Util.isServerScalingEnabled(context);
|
boolean serverScaling = Util.isServerScalingEnabled(context);
|
||||||
|
|
||||||
if (bitmap == null)
|
if (bitmap == null) {
|
||||||
{
|
Log.d(TAG, "Loading cover art for: " + entry);
|
||||||
String url = Util.getRestUrl(context, "getCoverArt");
|
|
||||||
|
final String id = entry.getCoverArt();
|
||||||
|
if (id == null) {
|
||||||
|
return null; // Can't load
|
||||||
|
}
|
||||||
|
|
||||||
|
StreamResponse response = subsonicAPIClient.getCoverArt(id, (long) size);
|
||||||
|
if (response.hasError() || response.getStream() == null) {
|
||||||
|
if (response.getApiError() != null) {
|
||||||
|
throw new SubsonicRESTException(response.getApiError().getCode(), "rest error");
|
||||||
|
} else {
|
||||||
|
throw new IOException("Failed to make endpoint request, code: " +
|
||||||
|
response.getRequestErrorCode());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (response.getStream() == null) {
|
||||||
|
return null; // Failed to load
|
||||||
|
}
|
||||||
|
|
||||||
InputStream in = null;
|
InputStream in = null;
|
||||||
try
|
try {
|
||||||
{
|
in = response.getStream();
|
||||||
List<String> parameterNames;
|
|
||||||
List<Object> parameterValues;
|
|
||||||
|
|
||||||
if (serverScaling)
|
|
||||||
{
|
|
||||||
parameterNames = asList("id", "size");
|
|
||||||
parameterValues = Arrays.<Object>asList(entry.getCoverArt(), size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
parameterNames = Collections.singletonList("id");
|
|
||||||
parameterValues = Arrays.<Object>asList(entry.getCoverArt());
|
|
||||||
}
|
|
||||||
|
|
||||||
HttpEntity entity = getEntityForURL(context, url, null, parameterNames, parameterValues, progressListener);
|
|
||||||
in = entity.getContent();
|
|
||||||
|
|
||||||
// If content type is XML, an error occurred. Get it.
|
|
||||||
String contentType = Util.getContentType(entity);
|
|
||||||
if (contentType != null && contentType.startsWith("text/xml"))
|
|
||||||
{
|
|
||||||
new ErrorParser(context).parse(new InputStreamReader(in, Constants.UTF_8));
|
|
||||||
return null; // Never reached.
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] bytes = Util.toByteArray(in);
|
byte[] bytes = Util.toByteArray(in);
|
||||||
|
|
||||||
// If we aren't allowing server-side scaling, always save the file to disk because it will be unmodified
|
// If we aren't allowing server-side scaling, always save the file to disk because it will be unmodified
|
||||||
if (!serverScaling || saveToFile)
|
if (!serverScaling || saveToFile) {
|
||||||
{
|
|
||||||
OutputStream out = null;
|
OutputStream out = null;
|
||||||
|
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
out = new FileOutputStream(FileUtil.getAlbumArtFile(context, entry));
|
out = new FileOutputStream(FileUtil.getAlbumArtFile(context, entry));
|
||||||
out.write(bytes);
|
out.write(bytes);
|
||||||
}
|
} finally {
|
||||||
finally
|
|
||||||
{
|
|
||||||
Util.close(out);
|
Util.close(out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bitmap = FileUtil.getSampledBitmap(bytes, size, highQuality);
|
bitmap = FileUtil.getSampledBitmap(bytes, size, highQuality);
|
||||||
}
|
} finally {
|
||||||
finally
|
|
||||||
{
|
|
||||||
Util.close(in);
|
Util.close(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user