use of com.github.hakko.musiccabinet.domain.model.library.MetaData in project musiccabinet by hakko.
the class UnittestLibraryUtil method getFile.
public static File getFile() {
File file = new File("/unittest", "/unittest/file" + counter++ + ".ogg", new DateTime(), 0);
MetaData md = new MetaData();
md.setArtist("Unittest Artist");
md.setAlbum("Unittest Album " + counter);
md.setTitle("Unittest Title " + counter);
md.setBitrate((short) 144);
md.setVbr(false);
md.setDuration((short) 90);
md.setYear((short) 1900);
md.setMediaType(Mediatype.OGG);
file.setMetaData(md);
return file;
}
use of com.github.hakko.musiccabinet.domain.model.library.MetaData in project musiccabinet by hakko.
the class ScrobbleServiceTest method createTestData.
@Before
public void createTestData() throws ApplicationException {
scrobbleService = new ScrobbleService();
UpdateNowPlayingClient nowPlayinglient = mock(UpdateNowPlayingClient.class);
when(nowPlayinglient.updateNowPlaying(Mockito.any(Scrobble.class))).thenReturn(new WSResponse(false, 404, "Not found"));
scrobbleService.setUpdateNowPlayingClient(nowPlayinglient);
ScrobbleClient scrobbleClient = mock(ScrobbleClient.class);
when(scrobbleClient.scrobble(Mockito.any(Scrobble.class))).thenReturn(new WSResponse("<lfm status=\"ok\"></lfm>"));
scrobbleService.setScrobbleClient(scrobbleClient);
PlayCountDao playCountDao = mock(PlayCountDao.class);
scrobbleService.setPlayCountDao(playCountDao);
MetaData metaData1 = new MetaData();
metaData1.setArtist("artist 1");
metaData1.setArtistId(artist1Id);
metaData1.setAlbum("album 1");
metaData1.setAlbumId(album1Id);
track1 = new Track(track1Id, "track 1", metaData1);
track2 = new Track(track2Id, "track 2", metaData1);
user1 = new LastFmUser(username1, sessionKey1);
user2 = new LastFmUser(username2, sessionKey2);
}
use of com.github.hakko.musiccabinet.domain.model.library.MetaData in project musiccabinet by hakko.
the class JdbcLibraryAdditionDaoTest method createAlbumTestData.
@Before
public void createAlbumTestData() throws ApplicationException {
PostgreSQLUtil.truncateTables(libraryAdditionDao);
final String DIR = "/dir", FILE = "file";
int fileNr = 0;
List<File> files = new ArrayList<>();
for (short year : new short[] { 2000, 2002, 2004, 2001, 2003 }) {
File file = new File(DIR, FILE + ++fileNr, parse(format("%d-01-01", year)), 0);
MetaData md = new MetaData();
md.setArtist("artist");
md.setTitle("title " + fileNr);
md.setAlbum("album " + fileNr);
md.setYear(year);
md.setMediaType(Mediatype.OGG);
file.setMetaData(md);
files.add(file);
}
libraryAdditionDao.addSubdirectories(null, set(DIR));
libraryAdditionDao.addFiles(DIR, new HashSet<>(files));
libraryAdditionDao.updateLibrary();
}
use of com.github.hakko.musiccabinet.domain.model.library.MetaData in project musiccabinet by hakko.
the class AudioTagService method updateMetadata.
public void updateMetadata(File file) {
String extension = getExtension(file.getFilename()).toUpperCase();
if (!ALLOWED_EXTENSIONS.contains(extension)) {
return;
}
MetaData metaData = new MetaData();
metaData.setMediaType(Mediatype.valueOf(extension));
try {
AudioFile audioFile = AudioFileIO.read(new java.io.File(file.getDirectory(), file.getFilename()));
Tag tag = audioFile.getTag();
if (tag != null) {
metaData.setArtist(getTagField(tag, ARTIST));
metaData.setArtistSort(getTagField(tag, ARTIST_SORT));
metaData.setAlbumArtist(toAlbumArtist(tag));
metaData.setAlbumArtistSort(getTagField(tag, ALBUM_ARTIST_SORT));
metaData.setAlbum(toAlbum(getTagField(tag, ALBUM)));
metaData.setTitle(getTagField(tag, TITLE));
metaData.setYear(getTagField(tag, YEAR));
metaData.setGenre(toGenre(getTagField(tag, GENRE)));
metaData.setLyrics(getTagField(tag, LYRICS));
metaData.setComposer(getTagField(tag, COMPOSER));
metaData.setDiscNr(toFirstNumber(getTagField(tag, DISC_NO)));
metaData.setDiscNrs(toShort(getTagField(tag, DISC_TOTAL)));
metaData.setTrackNr(toFirstNumber(getTagField(tag, TRACK)));
metaData.setTrackNrs(toShort(getTagField(tag, TRACK_TOTAL)));
metaData.setCoverArtEmbedded(tag.getFirstArtwork() != null);
}
AudioHeader audioHeader = audioFile.getAudioHeader();
if (audioHeader != null) {
metaData.setVbr(audioHeader.isVariableBitRate());
metaData.setBitrate((short) audioHeader.getBitRateAsNumber());
metaData.setDuration((short) audioHeader.getTrackLength());
}
file.setMetaData(metaData);
} catch (CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException | RuntimeException e) {
// AudioFileIO has been seen to throw NumberFormatException
LOG.warn("Could not read metadata of file " + file.getFilename() + " from " + file.getDirectory(), e);
}
}
use of com.github.hakko.musiccabinet.domain.model.library.MetaData in project musiccabinet by hakko.
the class JdbcNameSearchDao method getTracks.
@Override
public NameSearchResult<Track> getTracks(String userQuery, int offset, int limit) {
String sql = "select mart.id, mart.artist_name_capitalization," + " malb.id, malb.album_name_capitalization," + " lt.id, mt.track_name_capitalization from library.track lt" + " inner join music.track mt on lt.track_id = mt.id" + " inner join music.album malb on lt.album_id = malb.id" + " inner join music.artist mart on mt.artist_id = mart.id" + " where lt.track_name_search like ?" + " order by mt.track_name" + " offset ? limit ?";
List<Track> albums = jdbcTemplate.query(sql, new Object[] { getNameQuery(userQuery), offset, limit }, new RowMapper<Track>() {
@Override
public Track mapRow(ResultSet rs, int rowNum) throws SQLException {
MetaData metaData = new MetaData();
metaData.setArtistId(rs.getInt(1));
metaData.setArtist(rs.getString(2));
metaData.setAlbumId(rs.getInt(3));
metaData.setAlbum(rs.getString(4));
return new Track(rs.getInt(5), rs.getString(6), metaData);
}
});
return new NameSearchResult<>(albums, offset);
}
Aggregations