Search in sources :

Example 46 with Artist

use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.

the class JdbcArtistRelationDao method getArtistRelations.

@Override
public List<ArtistRelation> getArtistRelations(Artist sourceArtist) {
    final int sourceArtistId = jdbcTemplate.queryForInt("select * from music.get_artist_id(?)", sourceArtist.getName());
    String sql = "select artist_name_capitalization, weight" + " from music.artistrelation" + " inner join music.artist on music.artistrelation.target_id = music.artist.id" + " where music.artistrelation.source_id = ?";
    List<ArtistRelation> artistRelations = jdbcTemplate.query(sql, new Object[] { sourceArtistId }, new RowMapper<ArtistRelation>() {

        @Override
        public ArtistRelation mapRow(ResultSet rs, int rowNum) throws SQLException {
            String artistName = rs.getString(1);
            float match = rs.getFloat(2);
            return new ArtistRelation(new Artist(artistName), match);
        }
    });
    return artistRelations;
}
Also used : ArtistRelation(com.github.hakko.musiccabinet.domain.model.music.ArtistRelation) Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet)

Example 47 with Artist

use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.

the class JdbcArtistRelationDao method getSimilarArtistsByTags.

/*
	 * TODO
	 *
	 * on "Related artists" page, add an "Edit" possibility
	 * Display top tags for main artist
	 * Allow user to select which ones to use
	 * Return matching artists (see below)
	 * Add selected matching artists as related
	 *
	 * somehow mark as updated to avoid overwriting
	 */
public List<ArtistRelation> getSimilarArtistsByTags(int artistId) {
    String topTagsTable = settingsService.getArtistTopTagsTable();
    String topTagsSql = "select tag_id, tag_count from " + topTagsTable + " where artist_id = " + artistId + " order by tag_count desc limit 5";
    String similarityTableSql = "create temporary table similarity" + " (artist_id integer not null, count integer not null";
    String insertSimilaritySql = "insert into similarity (artist_id, count)" + " select artist_id, 100-abs(?-tag_count) from" + " " + topTagsTable + " where tag_id = ?";
    String topArtistsSql = "select a.artist_name_capitalization, m.sum/(100.0*?) from music.artist a" + " inner join (select artist_id, sum(count) from similarity group by artist_id) s" + " on a.id = s.artist_id order by m.sum desc";
    List<TagCount> topTags = jdbcTemplate.query(topTagsSql, new RowMapper<TagCount>() {

        @Override
        public TagCount mapRow(ResultSet rs, int rowNum) throws SQLException {
            return new TagCount(rs.getInt(1), rs.getInt(2));
        }
    });
    jdbcTemplate.execute(similarityTableSql);
    for (TagCount topTag : topTags) {
        jdbcTemplate.update(insertSimilaritySql, topTag.tagCount, topTag.tagId);
    }
    return jdbcTemplate.query(topArtistsSql, new Object[] { topTags.size() }, new RowMapper<ArtistRelation>() {

        @Override
        public ArtistRelation mapRow(ResultSet rs, int rowNum) throws SQLException {
            return new ArtistRelation(new Artist(rs.getString(1)), rs.getFloat(2));
        }
    });
}
Also used : ArtistRelation(com.github.hakko.musiccabinet.domain.model.music.ArtistRelation) Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet)

Example 48 with Artist

use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.

the class AlbumInfoHandler method endElement.

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (parsing) {
        String chars = characterData.toString();
        if (TAG_NAME.equals(qName)) {
            albumInfo = new AlbumInfo();
            albumInfo.setAlbum(new Album(chars));
        } else if (TAG_ARTIST.equals(qName)) {
            albumInfo.getAlbum().setArtist(new Artist(chars));
        } else if (TAG_IMAGE.equals(qName)) {
            if (ATTR_SMALL.equals(imageSize)) {
                albumInfo.setSmallImageUrl(validateUrl(chars));
            } else if (ATTR_MEDIUM.equals(imageSize)) {
                albumInfo.setMediumImageUrl(validateUrl(chars));
            } else if (ATTR_LARGE.equals(imageSize)) {
                albumInfo.setLargeImageUrl(validateUrl(chars));
            } else if (ATTR_EXTRA_LARGE.equals(imageSize)) {
                albumInfo.setExtraLargeImageUrl(validateUrl(chars));
            }
        } else if (TAG_LISTENERS.equals(qName)) {
            albumInfo.setListeners(toInt(chars));
        } else if (TAG_PLAY_COUNT.equals(qName)) {
            albumInfo.setPlayCount(toInt(chars));
            parsing = false;
        }
    }
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) AlbumInfo(com.github.hakko.musiccabinet.domain.model.music.AlbumInfo) Album(com.github.hakko.musiccabinet.domain.model.music.Album)

