Skip to content

Commit

Permalink
Make the Album artist be listed as the album's Primary artist and dis…
Browse files Browse the repository at this point in the history
…tinguish albums by the combination of (Album name, Album artist).
  • Loading branch information
ddv239 committed Aug 7, 2018
1 parent 480df8e commit 69afc3b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,20 @@ private boolean rpcInspectFile(File file) {
if (discNumber == null)
discNumber = "1"; // untagged, but most likely '1' - this prevents annoying sorting issues with partially tagged files

long artistId = MediaLibrary.hash63(artist);
long albumId = MediaLibrary.hash63(album);
// albumartist is now always present
String albumartist = tags.getFirst(MediaMetadataExtractor.ALBUMARTIST);
if (albumartist == null)
albumartist = "<No Artist>";

long albumartistId = MediaLibrary.hash63(albumartist);

// Overwrite albumId with a hash that included the parent dir if set in preferences
// I have several albums all called "Greatest Hits" with different album artists
String albumIdString = album + "\n" + albumartist;
// Include the parent dir in the hash if set in preferences
if (prefs.groupAlbumsByFolder) {
albumId = MediaLibrary.hash63(album + "\n" + file.getParent());
albumIdString += "\n" + file.getParent();
}
long albumId = MediaLibrary.hash63(albumIdString);

ContentValues v = new ContentValues();
v.put(MediaLibrary.SongColumns._ID, songId);
Expand All @@ -527,31 +534,45 @@ private boolean rpcInspectFile(File file) {
v.put(MediaLibrary.AlbumColumns._ID, albumId);
v.put(MediaLibrary.AlbumColumns.ALBUM, album);
v.put(MediaLibrary.AlbumColumns.ALBUM_SORT, MediaLibrary.keyFor(album));
v.put(MediaLibrary.AlbumColumns.PRIMARY_ARTIST_ID, artistId);
v.put(MediaLibrary.AlbumColumns.PRIMARY_ARTIST_ID, albumartistId);
v.put(MediaLibrary.AlbumColumns.PRIMARY_ALBUM_YEAR,tags.getFirst(MediaMetadataExtractor.YEAR));
long albumInsert = mBackend.insert(MediaLibrary.TABLE_ALBUMS, null, v);
if (albumInsert == -1) {
// Insert failed, so the column probably already existed.
// Insert failed, so the entry probably already existed.
// We need to ensure that the album table is up-to-date as it contains
// some 'cached' (PRIMARY_*) values.
// Failure to do so would mean that we never update the year or may point to an
// orphaned artist id.
v.clear();
v.put(MediaLibrary.AlbumColumns.PRIMARY_ARTIST_ID, artistId);
v.put(MediaLibrary.AlbumColumns.PRIMARY_ARTIST_ID, albumartistId);
v.put(MediaLibrary.AlbumColumns.PRIMARY_ALBUM_YEAR,tags.getFirst(MediaMetadataExtractor.YEAR));
mBackend.update(MediaLibrary.TABLE_ALBUMS, v, MediaLibrary.AlbumColumns._ID+"=?", new String[]{ Long.toString(albumId) });
}

long artistId = MediaLibrary.hash63(artist);

v.clear();
v.put(MediaLibrary.ContributorColumns._ID, artistId);
v.put(MediaLibrary.ContributorColumns._CONTRIBUTOR, artist);
v.put(MediaLibrary.ContributorColumns._ID, artistId);
v.put(MediaLibrary.ContributorColumns._CONTRIBUTOR, artist);
v.put(MediaLibrary.ContributorColumns._CONTRIBUTOR_SORT, MediaLibrary.keyFor(artist));
mBackend.insert(MediaLibrary.TABLE_CONTRIBUTORS, null, v);

v.clear();
v.put(MediaLibrary.ContributorSongColumns._CONTRIBUTOR_ID, artistId);
v.put(MediaLibrary.ContributorSongColumns.SONG_ID, songId);
v.put(MediaLibrary.ContributorSongColumns.ROLE, MediaLibrary.ROLE_ARTIST);
mBackend.insert(MediaLibrary.TABLE_CONTRIBUTORS_SONGS, null, v);

v.clear();
v.put(MediaLibrary.ContributorColumns._ID, albumartistId);
v.put(MediaLibrary.ContributorColumns._CONTRIBUTOR, albumartist);
v.put(MediaLibrary.ContributorColumns._CONTRIBUTOR_SORT, MediaLibrary.keyFor(albumartist));
mBackend.insert(MediaLibrary.TABLE_CONTRIBUTORS, null, v);

v.clear();
v.put(MediaLibrary.ContributorSongColumns._CONTRIBUTOR_ID, albumartistId);
v.put(MediaLibrary.ContributorSongColumns.SONG_ID, songId);
v.put(MediaLibrary.ContributorSongColumns.ROLE, MediaLibrary.ROLE_ARTIST);
v.put(MediaLibrary.ContributorSongColumns.ROLE, MediaLibrary.ROLE_ALBUMARTIST);
mBackend.insert(MediaLibrary.TABLE_CONTRIBUTORS_SONGS, null, v);

// Composers are optional: only add if we found it
Expand All @@ -571,23 +592,6 @@ private boolean rpcInspectFile(File file) {
mBackend.insert(MediaLibrary.TABLE_CONTRIBUTORS_SONGS, null, v);
}

// Same as with composer: albumartist is an optional tag
String albumartist = tags.getFirst(MediaMetadataExtractor.ALBUMARTIST);
if (albumartist != null) {
long albumartistId = MediaLibrary.hash63(albumartist);
v.clear();
v.put(MediaLibrary.ContributorColumns._ID, albumartistId);
v.put(MediaLibrary.ContributorColumns._CONTRIBUTOR, albumartist);
v.put(MediaLibrary.ContributorColumns._CONTRIBUTOR_SORT, MediaLibrary.keyFor(albumartist));
mBackend.insert(MediaLibrary.TABLE_CONTRIBUTORS, null, v);

v.clear();
v.put(MediaLibrary.ContributorSongColumns._CONTRIBUTOR_ID, albumartistId);
v.put(MediaLibrary.ContributorSongColumns.SONG_ID, songId);
v.put(MediaLibrary.ContributorSongColumns.ROLE, MediaLibrary.ROLE_ALBUMARTIST);
mBackend.insert(MediaLibrary.TABLE_CONTRIBUTORS_SONGS, null, v);
}

// A song might be in multiple genres
if (tags.containsKey(MediaMetadataExtractor.GENRE)) {
ArrayList<String> genres = tags.get(MediaMetadataExtractor.GENRE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public class MediaSchema {
+" ;";

/**
* View wich includes SONGS_ALBUMS_ARTISTS and any other contributors
* View which includes SONGS_ALBUMS_ARTISTS and any other contributors
* This view should only be used if needed as the SQL query is pretty expensive
*/
private static final String VIEW_CREATE_SONGS_ALBUMS_ARTISTS_HUGE = "CREATE VIEW "+ MediaLibrary.VIEW_SONGS_ALBUMS_ARTISTS_HUGE+" AS "
Expand Down

0 comments on commit 69afc3b

Please sign in to comment.