Search in sources :

Example 1 with Playlist

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

the class RESTController method updatePlaylist.

@RequestMapping(value = "/rest/updatePlaylist", method = { RequestMethod.GET, RequestMethod.POST })
public void updatePlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request, true);
    String username = securityService.getCurrentUsername(request);
    int id = getRequiredIntParameter(request, "playlistId");
    Playlist playlist = playlistService.getPlaylist(id);
    if (playlist == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Playlist not found: " + id);
        return;
    }
    if (!playlistService.isWriteAllowed(playlist, username)) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, "Permission denied for playlist " + id);
        return;
    }
    String name = request.getParameter("name");
    if (name != null) {
        playlist.setName(name);
    }
    String comment = request.getParameter("comment");
    if (comment != null) {
        playlist.setComment(comment);
    }
    Boolean shared = getBooleanParameter(request, "public");
    if (shared != null) {
        playlist.setShared(shared);
    }
    playlistService.updatePlaylist(playlist);
    // TODO: Add later
    //            for (String usernameToAdd : ServletRequestUtils.getStringParameters(request, "usernameToAdd")) {
    //                if (securityService.getUserByName(usernameToAdd) != null) {
    //                    playlistService.addPlaylistUser(id, usernameToAdd);
    //                }
    //            }
    //            for (String usernameToRemove : ServletRequestUtils.getStringParameters(request, "usernameToRemove")) {
    //                if (securityService.getUserByName(usernameToRemove) != null) {
    //                    playlistService.deletePlaylistUser(id, usernameToRemove);
    //                }
    //            }
    List<MediaFile> songs = playlistService.getFilesInPlaylist(id);
    boolean songsChanged = false;
    SortedSet<Integer> tmp = new TreeSet<Integer>();
    for (int songIndexToRemove : getIntParameters(request, "songIndexToRemove")) {
        tmp.add(songIndexToRemove);
    }
    List<Integer> songIndexesToRemove = new ArrayList<Integer>(tmp);
    Collections.reverse(songIndexesToRemove);
    for (Integer songIndexToRemove : songIndexesToRemove) {
        songs.remove(songIndexToRemove.intValue());
        songsChanged = true;
    }
    for (int songToAdd : getIntParameters(request, "songIdToAdd")) {
        MediaFile song = mediaFileService.getMediaFile(songToAdd);
        if (song != null) {
            songs.add(song);
            songsChanged = true;
        }
    }
    if (songsChanged) {
        playlistService.setFilesInPlaylist(id, songs);
    }
    writeEmptyResponse(request, response);
}
Also used : Playlist(org.libresonic.player.domain.Playlist) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with Playlist

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

the class RESTController method getPlaylist.

@RequestMapping(value = "/rest/getPlaylist", method = { RequestMethod.GET, RequestMethod.POST })
public void getPlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    int id = getRequiredIntParameter(request, "id");
    Playlist playlist = playlistService.getPlaylist(id);
    if (playlist == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Playlist not found: " + id);
        return;
    }
    if (!playlistService.isReadAllowed(playlist, username)) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, "Permission denied for playlist " + id);
        return;
    }
    PlaylistWithSongs result = createJaxbPlaylist(new PlaylistWithSongs(), playlist);
    for (MediaFile mediaFile : playlistService.getFilesInPlaylist(id)) {
        if (securityService.isFolderAccessAllowed(mediaFile, username)) {
            result.getEntry().add(createJaxbChild(player, mediaFile, username));
        }
    }
    Response res = createResponse();
    res.setPlaylist(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Playlist(org.libresonic.player.domain.Playlist) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with Playlist

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

the class PlaylistService method updatePlaylist.

public PlaylistInfo updatePlaylist(int id, String name, String comment, boolean shared) {
    Playlist playlist = playlistService.getPlaylist(id);
    playlist.setName(name);
    playlist.setComment(comment);
    playlist.setShared(shared);
    playlistService.updatePlaylist(playlist);
    return getPlaylist(id);
}
Also used : Playlist(org.libresonic.player.domain.Playlist)

Example 4 with Playlist

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

the class PlaylistService method createPlaylistForStarredSongs.

public int createPlaylistForStarredSongs() {
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
    Locale locale = localeResolver.resolveLocale(request);
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, locale);
    Date now = new Date();
    Playlist playlist = new Playlist();
    String username = securityService.getCurrentUsername(request);
    playlist.setUsername(username);
    playlist.setCreated(now);
    playlist.setChanged(now);
    playlist.setShared(false);
    ResourceBundle bundle = ResourceBundle.getBundle("org.libresonic.player.i18n.ResourceBundle", locale);
    playlist.setName(bundle.getString("top.starred") + " " + dateFormat.format(now));
    playlistService.createPlaylist(playlist);
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<MediaFile> songs = mediaFileDao.getStarredFiles(0, Integer.MAX_VALUE, username, musicFolders);
    playlistService.setFilesInPlaylist(playlist.getId(), songs);
    return playlist.getId();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaFile(org.libresonic.player.domain.MediaFile) Playlist(org.libresonic.player.domain.Playlist) DateFormat(java.text.DateFormat) MusicFolder(org.libresonic.player.domain.MusicFolder)

Example 5 with Playlist

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

the class PlaylistService method createPlaylistForPlayQueue.

public int createPlaylistForPlayQueue() {
    HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
    HttpServletResponse response = WebContextFactory.get().getHttpServletResponse();
    Player player = playerService.getPlayer(request, response);
    Locale locale = localeResolver.resolveLocale(request);
    DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, locale);
    Date now = new Date();
    Playlist playlist = new Playlist();
    playlist.setUsername(securityService.getCurrentUsername(request));
    playlist.setCreated(now);
    playlist.setChanged(now);
    playlist.setShared(false);
    playlist.setName(dateFormat.format(now));
    playlistService.createPlaylist(playlist);
    playlistService.setFilesInPlaylist(playlist.getId(), player.getPlayQueue().getFiles());
    return playlist.getId();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Player(org.libresonic.player.domain.Player) Playlist(org.libresonic.player.domain.Playlist) DateFormat(java.text.DateFormat) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Aggregations

Playlist (org.libresonic.player.domain.Playlist)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 MediaFile (org.libresonic.player.domain.MediaFile)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 DateFormat (java.text.DateFormat)3 HashMap (java.util.HashMap)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 User (org.libresonic.player.domain.User)3 JDOMException (org.jdom.JDOMException)2 Player (org.libresonic.player.domain.Player)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1 FileItem (org.apache.commons.fileupload.FileItem)1 FileItemFactory (org.apache.commons.fileupload.FileItemFactory)1 DiskFileItemFactory (org.apache.commons.fileupload.disk.DiskFileItemFactory)1 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)1 MusicFolder (org.libresonic.player.domain.MusicFolder)1 UserSettings (org.libresonic.player.domain.UserSettings)1 RedirectView (org.springframework.web.servlet.view.RedirectView)1