Search in sources :

Example 11 with MusicFolder

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

the class RESTController method createShare.

@RequestMapping(value = "/rest/createShare", method = { RequestMethod.GET, RequestMethod.POST })
public void createShare(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    User user = securityService.getCurrentUser(request);
    if (!user.isShareRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, user.getUsername() + " is not authorized to share media.");
        return;
    }
    List<MediaFile> files = new ArrayList<MediaFile>();
    for (int id : getRequiredIntParameters(request, "id")) {
        files.add(mediaFileService.getMediaFile(id));
    }
    Share share = shareService.createShare(request, files);
    share.setDescription(request.getParameter("description"));
    long expires = getLongParameter(request, "expires", 0L);
    if (expires != 0) {
        share.setExpires(new Date(expires));
    }
    shareService.updateShare(share);
    Shares result = new Shares();
    org.libresonic.restapi.Share s = createJaxbShare(request, share);
    result.getShare().add(s);
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    for (MediaFile mediaFile : shareService.getSharedFiles(share.getId(), musicFolders)) {
        s.getEntry().add(createJaxbChild(player, mediaFile, username));
    }
    Response res = createResponse();
    res.setShares(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : User(org.libresonic.player.domain.User) org.libresonic.restapi(org.libresonic.restapi) MusicFolder(org.libresonic.player.domain.MusicFolder) HttpServletResponse(javax.servlet.http.HttpServletResponse) Share(org.libresonic.player.domain.Share) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with MusicFolder

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

the class RESTController method search.

@RequestMapping(value = "/rest/search", method = { RequestMethod.GET, RequestMethod.POST })
public void search(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    String any = request.getParameter("any");
    String artist = request.getParameter("artist");
    String album = request.getParameter("album");
    String title = request.getParameter("title");
    StringBuilder query = new StringBuilder();
    if (any != null) {
        query.append(any).append(" ");
    }
    if (artist != null) {
        query.append(artist).append(" ");
    }
    if (album != null) {
        query.append(album).append(" ");
    }
    if (title != null) {
        query.append(title);
    }
    SearchCriteria criteria = new SearchCriteria();
    criteria.setQuery(query.toString().trim());
    criteria.setCount(getIntParameter(request, "count", 20));
    criteria.setOffset(getIntParameter(request, "offset", 0));
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    SearchResult result = searchService.search(criteria, musicFolders, SearchService.IndexType.SONG);
    org.libresonic.restapi.SearchResult searchResult = new org.libresonic.restapi.SearchResult();
    searchResult.setOffset(result.getOffset());
    searchResult.setTotalHits(result.getTotalHits());
    for (MediaFile mediaFile : result.getMediaFiles()) {
        searchResult.getMatch().add(createJaxbChild(player, mediaFile, username));
    }
    Response res = createResponse();
    res.setSearchResult(searchResult);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : SearchResult(org.libresonic.player.domain.SearchResult) org.libresonic.restapi(org.libresonic.restapi) MusicFolder(org.libresonic.player.domain.MusicFolder) HttpServletResponse(javax.servlet.http.HttpServletResponse) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with MusicFolder

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

the class RESTController method getSongsByGenre.

@RequestMapping(value = "/rest/getSongsByGenre", method = { RequestMethod.GET, RequestMethod.POST })
public void getSongsByGenre(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    Songs songs = new Songs();
    String genre = getRequiredStringParameter(request, "genre");
    int offset = getIntParameter(request, "offset", 0);
    int count = getIntParameter(request, "count", 10);
    count = Math.max(0, Math.min(count, 500));
    Integer musicFolderId = getIntParameter(request, "musicFolderId");
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username, musicFolderId);
    for (MediaFile mediaFile : mediaFileDao.getSongsByGenre(genre, offset, count, musicFolders)) {
        songs.getSong().add(createJaxbChild(player, mediaFile, username));
    }
    Response res = createResponse();
    res.setSongsByGenre(songs);
    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 14 with MusicFolder

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

the class RESTController method getRandomSongs.

@RequestMapping(value = "/rest/getRandomSongs", method = { RequestMethod.GET, RequestMethod.POST })
public void getRandomSongs(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", 10);
    size = Math.max(0, Math.min(size, 500));
    String genre = getStringParameter(request, "genre");
    Integer fromYear = getIntParameter(request, "fromYear");
    Integer toYear = getIntParameter(request, "toYear");
    Integer musicFolderId = getIntParameter(request, "musicFolderId");
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username, musicFolderId);
    RandomSearchCriteria criteria = new RandomSearchCriteria(size, genre, fromYear, toYear, musicFolders);
    Songs result = new Songs();
    for (MediaFile mediaFile : searchService.getRandomSongs(criteria)) {
        result.getSong().add(createJaxbChild(player, mediaFile, username));
    }
    Response res = createResponse();
    res.setRandomSongs(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 15 with MusicFolder

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

the class RESTController method getTopSongs.

@RequestMapping(value = "/rest/getTopSongs", method = { RequestMethod.GET, RequestMethod.POST })
public void getTopSongs(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = securityService.getCurrentUsername(request);
    String artist = getRequiredStringParameter(request, "artist");
    int count = getIntParameter(request, "count", 50);
    TopSongs result = new TopSongs();
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<MediaFile> topSongs = lastFmService.getTopSongs(artist, count, musicFolders);
    Player player = playerService.getPlayer(request, response);
    for (MediaFile topSong : topSongs) {
        result.getSong().add(createJaxbChild(player, topSong, username));
    }
    Response res = createResponse();
    res.setTopSongs(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