Added disc numbers to library. Fixed some maven related build stuff.
This commit is contained in:
parent
e8255c5b32
commit
4414e0b51c
22
pom.xml
22
pom.xml
@ -8,6 +8,23 @@
|
|||||||
<artifactId>musicplayer</artifactId>
|
<artifactId>musicplayer</artifactId>
|
||||||
<version>DEVELOPMENT</version>
|
<version>DEVELOPMENT</version>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>2.3.2</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -30,6 +47,11 @@
|
|||||||
<artifactId>gstreamer-java</artifactId>
|
<artifactId>gstreamer-java</artifactId>
|
||||||
<version>1.5</version>
|
<version>1.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.12</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
|
@ -81,7 +81,8 @@ public class Gateway {
|
|||||||
Artist artist = new Artist(metadata.artist);
|
Artist artist = new Artist(metadata.artist);
|
||||||
artistObj = Optional.of(artist);
|
artistObj = Optional.of(artist);
|
||||||
}
|
}
|
||||||
session.save(new Song(metadata.trackNumber, metadata.title, artistObj.get(), albumObj.get(), metadata.genre, metadata.songFile));
|
session.save(new Song(metadata.trackNumber, metadata.discNumber, metadata.title, artistObj.get(),
|
||||||
|
albumObj.get(), metadata.genre, metadata.songFile));
|
||||||
session.getTransaction().commit();
|
session.getTransaction().commit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,14 +31,22 @@ public class Song implements Comparable<Song> {
|
|||||||
private String songFile;
|
private String songFile;
|
||||||
@Column(name = "trackNumber")
|
@Column(name = "trackNumber")
|
||||||
private int trackNumber;
|
private int trackNumber;
|
||||||
|
@Column(name = "discNumber")
|
||||||
|
private int discNumber;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private static int discNumberComparator = 1000;
|
||||||
|
|
||||||
protected Song() {
|
protected Song() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Song(String trackNumber, 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 {
|
try {
|
||||||
this.trackNumber = Integer.parseInt(trackNumber);
|
this.trackNumber = Integer.parseInt(trackNumber);
|
||||||
} catch (NumberFormatException e){ this.trackNumber = 0; }
|
} catch (NumberFormatException e){ this.trackNumber = 0; }
|
||||||
|
try {
|
||||||
|
this.discNumber = Integer.parseInt(discNumber);
|
||||||
|
} catch (NumberFormatException e){ this.discNumber = 0; }
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.artist = artist;
|
this.artist = artist;
|
||||||
this.genre = genre;
|
this.genre = genre;
|
||||||
@ -118,8 +126,10 @@ public class Song implements Comparable<Song> {
|
|||||||
return trackNumber;
|
return trackNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Integer getDiscNumber() { return discNumber; }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(Song o) {
|
public int compareTo(Song o) {
|
||||||
return trackNumber - o.getTrackNumber();
|
return (trackNumber - o.getTrackNumber()) + ((discNumber - o.getDiscNumber()) * discNumberComparator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ import musicplayer.model.Song;
|
|||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.jaudiotagger.tag.FieldKey;
|
import org.jaudiotagger.tag.FieldKey;
|
||||||
import org.jaudiotagger.tag.Tag;
|
import org.jaudiotagger.tag.Tag;
|
||||||
import org.jaudiotagger.tag.id3.ID3v11Tag;
|
import org.jaudiotagger.tag.id3.ID3v23Tag;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -70,9 +70,9 @@ public class GatewayTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testListAllSongs() throws Exception {
|
public void testListAllSongs() throws Exception {
|
||||||
Song song1 = new Song("1", "s1", new Artist("a"), new Album("a"), "", "");
|
Song song1 = new Song("1", "1", "s1", new Artist("a"), new Album("a"), "", "");
|
||||||
Song song2 = new Song("2", "s2", new Artist("b"), new Album("a"), "", "");
|
Song song2 = new Song("2", "1","s2", new Artist("b"), new Album("a"), "", "");
|
||||||
Song song3 = new Song("1", "t1", new Artist("c"), new Album("b"), "", "");
|
Song song3 = new Song("1", "1","t1", new Artist("c"), new Album("b"), "", "");
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
session.save(song1);
|
session.save(song1);
|
||||||
session.save(song2);
|
session.save(song2);
|
||||||
@ -95,9 +95,9 @@ public class GatewayTest {
|
|||||||
public void testListAllSongsGroupedByAlbum() throws Exception {
|
public void testListAllSongsGroupedByAlbum() throws Exception {
|
||||||
Album album1 = new Album("Test 1");
|
Album album1 = new Album("Test 1");
|
||||||
Album album2 = new Album("Test 2");
|
Album album2 = new Album("Test 2");
|
||||||
Song song1 = new Song("1", "s1", new Artist("a"), album1, "", "");
|
Song song1 = new Song("1", "1", "s1", new Artist("a"), album1, "", "");
|
||||||
Song song2 = new Song("2", "s2", new Artist("b"), album1, "", "");
|
Song song2 = new Song("2", "1", "s2", new Artist("b"), album1, "", "");
|
||||||
Song song3 = new Song("1", "t1", new Artist("c"), album2, "", "");
|
Song song3 = new Song("1", "1", "t1", new Artist("c"), album2, "", "");
|
||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
session.save(song1);
|
session.save(song1);
|
||||||
session.save(song2);
|
session.save(song2);
|
||||||
@ -120,12 +120,13 @@ public class GatewayTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddSong() throws Exception {
|
public void testAddSong() throws Exception {
|
||||||
Tag tags = new ID3v11Tag();
|
Tag tags = new ID3v23Tag();
|
||||||
tags.addField(FieldKey.ALBUM, "Test Album");
|
tags.addField(FieldKey.ALBUM, "Test Album");
|
||||||
tags.addField(FieldKey.ARTIST, "Test Artist");
|
tags.addField(FieldKey.ARTIST, "Test Artist");
|
||||||
tags.addField(FieldKey.TRACK, "1");
|
tags.addField(FieldKey.TRACK, "1");
|
||||||
tags.addField(FieldKey.TITLE, "Test Song");
|
tags.addField(FieldKey.TITLE, "Test Song");
|
||||||
tags.addField(FieldKey.GENRE, "Test Genre");
|
tags.addField(FieldKey.GENRE, "Test Genre");
|
||||||
|
tags.addField(FieldKey.DISC_NO, "100");
|
||||||
ExtractedMetadata metadata = new ExtractedMetadata(tags, new File(""));
|
ExtractedMetadata metadata = new ExtractedMetadata(tags, new File(""));
|
||||||
Gateway.addSong(metadata);
|
Gateway.addSong(metadata);
|
||||||
Song song = (Song)session.createCriteria(Song.class).uniqueResult();
|
Song song = (Song)session.createCriteria(Song.class).uniqueResult();
|
||||||
@ -134,5 +135,6 @@ public class GatewayTest {
|
|||||||
assertEquals(song.getTrackNumber(), Integer.valueOf(1));
|
assertEquals(song.getTrackNumber(), Integer.valueOf(1));
|
||||||
assertEquals(song.getTitle(), metadata.title);
|
assertEquals(song.getTitle(), metadata.title);
|
||||||
assertEquals(song.getGenre(), metadata.genre);
|
assertEquals(song.getGenre(), metadata.genre);
|
||||||
|
assertEquals(song.getDiscNumber(), Integer.valueOf(100));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user