Search in sources :

Example 6 with Artist

use of org.libresonic.player.domain.Artist in project libresonic by Libresonic.

the class RESTController method search3.

@RequestMapping(value = "/rest/search3", method = { RequestMethod.GET, RequestMethod.POST })
public void search3(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    Integer musicFolderId = getIntParameter(request, "musicFolderId");
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username, musicFolderId);
    SearchResult3 searchResult = new SearchResult3();
    String query = request.getParameter("query");
    SearchCriteria criteria = new SearchCriteria();
    criteria.setQuery(StringUtils.trimToEmpty(query));
    criteria.setCount(getIntParameter(request, "artistCount", 20));
    criteria.setOffset(getIntParameter(request, "artistOffset", 0));
    SearchResult result = searchService.search(criteria, musicFolders, SearchService.IndexType.ARTIST_ID3);
    for (Artist artist : result.getArtists()) {
        searchResult.getArtist().add(createJaxbArtist(new ArtistID3(), artist, username));
    }
    criteria.setCount(getIntParameter(request, "albumCount", 20));
    criteria.setOffset(getIntParameter(request, "albumOffset", 0));
    result = searchService.search(criteria, musicFolders, SearchService.IndexType.ALBUM_ID3);
    for (Album album : result.getAlbums()) {
        searchResult.getAlbum().add(createJaxbAlbum(new AlbumID3(), album, username));
    }
    criteria.setCount(getIntParameter(request, "songCount", 20));
    criteria.setOffset(getIntParameter(request, "songOffset", 0));
    result = searchService.search(criteria, musicFolders, SearchService.IndexType.SONG);
    for (MediaFile song : result.getMediaFiles()) {
        searchResult.getSong().add(createJaxbChild(player, song, username));
    }
    Response res = createResponse();
    res.setSearchResult3(searchResult);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : Artist(org.libresonic.player.domain.Artist) SearchResult(org.libresonic.player.domain.SearchResult) MusicFolder(org.libresonic.player.domain.MusicFolder) HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with Artist

use of org.libresonic.player.domain.Artist in project libresonic by Libresonic.

the class RESTController method getArtistInfo2.

