use of org.libresonic.player.domain.Playlist in project libresonic by Libresonic.
the class RESTController method deletePlaylist.
@RequestMapping(value = "/rest/deletePlaylist", method = { RequestMethod.GET, RequestMethod.POST })
public void deletePlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request, true);
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.isWriteAllowed(playlist, username)) {
error(request, response, ErrorCode.NOT_AUTHORIZED, "Permission denied for playlist " + id);
return;
}
playlistService.deletePlaylist(id);
writeEmptyResponse(request, response);
}
use of org.libresonic.player.domain.Playlist in project libresonic by Libresonic.
the class PlaylistService method createEmptyPlaylist.
public List<Playlist> createEmptyPlaylist() {
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();
playlist.setUsername(securityService.getCurrentUsername(request));
playlist.setCreated(now);
playlist.setChanged(now);
playlist.setShared(false);
playlist.setName(dateFormat.format(now));
playlistService.createPlaylist(playlist);
return getReadablePlaylists();
}
use of org.libresonic.player.domain.Playlist in project libresonic by Libresonic.
the class PlaylistService method getPlaylist.
public PlaylistInfo getPlaylist(int id) {
HttpServletRequest request = WebContextFactory.get().getHttpServletRequest();
Playlist playlist = playlistService.getPlaylist(id);
List<MediaFile> files = playlistService.getFilesInPlaylist(id, true);
String username = securityService.getCurrentUsername(request);
mediaFileService.populateStarredDate(files, username);
populateAccess(files, username);
return new PlaylistInfo(playlist, createEntries(files));
}
use of org.libresonic.player.domain.Playlist in project libresonic by Libresonic.
the class PlaylistDao method getReadablePlaylistsForUser.
public List<Playlist> getReadablePlaylistsForUser(String username) {
List<Playlist> result1 = getWritablePlaylistsForUser(username);
List<Playlist> result2 = query("select " + QUERY_COLUMNS + " from playlist where is_public", rowMapper);
List<Playlist> result3 = query("select " + prefix(QUERY_COLUMNS, "playlist") + " from playlist, playlist_user where " + "playlist.id = playlist_user.playlist_id and " + "playlist.username != ? and " + "playlist_user.username = ?", rowMapper, username, username);
// Put in sorted map to avoid duplicates.
SortedMap<Integer, Playlist> map = new TreeMap<Integer, Playlist>();
for (Playlist playlist : result1) {
map.put(playlist.getId(), playlist);
}
for (Playlist playlist : result2) {
map.put(playlist.getId(), playlist);
}
for (Playlist playlist : result3) {
map.put(playlist.getId(), playlist);
}
return new ArrayList<Playlist>(map.values());
}
use of org.libresonic.player.domain.Playlist in project libresonic by Libresonic.
the class PlaylistService method doImportPlaylists.
private void doImportPlaylists() throws Exception {
String playlistFolderPath = settingsService.getPlaylistFolder();
if (playlistFolderPath == null) {
return;
}
File playlistFolder = new File(playlistFolderPath);
if (!playlistFolder.exists()) {
return;
}
List<Playlist> allPlaylists = playlistDao.getAllPlaylists();
for (File file : playlistFolder.listFiles()) {
try {
importPlaylistIfUpdated(file, allPlaylists);
} catch (Exception x) {
LOG.warn("Failed to auto-import playlist " + file + ". " + x.getMessage());
}
}
}
Aggregations