Example 49 with Artist

use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.

the class ArtistInfoHandler method endElement.

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (parsing) {
        String chars = characterData.toString();
        if (TAG_NAME.equals(qName) && artistInfo == null) {
            artistInfo = new ArtistInfo();
            artistInfo.setArtist(new Artist(chars));
        } else if (TAG_IMAGE.equals(qName)) {
            if (ATTR_SMALL.equals(imageSize)) {
                artistInfo.setSmallImageUrl(chars);
            } else if (ATTR_MEDIUM.equals(imageSize)) {
                artistInfo.setMediumImageUrl(chars);
            } else if (ATTR_LARGE.equals(imageSize)) {
                artistInfo.setLargeImageUrl(chars);
            } else if (ATTR_EXTRA_LARGE.equals(imageSize)) {
                artistInfo.setExtraLargeImageUrl(chars);
            }
        } else if (TAG_LISTENERS.equals(qName)) {
            artistInfo.setListeners(toInt(chars));
        } else if (TAG_PLAY_COUNT.equals(qName)) {
            artistInfo.setPlayCount(toInt(chars));
            parsing = false;
        }
    }
    if (TAG_BIO_SUMMARY.equals(qName)) {
        artistInfo.setBioSummary(stripLicenseAndReadMoreLink(characterData.toString(), artistInfo.getArtist().getName()));
    } else if (TAG_BIO_CONTENT.equals(qName)) {
        artistInfo.setBioContent(stripLicenseAndReadMoreLink(characterData.toString(), artistInfo.getArtist().getName()));
    }
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist) ArtistInfo(com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)

Example 50 with Artist

use of com.github.hakko.musiccabinet.domain.model.music.Artist in project musiccabinet by hakko.

the class ArtistSimilarityHandler method endElement.

@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
    if (state != null) {
        String chars = characterData.toString();
        if (state == NAME) {
            currentArtistRelation.setTarget(new Artist(chars));
        } else if (state == MATCH) {
            currentArtistRelation.setMatch(toFloat(chars));
        }
        state = null;
    }
    if (TAG_ARTIST.equals(qName)) {
        artistRelations.add(currentArtistRelation);
    }
}
Also used : Artist(com.github.hakko.musiccabinet.domain.model.music.Artist)

Aggregations

Artist (com.github.hakko.musiccabinet.domain.model.music.Artist)66 Test (org.junit.Test)33 WebserviceInvocation (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation)19 ArrayList (java.util.ArrayList)13 Album (com.github.hakko.musiccabinet.domain.model.music.Album)11 ArtistInfo (com.github.hakko.musiccabinet.domain.model.music.ArtistInfo)11 ApplicationException (com.github.hakko.musiccabinet.exception.ApplicationException)10 Track (com.github.hakko.musiccabinet.domain.model.music.Track)9 File (com.github.hakko.musiccabinet.domain.model.library.File)8 NameValuePair (org.apache.http.NameValuePair)8 Calltype (com.github.hakko.musiccabinet.domain.model.library.WebserviceInvocation.Calltype)7 Before (org.junit.Before)6 WebserviceHistoryService (com.github.hakko.musiccabinet.service.lastfm.WebserviceHistoryService)5 StringUtil (com.github.hakko.musiccabinet.util.StringUtil)5 UnittestLibraryUtil.getFile (com.github.hakko.musiccabinet.util.UnittestLibraryUtil.getFile)5 WSResponse (com.github.hakko.musiccabinet.ws.lastfm.WSResponse)5 LastFmUser (com.github.hakko.musiccabinet.domain.model.library.LastFmUser)4 Tag (com.github.hakko.musiccabinet.domain.model.music.Tag)4 ResourceUtil (com.github.hakko.musiccabinet.util.ResourceUtil)4 ResultSet (java.sql.ResultSet)4