Search in sources :

Example 1 with MetaData

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;
}
Also used : MetaData(com.github.hakko.musiccabinet.domain.model.library.MetaData) File(com.github.hakko.musiccabinet.domain.model.library.File) DateTime(org.joda.time.DateTime)

Example 2 with MetaData

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);
}
Also used : ScrobbleClient(com.github.hakko.musiccabinet.ws.lastfm.ScrobbleClient) MetaData(com.github.hakko.musiccabinet.domain.model.library.MetaData) UpdateNowPlayingClient(com.github.hakko.musiccabinet.ws.lastfm.UpdateNowPlayingClient) LastFmUser(com.github.hakko.musiccabinet.domain.model.library.LastFmUser) Scrobble(com.github.hakko.musiccabinet.domain.model.aggr.Scrobble) WSResponse(com.github.hakko.musiccabinet.ws.lastfm.WSResponse) Track(com.github.hakko.musiccabinet.domain.model.music.Track) PlayCountDao(com.github.hakko.musiccabinet.dao.PlayCountDao) Before(org.junit.Before)

Example 3 with MetaData

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();
}
Also used : MetaData(com.github.hakko.musiccabinet.domain.model.library.MetaData) ArrayList(java.util.ArrayList) File(com.github.hakko.musiccabinet.domain.model.library.File) Before(org.junit.Before)

Example 4 with MetaData

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);
    }
}
Also used : AudioHeader(org.jaudiotagger.audio.AudioHeader) CannotReadException(org.jaudiotagger.audio.exceptions.CannotReadException) InvalidAudioFrameException(org.jaudiotagger.audio.exceptions.InvalidAudioFrameException) IOException(java.io.IOException) AudioFile(org.jaudiotagger.audio.AudioFile) TagException(org.jaudiotagger.tag.TagException) MetaData(com.github.hakko.musiccabinet.domain.model.library.MetaData) ReadOnlyFileException(org.jaudiotagger.audio.exceptions.ReadOnlyFileException) FlacTag(org.jaudiotagger.tag.flac.FlacTag) Tag(org.jaudiotagger.tag.Tag) AbstractID3v2Tag(org.jaudiotagger.tag.id3.AbstractID3v2Tag)

Example 5 with MetaData

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);
}
Also used : NameSearchResult(com.github.hakko.musiccabinet.domain.model.aggr.NameSearchResult) SQLException(java.sql.SQLException) MetaData(com.github.hakko.musiccabinet.domain.model.library.MetaData) ResultSet(java.sql.ResultSet) Track(com.github.hakko.musiccabinet.domain.model.music.Track)

Aggregations

MetaData (com.github.hakko.musiccabinet.domain.model.library.MetaData)7 File (com.github.hakko.musiccabinet.domain.model.library.File)3 Track (com.github.hakko.musiccabinet.domain.model.music.Track)3 Before (org.junit.Before)2 PlayCountDao (com.github.hakko.musiccabinet.dao.PlayCountDao)1 NameSearchResult (com.github.hakko.musiccabinet.domain.model.aggr.NameSearchResult)1 Scrobble (com.github.hakko.musiccabinet.domain.model.aggr.Scrobble)1 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)1 ScrobbleClient (com.github.hakko.musiccabinet.ws.lastfm.ScrobbleClient)1 UpdateNowPlayingClient (com.github.hakko.musiccabinet.ws.lastfm.UpdateNowPlayingClient)1 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)1 IOException (java.io.IOException)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 AudioFile (org.jaudiotagger.audio.AudioFile)1 AudioHeader (org.jaudiotagger.audio.AudioHeader)1 CannotReadException (org.jaudiotagger.audio.exceptions.CannotReadException)1 InvalidAudioFrameException (org.jaudiotagger.audio.exceptions.InvalidAudioFrameException)1 ReadOnlyFileException (org.jaudiotagger.audio.exceptions.ReadOnlyFileException)1