Search in sources :

Example 16 with Playlist

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);
}
Also used : Playlist(org.libresonic.player.domain.Playlist) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with Playlist

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();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Playlist(org.libresonic.player.domain.Playlist) DateFormat(java.text.DateFormat)

Example 18 with Playlist

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));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) MediaFile(org.libresonic.player.domain.MediaFile) Playlist(org.libresonic.player.domain.Playlist)

Example 19 with Playlist

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());
}
Also used : Playlist(org.libresonic.player.domain.Playlist)

Example 20 with Playlist

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());
        }
    }
}
Also used : Playlist(org.libresonic.player.domain.Playlist) MediaFile(org.libresonic.player.domain.MediaFile) JDOMException(org.jdom.JDOMException)

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