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();
}
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();
}
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();
}
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();
}
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;
}
Aggregations