Search in sources :

Example 11 with Playlist

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

the class PlaylistsController method doGet.

@RequestMapping(method = RequestMethod.GET)
public String doGet(HttpServletRequest request, Model model) throws Exception {
    Map<String, Object> map = new HashMap<>();
    User user = securityService.getCurrentUser(request);
    List<Playlist> playlists = playlistService.getReadablePlaylistsForUser(user.getUsername());
    map.put("playlists", playlists);
    model.addAttribute("model", map);
    return "playlists";
}
Also used : Playlist(org.libresonic.player.domain.Playlist) User(org.libresonic.player.domain.User) HashMap(java.util.HashMap) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with Playlist

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

the class RESTController method getPlaylists.

@RequestMapping(value = "/rest/getPlaylists", method = { RequestMethod.GET, RequestMethod.POST })
public void getPlaylists(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    User user = securityService.getCurrentUser(request);
    String authenticatedUsername = user.getUsername();
    String requestedUsername = request.getParameter("username");
    if (requestedUsername == null) {
        requestedUsername = authenticatedUsername;
    } else if (!user.isAdminRole()) {
        error(request, response, ErrorCode.NOT_AUTHORIZED, authenticatedUsername + " is not authorized to get playlists for " + requestedUsername);
        return;
    }
    Playlists result = new Playlists();
    for (Playlist playlist : playlistService.getReadablePlaylistsForUser(requestedUsername)) {
        result.getPlaylist().add(createJaxbPlaylist(new org.libresonic.restapi.Playlist(), playlist));
    }
    Response res = createResponse();
    res.setPlaylists(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Playlist(org.libresonic.player.domain.Playlist) User(org.libresonic.player.domain.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with Playlist

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

the class PodcastController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String url = request.getRequestURL().toString();
    String username = securityService.getCurrentUsername(request);
    List<Playlist> playlists = playlistService.getReadablePlaylistsForUser(username);
    List<Podcast> podcasts = new ArrayList<>();
    for (Playlist playlist : playlists) {
        List<MediaFile> songs = playlistService.getFilesInPlaylist(playlist.getId());
        if (songs.isEmpty()) {
            continue;
        }
        long length = 0L;
        for (MediaFile song : songs) {
            length += song.getFileSize();
        }
        String publishDate = RSS_DATE_FORMAT.format(playlist.getCreated());
        // Resolve content type.
        String suffix = songs.get(0).getFormat();
        String type = StringUtil.getMimeType(suffix);
        String enclosureUrl = url + "/stream?playlist=" + playlist.getId();
        podcasts.add(new Podcast(playlist.getName(), publishDate, enclosureUrl, length, type));
    }
    Map<String, Object> map = new HashMap<>();
    map.put("url", url);
    map.put("podcasts", podcasts);
    return new ModelAndView("podcast", "model", map);
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) ModelAndView(org.springframework.web.servlet.ModelAndView) Playlist(org.libresonic.player.domain.Playlist) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with Playlist

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

the class ExportPlayListController method exportPlaylist.

@RequestMapping(method = { RequestMethod.GET })
public ModelAndView exportPlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception {
    int id = ServletRequestUtils.getRequiredIntParameter(request, "id");
    Playlist playlist = playlistService.getPlaylist(id);
    if (!playlistService.isReadAllowed(playlist, securityService.getCurrentUsername(request))) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return null;
    }
    response.setContentType("application/x-download");
    response.setHeader("Content-Disposition", "attachment; filename=\"" + StringUtil.fileSystemSafe(playlist.getName()) + ".m3u8\"");
    playlistService.exportPlaylist(id, response.getOutputStream());
    return null;
}
Also used : Playlist(org.libresonic.player.domain.Playlist) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with Playlist

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

the class RESTController method createPlaylist.

@RequestMapping(value = "/rest/createPlaylist", method = { RequestMethod.GET, RequestMethod.POST })
public void createPlaylist(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request, true);
    String username = securityService.getCurrentUsername(request);
    Integer playlistId = getIntParameter(request, "playlistId");
    String name = request.getParameter("name");
    if (playlistId == null && name == null) {
        error(request, response, ErrorCode.MISSING_PARAMETER, "Playlist ID or name must be specified.");
        return;
    }
    Playlist playlist;
    if (playlistId != null) {
        playlist = playlistService.getPlaylist(playlistId);
        if (playlist == null) {
            error(request, response, ErrorCode.NOT_FOUND, "Playlist not found: " + playlistId);
            return;
        }
        if (!playlistService.isWriteAllowed(playlist, username)) {
            error(request, response, ErrorCode.NOT_AUTHORIZED, "Permission denied for playlist " + playlistId);
            return;
        }
    } else {
        playlist = new Playlist();
        playlist.setName(name);
        playlist.setCreated(new Date());
        playlist.setChanged(new Date());
        playlist.setShared(false);
        playlist.setUsername(username);
        playlistService.createPlaylist(playlist);
    }
    List<MediaFile> songs = new ArrayList<MediaFile>();
    for (int id : getIntParameters(request, "songId")) {
        MediaFile song = mediaFileService.getMediaFile(id);
        if (song != null) {
            songs.add(song);
        }
    }
    playlistService.setFilesInPlaylist(playlist.getId(), songs);
    writeEmptyResponse(request, response);
}
Also used : Playlist(org.libresonic.player.domain.Playlist) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

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