use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.
the class RESTController method getSimilarSongs.
@RequestMapping(value = "/rest/getSimilarSongs", method = { RequestMethod.GET, RequestMethod.POST })
public void getSimilarSongs(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
String username = securityService.getCurrentUsername(request);
int id = getRequiredIntParameter(request, "id");
int count = getIntParameter(request, "count", 50);
SimilarSongs result = new SimilarSongs();
MediaFile mediaFile = mediaFileService.getMediaFile(id);
if (mediaFile == null) {
error(request, response, ErrorCode.NOT_FOUND, "Media file not found.");
return;
}
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
List<MediaFile> similarSongs = lastFmService.getSimilarSongs(mediaFile, count, musicFolders);
Player player = playerService.getPlayer(request, response);
for (MediaFile similarSong : similarSongs) {
result.getSong().add(createJaxbChild(player, similarSong, username));
}
Response res = createResponse();
res.setSimilarSongs(result);
jaxbWriter.writeResponse(request, response, res);
}
use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.
the class RESTController method getAlbumList.
@RequestMapping(value = "/rest/getAlbumList", method = { RequestMethod.GET, RequestMethod.POST })
public void getAlbumList(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
Player player = playerService.getPlayer(request, response);
String username = securityService.getCurrentUsername(request);
int size = getIntParameter(request, "size", 10);
int offset = getIntParameter(request, "offset", 0);
Integer musicFolderId = getIntParameter(request, "musicFolderId");
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username, musicFolderId);
size = Math.max(0, Math.min(size, 500));
String type = getRequiredStringParameter(request, "type");
List<MediaFile> albums;
if ("highest".equals(type)) {
albums = ratingService.getHighestRatedAlbums(offset, size, musicFolders);
} else if ("frequent".equals(type)) {
albums = mediaFileService.getMostFrequentlyPlayedAlbums(offset, size, musicFolders);
} else if ("recent".equals(type)) {
albums = mediaFileService.getMostRecentlyPlayedAlbums(offset, size, musicFolders);
} else if ("newest".equals(type)) {
albums = mediaFileService.getNewestAlbums(offset, size, musicFolders);
} else if ("starred".equals(type)) {
albums = mediaFileService.getStarredAlbums(offset, size, username, musicFolders);
} else if ("alphabeticalByArtist".equals(type)) {
albums = mediaFileService.getAlphabeticalAlbums(offset, size, true, musicFolders);
} else if ("alphabeticalByName".equals(type)) {
albums = mediaFileService.getAlphabeticalAlbums(offset, size, false, musicFolders);
} else if ("byGenre".equals(type)) {
albums = mediaFileService.getAlbumsByGenre(offset, size, getRequiredStringParameter(request, "genre"), musicFolders);
} else if ("byYear".equals(type)) {
albums = mediaFileService.getAlbumsByYear(offset, size, getRequiredIntParameter(request, "fromYear"), getRequiredIntParameter(request, "toYear"), musicFolders);
} else if ("random".equals(type)) {
albums = searchService.getRandomAlbums(size, musicFolders);
} else {
throw new Exception("Invalid list type: " + type);
}
AlbumList result = new AlbumList();
for (MediaFile album : albums) {
result.getAlbum().add(createJaxbChild(player, album, username));
}
Response res = createResponse();
res.setAlbumList(result);
jaxbWriter.writeResponse(request, response, res);
}
use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.
the class RESTController method createJaxbUser.
private org.libresonic.restapi.User createJaxbUser(User user) {
UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
org.libresonic.restapi.User result = new org.libresonic.restapi.User();
result.setUsername(user.getUsername());
result.setEmail(user.getEmail());
result.setScrobblingEnabled(userSettings.isLastFmEnabled());
result.setAdminRole(user.isAdminRole());
result.setSettingsRole(user.isSettingsRole());
result.setDownloadRole(user.isDownloadRole());
result.setUploadRole(user.isUploadRole());
// Since 1.8.0
result.setPlaylistRole(true);
result.setCoverArtRole(user.isCoverArtRole());
result.setCommentRole(user.isCommentRole());
result.setPodcastRole(user.isPodcastRole());
result.setStreamRole(user.isStreamRole());
result.setJukeboxRole(user.isJukeboxRole());
result.setShareRole(user.isShareRole());
TranscodeScheme transcodeScheme = userSettings.getTranscodeScheme();
if (transcodeScheme != null && transcodeScheme != TranscodeScheme.OFF) {
result.setMaxBitRate(transcodeScheme.getMaxBitRate());
}
List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername());
for (MusicFolder musicFolder : musicFolders) {
result.getFolder().add(musicFolder.getId());
}
return result;
}
use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.
the class MusicFolderSettingsController method onSubmit.
@RequestMapping(method = RequestMethod.POST)
protected String onSubmit(@ModelAttribute("command") MusicFolderSettingsCommand command, RedirectAttributes redirectAttributes) throws Exception {
for (MusicFolderSettingsCommand.MusicFolderInfo musicFolderInfo : command.getMusicFolders()) {
if (musicFolderInfo.isDelete()) {
settingsService.deleteMusicFolder(musicFolderInfo.getId());
} else {
MusicFolder musicFolder = musicFolderInfo.toMusicFolder();
if (musicFolder != null) {
settingsService.updateMusicFolder(musicFolder);
}
}
}
MusicFolder newMusicFolder = command.getNewMusicFolder().toMusicFolder();
if (newMusicFolder != null) {
settingsService.createMusicFolder(newMusicFolder);
}
settingsService.setIndexCreationInterval(Integer.parseInt(command.getInterval()));
settingsService.setIndexCreationHour(Integer.parseInt(command.getHour()));
settingsService.setFastCacheEnabled(command.isFastCache());
settingsService.setOrganizeByFolderStructure(command.isOrganizeByFolderStructure());
settingsService.save();
redirectAttributes.addFlashAttribute("settings_toast", true);
redirectAttributes.addFlashAttribute("settings_reload", true);
mediaScannerService.schedule();
return "redirect:musicFolderSettings.view";
}
use of org.libresonic.player.domain.MusicFolder in project libresonic by Libresonic.
the class RESTController method getMusicFolders.
@RequestMapping(value = "/rest/getMusicFolders", method = { RequestMethod.GET, RequestMethod.POST })
public void getMusicFolders(HttpServletRequest request, HttpServletResponse response) throws Exception {
request = wrapRequest(request);
MusicFolders musicFolders = new MusicFolders();
String username = securityService.getCurrentUsername(request);
for (MusicFolder musicFolder : settingsService.getMusicFoldersForUser(username)) {
org.libresonic.restapi.MusicFolder mf = new org.libresonic.restapi.MusicFolder();
mf.setId(musicFolder.getId());
mf.setName(musicFolder.getName());
musicFolders.getMusicFolder().add(mf);
}
Response res = createResponse();
res.setMusicFolders(musicFolders);
jaxbWriter.writeResponse(request, response, res);
}
Aggregations