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