Search in sources :

Example 21 with Playlist

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

the class SonosService method renameContainer.

@Override
public RenameContainerResult renameContainer(String id, String title) {
    if (id.startsWith(ID_PLAYLIST_PREFIX)) {
        int playlistId = Integer.parseInt(id.replace(ID_PLAYLIST_PREFIX, ""));
        Playlist playlist = playlistService.getPlaylist(playlistId);
        if (playlist != null && playlist.getUsername().equals(getUsername())) {
            playlist.setName(title);
            playlistService.updatePlaylist(playlist);
        }
    }
    return new RenameContainerResult();
}
Also used : Playlist(org.libresonic.player.domain.Playlist)

Example 22 with Playlist

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

the class SonosService method reorderContainer.

@Override
public ReorderContainerResult reorderContainer(String id, String from, int to, String updateId) {
    if (id.startsWith(ID_PLAYLIST_PREFIX)) {
        int playlistId = Integer.parseInt(id.replace(ID_PLAYLIST_PREFIX, ""));
        Playlist playlist = playlistService.getPlaylist(playlistId);
        if (playlist != null && playlist.getUsername().equals(getUsername())) {
            SortedMap<Integer, MediaFile> indexToSong = new ConcurrentSkipListMap<Integer, MediaFile>();
            List<MediaFile> songs = playlistService.getFilesInPlaylist(playlistId);
            for (int i = 0; i < songs.size(); i++) {
                indexToSong.put(i, songs.get(i));
            }
            List<MediaFile> movedSongs = new ArrayList<MediaFile>();
            for (Integer i : parsePlaylistIndices(from)) {
                movedSongs.add(indexToSong.remove(i));
            }
            List<MediaFile> updatedSongs = new ArrayList<MediaFile>();
            updatedSongs.addAll(indexToSong.headMap(to).values());
            updatedSongs.addAll(movedSongs);
            updatedSongs.addAll(indexToSong.tailMap(to).values());
            playlistService.setFilesInPlaylist(playlistId, updatedSongs);
        }
    }
    return new ReorderContainerResult();
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) Playlist(org.libresonic.player.domain.Playlist) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 23 with Playlist

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

the class SonosService method removeFromContainer.

@Override
public RemoveFromContainerResult removeFromContainer(String id, String indices, String updateId) {
    if (id.startsWith(ID_PLAYLIST_PREFIX)) {
        int playlistId = Integer.parseInt(id.replace(ID_PLAYLIST_PREFIX, ""));
        Playlist playlist = playlistService.getPlaylist(playlistId);
        if (playlist != null && playlist.getUsername().equals(getUsername())) {
            SortedSet<Integer> indicesToRemove = parsePlaylistIndices(indices);
            List<MediaFile> songs = playlistService.getFilesInPlaylist(playlistId);
            List<MediaFile> updatedSongs = new ArrayList<MediaFile>();
            for (int i = 0; i < songs.size(); i++) {
                if (!indicesToRemove.contains(i)) {
                    updatedSongs.add(songs.get(i));
                }
            }
            playlistService.setFilesInPlaylist(playlistId, updatedSongs);
        }
    }
    return new RemoveFromContainerResult();
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) Playlist(org.libresonic.player.domain.Playlist)

Example 24 with Playlist

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

the class SonosService method deleteContainer.

@Override
public DeleteContainerResult deleteContainer(String id) {
    if (id.startsWith(ID_PLAYLIST_PREFIX)) {
        int playlistId = Integer.parseInt(id.replace(ID_PLAYLIST_PREFIX, ""));
        Playlist playlist = playlistService.getPlaylist(playlistId);
        if (playlist != null && playlist.getUsername().equals(getUsername())) {
            playlistService.deletePlaylist(playlistId);
        }
    }
    return new DeleteContainerResult();
}
Also used : Playlist(org.libresonic.player.domain.Playlist)

Example 25 with Playlist

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

the class SonosService method createContainer.

@Override
public CreateContainerResult createContainer(String containerType, String title, String parentId, String seedId) {
    Date now = new Date();
    Playlist playlist = new Playlist();
    playlist.setName(title);
    playlist.setUsername(getUsername());
    playlist.setCreated(now);
    playlist.setChanged(now);
    playlist.setShared(false);
    playlistService.createPlaylist(playlist);
    CreateContainerResult result = new CreateContainerResult();
    result.setId(ID_PLAYLIST_PREFIX + playlist.getId());
    addItemToPlaylist(playlist.getId(), seedId, -1);
    return result;
}
Also used : Playlist(org.libresonic.player.domain.Playlist)

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