Search in sources :

Example 21 with MusicFolder

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

the class RESTController method getStarred.

@RequestMapping(value = "/rest/getStarred", method = { RequestMethod.GET, RequestMethod.POST })
public void getStarred(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);
    Starred result = new Starred();
    for (MediaFile artist : mediaFileDao.getStarredDirectories(0, Integer.MAX_VALUE, username, musicFolders)) {
        result.getArtist().add(createJaxbArtist(artist, username));
    }
    for (MediaFile album : mediaFileDao.getStarredAlbums(0, Integer.MAX_VALUE, username, musicFolders)) {
        result.getAlbum().add(createJaxbChild(player, album, username));
    }
    for (MediaFile song : mediaFileDao.getStarredFiles(0, Integer.MAX_VALUE, username, musicFolders)) {
        result.getSong().add(createJaxbChild(player, song, username));
    }
    Response res = createResponse();
    res.setStarred(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) MusicFolder(org.libresonic.player.domain.MusicFolder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 22 with MusicFolder

use of org.libresonic.player.domain.MusicFolder 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 23 with MusicFolder

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

the class RESTController method getArtistInfo.

@RequestMapping(value = "/rest/getArtistInfo", method = { RequestMethod.GET, RequestMethod.POST })
public void getArtistInfo(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);
    ArtistInfo result = new ArtistInfo();
    MediaFile mediaFile = mediaFileService.getMediaFile(id);
    if (mediaFile == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Media file not found.");
        return;
    }
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<MediaFile> similarArtists = lastFmService.getSimilarArtists(mediaFile, count, includeNotPresent, musicFolders);
    for (MediaFile similarArtist : similarArtists) {
        result.getSimilarArtist().add(createJaxbArtist(similarArtist, username));
    }
    ArtistBio artistBio = lastFmService.getArtistBio(mediaFile);
    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.setArtistInfo(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) MusicFolder(org.libresonic.player.domain.MusicFolder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with MusicFolder

use of org.libresonic.player.domain.MusicFolder 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 25 with MusicFolder

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

the class RESTController method getVideos.

@RequestMapping(value = "/rest/getVideos", method = { RequestMethod.GET, RequestMethod.POST })
public void getVideos(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    int size = getIntParameter(request, "size", Integer.MAX_VALUE);
    int offset = getIntParameter(request, "offset", 0);
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    Videos result = new Videos();
    for (MediaFile mediaFile : mediaFileDao.getVideos(size, offset, musicFolders)) {
        result.getVideo().add(createJaxbChild(player, mediaFile, username));
    }
    Response res = createResponse();
    res.setVideos(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) MusicFolder(org.libresonic.player.domain.MusicFolder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MusicFolder (org.libresonic.player.domain.MusicFolder)37 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 HttpServletResponse (javax.servlet.http.HttpServletResponse)21 Artist (org.libresonic.player.domain.Artist)7 File (java.io.File)6 org.libresonic.restapi (org.libresonic.restapi)6 Date (java.util.Date)5 MediaFile (org.libresonic.player.domain.MediaFile)5 User (org.libresonic.player.domain.User)5 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 SearchResult (org.libresonic.player.domain.SearchResult)3 Share (org.libresonic.player.domain.Share)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 FileOutputStream (java.io.FileOutputStream)1 DateFormat (java.text.DateFormat)1 HashMap (java.util.HashMap)1 MusicFolderSettingsCommand (org.libresonic.player.command.MusicFolderSettingsCommand)1 Player (org.libresonic.player.domain.Player)1