@RequestMapping(value = "/rest/getArtistInfo2", method = { RequestMethod.GET, RequestMethod.POST })
public void getArtistInfo2(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = securityService.getCurrentUsername(request);
    int id = getRequiredIntParameter(request, "id");
    int count = getIntParameter(request, "count", 20);
    boolean includeNotPresent = ServletRequestUtils.getBooleanParameter(request, "includeNotPresent", false);
    ArtistInfo2 result = new ArtistInfo2();
    Artist artist = artistDao.getArtist(id);
    if (artist == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Artist not found.");
        return;
    }
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<Artist> similarArtists = lastFmService.getSimilarArtists(artist, count, includeNotPresent, musicFolders);
    for (Artist similarArtist : similarArtists) {
        result.getSimilarArtist().add(createJaxbArtist(new ArtistID3(), similarArtist, username));
    }
    ArtistBio artistBio = lastFmService.getArtistBio(artist);
    if (artistBio != null) {
        result.setBiography(artistBio.getBiography());
        result.setMusicBrainzId(artistBio.getMusicBrainzId());
        result.setLastFmUrl(artistBio.getLastFmUrl());
        result.setSmallImageUrl(artistBio.getSmallImageUrl());
        result.setMediumImageUrl(artistBio.getMediumImageUrl());
        result.setLargeImageUrl(artistBio.getLargeImageUrl());
    }
    Response res = createResponse();
    res.setArtistInfo2(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : Artist(org.libresonic.player.domain.Artist) HttpServletResponse(javax.servlet.http.HttpServletResponse) MusicFolder(org.libresonic.player.domain.MusicFolder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with Artist

use of org.libresonic.player.domain.Artist in project libresonic by Libresonic.

the class RESTController method createJaxbAlbum.

private <T extends AlbumID3> T createJaxbAlbum(T jaxbAlbum, Album album, String username) {
    jaxbAlbum.setId(String.valueOf(album.getId()));
    jaxbAlbum.setName(album.getName());
    if (album.getArtist() != null) {
        jaxbAlbum.setArtist(album.getArtist());
        Artist artist = artistDao.getArtist(album.getArtist());
        if (artist != null) {
            jaxbAlbum.setArtistId(String.valueOf(artist.getId()));
        }
    }
    if (album.getCoverArtPath() != null) {
        jaxbAlbum.setCoverArt(CoverArtController.ALBUM_COVERART_PREFIX + album.getId());
    }
    jaxbAlbum.setSongCount(album.getSongCount());
    jaxbAlbum.setDuration(album.getDurationSeconds());
    jaxbAlbum.setCreated(jaxbWriter.convertDate(album.getCreated()));
    jaxbAlbum.setStarred(jaxbWriter.convertDate(albumDao.getAlbumStarredDate(album.getId(), username)));
    jaxbAlbum.setYear(album.getYear());
    jaxbAlbum.setGenre(album.getGenre());
    return jaxbAlbum;
}
Also used : Artist(org.libresonic.player.domain.Artist)

Example 9 with Artist

use of org.libresonic.player.domain.Artist in project libresonic by Libresonic.

the class RESTController method getSimilarSongs2.

@RequestMapping(value = "/rest/getSimilarSongs2", method = { RequestMethod.GET, RequestMethod.POST })
public void getSimilarSongs2(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = securityService.getCurrentUsername(request);
    int id = getRequiredIntParameter(request, "id");
    int count = getIntParameter(request, "count", 50);
    SimilarSongs2 result = new SimilarSongs2();
    Artist artist = artistDao.getArtist(id);
    if (artist == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Artist not found.");
        return;
    }
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<MediaFile> similarSongs = lastFmService.getSimilarSongs(artist, count, musicFolders);
    Player player = playerService.getPlayer(request, response);
    for (MediaFile similarSong : similarSongs) {
        result.getSong().add(createJaxbChild(player, similarSong, username));
    }
    Response res = createResponse();
    res.setSimilarSongs2(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : Artist(org.libresonic.player.domain.Artist) HttpServletResponse(javax.servlet.http.HttpServletResponse) MusicFolder(org.libresonic.player.domain.MusicFolder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with Artist

use of org.libresonic.player.domain.Artist in project libresonic by Libresonic.

the class RESTController method getStarred2.

@RequestMapping(value = "/rest/getStarred2", method = { RequestMethod.GET, RequestMethod.POST })
public void getStarred2(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    Integer musicFolderId = getIntParameter(request, "musicFolderId");
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username, musicFolderId);
    Starred2 result = new Starred2();
    for (Artist artist : artistDao.getStarredArtists(0, Integer.MAX_VALUE, username, musicFolders)) {
        result.getArtist().add(createJaxbArtist(new ArtistID3(), artist, username));
    }
    for (Album album : albumDao.getStarredAlbums(0, Integer.MAX_VALUE, username, musicFolders)) {
        result.getAlbum().add(createJaxbAlbum(new AlbumID3(), album, username));
    }
    for (MediaFile song : mediaFileDao.getStarredFiles(0, Integer.MAX_VALUE, username, musicFolders)) {
        result.getSong().add(createJaxbChild(player, song, username));
    }
    Response res = createResponse();
    res.setStarred2(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : Artist(org.libresonic.player.domain.Artist) HttpServletResponse(javax.servlet.http.HttpServletResponse) MusicFolder(org.libresonic.player.domain.MusicFolder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Artist (org.libresonic.player.domain.Artist)11 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 MusicFolder (org.libresonic.player.domain.MusicFolder)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 ConsoleReporter (com.codahale.metrics.ConsoleReporter)1 Timer (com.codahale.metrics.Timer)1 Test (org.junit.Test)1 Album (org.libresonic.player.domain.Album)1 Bookmark (org.libresonic.player.domain.Bookmark)1 MediaFile (org.libresonic.player.domain.MediaFile)1 SearchResult (org.libresonic.player.domain.SearchResult)1 org.libresonic.restapi (org.libresonic.restapi)1