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