Updating the library will now to add songs with the same base file.
This commit is contained in:
parent
148eb38bba
commit
2ae4ca1402
@ -154,4 +154,8 @@ class Player {
|
|||||||
Gst.quit();
|
Gst.quit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isPlaying(){
|
||||||
|
return playBin.isPlaying();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,18 @@ public class Gateway {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param metadata Metadata of song to find.
|
||||||
|
* @return Song found with metadata or Optional.empty()
|
||||||
|
*/
|
||||||
|
public static Optional<Song> getOneSong(ExtractedMetadata metadata){
|
||||||
|
try (Session session = DatabaseManager.getInstance().getSession()) {
|
||||||
|
Song song = (Song)session.createCriteria(Song.class)
|
||||||
|
.add(Restrictions.eq("songFile", metadata.songFile)).uniqueResult();
|
||||||
|
return (song == null) ? Optional.empty() : Optional.of(song);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all items in the database of a certain type.
|
* List all items in the database of a certain type.
|
||||||
* @param typeClass Class representing the type of items to find.
|
* @param typeClass Class representing the type of items to find.
|
||||||
@ -74,7 +86,7 @@ public class Gateway {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new song to the database.
|
* Add a new song to the database.
|
||||||
*
|
* If the song already exists it will be updated instead.
|
||||||
* @param metadata New song information.
|
* @param metadata New song information.
|
||||||
*/
|
*/
|
||||||
public static void addSong(ExtractedMetadata metadata) {
|
public static void addSong(ExtractedMetadata metadata) {
|
||||||
@ -90,8 +102,13 @@ public class Gateway {
|
|||||||
Artist artist = new Artist(metadata.artist);
|
Artist artist = new Artist(metadata.artist);
|
||||||
artistObj = Optional.of(artist);
|
artistObj = Optional.of(artist);
|
||||||
}
|
}
|
||||||
|
Optional<Song> songObj = getOneSong(metadata);
|
||||||
|
if(!songObj.isPresent())
|
||||||
session.save(new Song(metadata.trackNumber, metadata.discNumber, metadata.title, artistObj.get(),
|
session.save(new Song(metadata.trackNumber, metadata.discNumber, metadata.title, artistObj.get(),
|
||||||
albumObj.get(), metadata.genre, metadata.songFile));
|
albumObj.get(), metadata.genre, metadata.songFile));
|
||||||
|
else
|
||||||
|
songObj.get().updateData(metadata.trackNumber, metadata.discNumber, metadata.title, artistObj.get(),
|
||||||
|
albumObj.get(), metadata.genre, metadata.songFile);
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,17 +41,7 @@ public class Song implements Comparable<Song>, IDBType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Song(String trackNumber, String discNumber, String title, Artist artist, Album album, String genre, String songFile) {
|
public Song(String trackNumber, String discNumber, String title, Artist artist, Album album, String genre, String songFile) {
|
||||||
try {
|
updateData(trackNumber, discNumber, title, artist, album, genre, songFile);
|
||||||
this.trackNumber = Integer.parseInt(trackNumber);
|
|
||||||
} catch (NumberFormatException e){ this.trackNumber = 0; }
|
|
||||||
try {
|
|
||||||
this.discNumber = Integer.parseInt(discNumber);
|
|
||||||
} catch (NumberFormatException e){ this.discNumber = 0; }
|
|
||||||
this.title = title;
|
|
||||||
this.artist = artist;
|
|
||||||
this.genre = genre;
|
|
||||||
this.album = album;
|
|
||||||
this.songFile = songFile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -139,4 +129,28 @@ public class Song implements Comparable<Song>, IDBType {
|
|||||||
public String getM3UFormatString(){
|
public String getM3UFormatString(){
|
||||||
return String.format("#EXTINF:0,%s - %s\n%s\n", getArtist().getName(), getTitle(), getSongFile().getAbsolutePath());
|
return String.format("#EXTINF:0,%s - %s\n%s\n", getArtist().getName(), getTitle(), getSongFile().getAbsolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the data stored in this Song object
|
||||||
|
* @param trackNumber Track Number
|
||||||
|
* @param discNumber Disc Number
|
||||||
|
* @param title Song Title
|
||||||
|
* @param artist Artist
|
||||||
|
* @param album Album
|
||||||
|
* @param genre Genre
|
||||||
|
* @param songFile Absolute path to song source file
|
||||||
|
*/
|
||||||
|
public void updateData(String trackNumber, String discNumber, String title, Artist artist, Album album, String genre, String songFile){
|
||||||
|
try {
|
||||||
|
this.trackNumber = Integer.parseInt(trackNumber);
|
||||||
|
} catch (NumberFormatException e){ this.trackNumber = 0; }
|
||||||
|
try {
|
||||||
|
this.discNumber = Integer.parseInt(discNumber);
|
||||||
|
} catch (NumberFormatException e){ this.discNumber = 0; }
|
||||||
|
this.title = title;
|
||||||
|
this.artist = artist;
|
||||||
|
this.genre = genre;
|
||||||
|
this.album = album;
|
||||||
|
this.songFile = songFile;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user