set disc_num to 1 if unset

This commit is contained in:
Adrian Ulrich 2017-01-03 21:22:11 +01:00
parent e4cbf3e4fe
commit 364a08b3bc
3 changed files with 12 additions and 5 deletions

View File

@ -35,7 +35,7 @@ public class MediaLibraryBackend extends SQLiteOpenHelper {
/**
* The database version we are using
*/
private static final int DATABASE_VERSION = 20170101;
private static final int DATABASE_VERSION = 20170102;
/**
* on-disk file to store the database
*/

View File

@ -362,16 +362,19 @@ public class MediaScanner implements Handler.Callback {
// Get tags which always must be set
String title = tags.getFirst(MediaMetadataExtractor.TITLE);
if (title == null)
title = "Untitled";
title = "<"+file.getName()+">";
String album = tags.getFirst(MediaMetadataExtractor.ALBUM);
if (album == null)
album = "No Album";
album = "<No Album>";
String artist = tags.getFirst(MediaMetadataExtractor.ARTIST);
if (artist == null)
artist = "No Artist";
artist = "<No Artist>";
String discNumber = tags.getFirst(MediaMetadataExtractor.DISC_NUMBER);
if (discNumber == null)
discNumber = "1"; // untagged, but most likely '1' - this prevents annoying sorting issues with partially tagged files
long albumId = MediaLibrary.hash63(album);
long artistId = MediaLibrary.hash63(artist);
@ -383,7 +386,7 @@ public class MediaScanner implements Handler.Callback {
v.put(MediaLibrary.SongColumns.ALBUM_ID, albumId);
v.put(MediaLibrary.SongColumns.DURATION, tags.getFirst(MediaMetadataExtractor.DURATION));
v.put(MediaLibrary.SongColumns.SONG_NUMBER, tags.getFirst(MediaMetadataExtractor.TRACK_NUMBER));
v.put(MediaLibrary.SongColumns.DISC_NUMBER, tags.getFirst(MediaMetadataExtractor.DISC_NUMBER));
v.put(MediaLibrary.SongColumns.DISC_NUMBER, discNumber);
v.put(MediaLibrary.SongColumns.YEAR, tags.getFirst(MediaMetadataExtractor.YEAR));
v.put(MediaLibrary.SongColumns.PATH, path);
mBackend.insert(MediaLibrary.TABLE_SONGS, null, v);

View File

@ -217,6 +217,10 @@ public class MediaSchema {
dbh.execSQL(DATABASE_CREATE_SONGS);
dbh.execSQL(DATABASE_CREATE_ALBUMS);
}
if (oldVersion < 20170102) {
dbh.execSQL("UPDATE songs SET disc_num=1 WHERE disc_num IS null");
}
}
}