Search in sources :

Example 6 with MetaData

use of com.github.hakko.musiccabinet.domain.model.library.MetaData in project musiccabinet by hakko.

the class TrackWithMetadataRowMapper method mapRow.

@Override
public Track mapRow(ResultSet rs, int rowNum) throws SQLException {
    String trackName = rs.getString(1);
    MetaData md = new MetaData();
    md.setAlbum(rs.getString(2));
    md.setArtist(rs.getString(3));
    md.setAlbumArtist(rs.getString(4));
    md.setComposer(rs.getString(5));
    md.setTrackNr(rs.getShort(6));
    md.setTrackNrs(rs.getShort(7));
    md.setDiscNr(rs.getShort(8));
    md.setDiscNrs(rs.getShort(9));
    md.setYear(rs.getShort(10));
    md.setHasLyrics(rs.getBoolean(11));
    md.setBitrate(rs.getShort(12));
    md.setVbr(rs.getBoolean(13));
    md.setDuration(rs.getShort(14));
    md.setMediaType(Mediatype.values()[rs.getShort(15)]);
    md.setPath(rs.getString(16) + separatorChar + rs.getString(17));
    md.setSize(rs.getInt(18));
    md.setModified(rs.getTimestamp(19).getTime());
    int trackId = rs.getInt(20);
    md.setAlbumId(rs.getInt(21));
    md.setArtistId(rs.getInt(22));
    return new Track(trackId, trackName, md);
}
Also used : MetaData(com.github.hakko.musiccabinet.domain.model.library.MetaData) Track(com.github.hakko.musiccabinet.domain.model.music.Track)

Example 7 with MetaData

use of com.github.hakko.musiccabinet.domain.model.library.MetaData in project musiccabinet by hakko.

the class JdbcLibraryAdditionDao method addMetadata.

private void addMetadata(Set<File> files) {
    String sql = "insert into library.file_headertag_import (path, filename, extension," + "bitrate, vbr, duration, artist_name, album_artist_name, composer_name," + "album_name, track_name, track_nr, track_nrs, disc_nr, disc_nrs, year," + "tag_name, lyrics, coverart, artistsort_name, albumartistsort_name) values" + "(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    BatchSqlUpdate batch = new BatchSqlUpdate(jdbcTemplate.getDataSource(), sql);
    batch.declareParameter(new SqlParameter("path", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("filename", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("extension", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("bitrate", Types.SMALLINT));
    batch.declareParameter(new SqlParameter("vbr", Types.BOOLEAN));
    batch.declareParameter(new SqlParameter("duration", Types.SMALLINT));
    batch.declareParameter(new SqlParameter("artist_name", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("album_artist_name", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("composer_name", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("album_name", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("track_name", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("track_nr", Types.SMALLINT));
    batch.declareParameter(new SqlParameter("track_nrs", Types.SMALLINT));
    batch.declareParameter(new SqlParameter("disc_nr", Types.SMALLINT));
    batch.declareParameter(new SqlParameter("disc_nrs", Types.SMALLINT));
    batch.declareParameter(new SqlParameter("year", Types.SMALLINT));
    batch.declareParameter(new SqlParameter("tag_name", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("lyrics", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("coverart", Types.BOOLEAN));
    batch.declareParameter(new SqlParameter("artistsort_name", Types.VARCHAR));
    batch.declareParameter(new SqlParameter("albumartistsort_name", Types.VARCHAR));
    for (File file : files) {
        MetaData md = file.getMetadata();
        if (md != null) {
            batch.update(new Object[] { file.getDirectory(), file.getFilename(), md.getMediaType().getFilesuffix(), md.getBitrate(), md.isVbr(), md.getDuration(), md.getArtist(), md.getAlbumArtist(), md.getComposer(), md.getAlbum(), md.getTitle(), md.getTrackNr(), md.getTrackNrs(), md.getDiscNr(), md.getDiscNrs(), md.getYear(), md.getGenre(), md.getLyrics(), md.isCoverArtEmbedded(), md.getArtistSort(), md.getAlbumArtistSort() });
        }
    }
    batch.flush();
}
Also used : SqlParameter(org.springframework.jdbc.core.SqlParameter) MetaData(com.github.hakko.musiccabinet.domain.model.library.MetaData) BatchSqlUpdate(org.springframework.jdbc.object.BatchSqlUpdate) File(com.github.hakko.musiccabinet.domain.model.library.File)

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