Search in sources :

Example 16 with MusicFolder

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

Example 17 with MusicFolder

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

Example 18 with MusicFolder

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

Example 19 with MusicFolder

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

Example 20 with MusicFolder

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);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) org.libresonic.restapi(org.libresonic.restapi) MusicFolder(org.libresonic.player.domain.MusicFolder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MusicFolder (org.libresonic.player.domain.MusicFolder)37 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 HttpServletResponse (javax.servlet.http.HttpServletResponse)21 Artist (org.libresonic.player.domain.Artist)7 File (java.io.File)6 org.libresonic.restapi (org.libresonic.restapi)6 Date (java.util.Date)5 MediaFile (org.libresonic.player.domain.MediaFile)5 User (org.libresonic.player.domain.User)5 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 SearchResult (org.libresonic.player.domain.SearchResult)3 Share (org.libresonic.player.domain.Share)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 FileOutputStream (java.io.FileOutputStream)1 DateFormat (java.text.DateFormat)1 HashMap (java.util.HashMap)1 MusicFolderSettingsCommand (org.libresonic.player.command.MusicFolderSettingsCommand)1 Player (org.libresonic.player.domain.Player)1