mirror of
https://github.com/antebudimir/tempus.git
synced 2026-04-15 16:27:26 +00:00
fix: handle empty albums and null mappings (#301)
This commit is contained in:
commit
3fbadc2521
2 changed files with 108 additions and 74 deletions
|
|
@ -205,6 +205,8 @@ public class AlbumRepository {
|
|||
}
|
||||
|
||||
public void getInstantMix(AlbumID3 album, int count, MediaCallback callback) {
|
||||
Log.d("AlbumRepository", "Attempting getInstantMix for AlbumID: " + album.getId());
|
||||
|
||||
App.getSubsonicClientInstance(false)
|
||||
.getBrowsingClient()
|
||||
.getSimilarSongs2(album.getId(), count)
|
||||
|
|
@ -213,8 +215,17 @@ public class AlbumRepository {
|
|||
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull Response<ApiResponse> response) {
|
||||
List<Child> songs = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getSubsonicResponse().getSimilarSongs2() != null) {
|
||||
songs.addAll(response.body().getSubsonicResponse().getSimilarSongs2().getSongs());
|
||||
if (response.isSuccessful()
|
||||
&& response.body() != null
|
||||
&& response.body().getSubsonicResponse().getSimilarSongs2() != null) {
|
||||
|
||||
List<Child> similarSongs = response.body().getSubsonicResponse().getSimilarSongs2().getSongs();
|
||||
|
||||
if (similarSongs == null) {
|
||||
Log.w("AlbumRepository", "API successful but 'songs' list was NULL for AlbumID: " + album.getId());
|
||||
} else {
|
||||
songs.addAll(similarSongs);
|
||||
}
|
||||
}
|
||||
|
||||
callback.onLoadMedia(songs);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.cappielloantonio.tempo.util;
|
|||
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.OptIn;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
|
@ -35,21 +36,31 @@ public class MappingUtil {
|
|||
return mediaItems;
|
||||
}
|
||||
|
||||
private static final String TAG = "MappingUtil";
|
||||
|
||||
public static MediaItem mapMediaItem(Child media) {
|
||||
try {
|
||||
Uri uri = getUri(media);
|
||||
Uri artworkUri = Uri.parse(CustomGlideRequest.createUrl(media.getCoverArtId(), Preferences.getImageSize()));
|
||||
String coverArtId = media.getCoverArtId();
|
||||
Uri artworkUri = null;
|
||||
|
||||
if (coverArtId != null) {
|
||||
artworkUri = Uri.parse(CustomGlideRequest.createUrl(coverArtId, Preferences.getImageSize()));
|
||||
}
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("id", media.getId());
|
||||
bundle.putString("parentId", media.getParentId());
|
||||
bundle.putBoolean("isDir", media.isDir());
|
||||
|
||||
bundle.putString("title", media.getTitle());
|
||||
bundle.putString("album", media.getAlbum());
|
||||
bundle.putString("artist", media.getArtist());
|
||||
|
||||
bundle.putInt("track", media.getTrack() != null ? media.getTrack() : 0);
|
||||
bundle.putInt("year", media.getYear() != null ? media.getYear() : 0);
|
||||
bundle.putString("genre", media.getGenre());
|
||||
bundle.putString("coverArtId", media.getCoverArtId());
|
||||
bundle.putString("coverArtId", coverArtId);
|
||||
bundle.putLong("size", media.getSize() != null ? media.getSize() : 0);
|
||||
bundle.putString("contentType", media.getContentType());
|
||||
bundle.putString("suffix", media.getSuffix());
|
||||
|
|
@ -74,9 +85,10 @@ public class MappingUtil {
|
|||
bundle.putInt("originalWidth", media.getOriginalWidth() != null ? media.getOriginalWidth() : 0);
|
||||
bundle.putInt("originalHeight", media.getOriginalHeight() != null ? media.getOriginalHeight() : 0);
|
||||
bundle.putString("uri", uri.toString());
|
||||
bundle.putString("assetLinkSong", AssetLinkUtil.buildLink(AssetLinkUtil.TYPE_SONG, media.getId()));
|
||||
bundle.putString("assetLinkAlbum", AssetLinkUtil.buildLink(AssetLinkUtil.TYPE_ALBUM, media.getAlbumId()));
|
||||
bundle.putString("assetLinkArtist", AssetLinkUtil.buildLink(AssetLinkUtil.TYPE_ARTIST, media.getArtistId()));
|
||||
|
||||
bundle.putString("assetLinkSong", media.getId() != null ? AssetLinkUtil.buildLink(AssetLinkUtil.TYPE_SONG, media.getId()) : null);
|
||||
bundle.putString("assetLinkAlbum", media.getAlbumId() != null ? AssetLinkUtil.buildLink(AssetLinkUtil.TYPE_ALBUM, media.getAlbumId()) : null);
|
||||
bundle.putString("assetLinkArtist", media.getArtistId() != null ? AssetLinkUtil.buildLink(AssetLinkUtil.TYPE_ARTIST, media.getArtistId()) : null);
|
||||
bundle.putString("assetLinkGenre", AssetLinkUtil.buildLink(AssetLinkUtil.TYPE_GENRE, media.getGenre()));
|
||||
Integer year = media.getYear();
|
||||
bundle.putString("assetLinkYear", year != null && year != 0 ? AssetLinkUtil.buildLink(AssetLinkUtil.TYPE_YEAR, String.valueOf(year)) : null);
|
||||
|
|
@ -113,6 +125,17 @@ public class MappingUtil {
|
|||
.setMimeType(MimeTypes.BASE_TYPE_AUDIO)
|
||||
.setUri(uri)
|
||||
.build();
|
||||
|
||||
} catch (Exception e) {
|
||||
String id = media != null ? media.getId() : "NULL_MEDIA_OBJECT";
|
||||
String title = media != null ? media.getTitle() : "N/A";
|
||||
|
||||
Log.e(TAG, "Instant Mix CRASH! Failed to map song to MediaItem. " +
|
||||
"Problematic Song ID: " + id +
|
||||
", Title: " + title +
|
||||
". Inspect this song's Subsonic data for missing fields.", e);
|
||||
throw new RuntimeException("Mapping failed for song ID: " + id, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static MediaItem mapMediaItem(MediaItem old) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue