Search in sources :

Example 26 with MusicFolder

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

the class MusicFolderDaoTestCase method testCreateMusicFolder.

@Test
public void testCreateMusicFolder() {
    MusicFolder musicFolder = new MusicFolder(new File("path"), "name", true, new Date());
    musicFolderDao.createMusicFolder(musicFolder);
    MusicFolder newMusicFolder = musicFolderDao.getAllMusicFolders().get(0);
    assertMusicFolderEquals(musicFolder, newMusicFolder);
}
Also used : MusicFolder(org.libresonic.player.domain.MusicFolder) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 27 with MusicFolder

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

the class MusicFolderDaoTestCase method testDeleteMusicFolder.

@Test
public void testDeleteMusicFolder() {
    assertEquals("Wrong number of music folders.", 0, musicFolderDao.getAllMusicFolders().size());
    musicFolderDao.createMusicFolder(new MusicFolder(new File("path"), "name", true, new Date()));
    assertEquals("Wrong number of music folders.", 1, musicFolderDao.getAllMusicFolders().size());
    musicFolderDao.createMusicFolder(new MusicFolder(new File("path"), "name", true, new Date()));
    assertEquals("Wrong number of music folders.", 2, musicFolderDao.getAllMusicFolders().size());
    musicFolderDao.deleteMusicFolder(musicFolderDao.getAllMusicFolders().get(0).getId());
    assertEquals("Wrong number of music folders.", 1, musicFolderDao.getAllMusicFolders().size());
    musicFolderDao.deleteMusicFolder(musicFolderDao.getAllMusicFolders().get(0).getId());
    assertEquals("Wrong number of music folders.", 0, musicFolderDao.getAllMusicFolders().size());
}
Also used : MusicFolder(org.libresonic.player.domain.MusicFolder) File(java.io.File) Date(java.util.Date) Test(org.junit.Test)

Example 28 with MusicFolder

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

the class RESTController method getSimilarSongs2.

@RequestMapping(value = "/rest/getSimilarSongs2", method = { RequestMethod.GET, RequestMethod.POST })
public void getSimilarSongs2(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);
    SimilarSongs2 result = new SimilarSongs2();
    Artist artist = artistDao.getArtist(id);
    if (artist == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Artist not found.");
        return;
    }
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    List<MediaFile> similarSongs = lastFmService.getSimilarSongs(artist, count, musicFolders);
    Player player = playerService.getPlayer(request, response);
    for (MediaFile similarSong : similarSongs) {
        result.getSong().add(createJaxbChild(player, similarSong, username));
    }
    Response res = createResponse();
    res.setSimilarSongs2(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : Artist(org.libresonic.player.domain.Artist) HttpServletResponse(javax.servlet.http.HttpServletResponse) MusicFolder(org.libresonic.player.domain.MusicFolder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with MusicFolder

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

the class RESTController method getShares.

@RequestMapping(value = "/rest/getShares", method = { RequestMethod.GET, RequestMethod.POST })
public void getShares(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    User user = securityService.getCurrentUser(request);
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    Shares result = new Shares();
    for (Share share : shareService.getSharesForUser(user)) {
        org.libresonic.restapi.Share s = createJaxbShare(request, share);
        result.getShare().add(s);
        for (MediaFile mediaFile : shareService.getSharedFiles(share.getId(), musicFolders)) {
            s.getEntry().add(createJaxbChild(player, mediaFile, username));
        }
    }
    Response res = createResponse();
    res.setShares(result);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) User(org.libresonic.player.domain.User) org.libresonic.restapi(org.libresonic.restapi) MusicFolder(org.libresonic.player.domain.MusicFolder) Share(org.libresonic.player.domain.Share) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with MusicFolder

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

the class RESTController method getAlbumList2.

@RequestMapping(value = "/rest/getAlbumList2", method = { RequestMethod.GET, RequestMethod.POST })
public void getAlbumList2(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    int size = getIntParameter(request, "size", 10);
    int offset = getIntParameter(request, "offset", 0);
    size = Math.max(0, Math.min(size, 500));
    String type = getRequiredStringParameter(request, "type");
    String username = securityService.getCurrentUsername(request);
    Integer musicFolderId = getIntParameter(request, "musicFolderId");
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username, musicFolderId);
    List<Album> albums;
    if ("frequent".equals(type)) {
        albums = albumDao.getMostFrequentlyPlayedAlbums(offset, size, musicFolders);
    } else if ("recent".equals(type)) {
        albums = albumDao.getMostRecentlyPlayedAlbums(offset, size, musicFolders);
    } else if ("newest".equals(type)) {
        albums = albumDao.getNewestAlbums(offset, size, musicFolders);
    } else if ("alphabeticalByArtist".equals(type)) {
        albums = albumDao.getAlphabetialAlbums(offset, size, true, musicFolders);
    } else if ("alphabeticalByName".equals(type)) {
        albums = albumDao.getAlphabetialAlbums(offset, size, false, musicFolders);
    } else if ("byGenre".equals(type)) {
        albums = albumDao.getAlbumsByGenre(offset, size, getRequiredStringParameter(request, "genre"), musicFolders);
    } else if ("byYear".equals(type)) {
        albums = albumDao.getAlbumsByYear(offset, size, getRequiredIntParameter(request, "fromYear"), getRequiredIntParameter(request, "toYear"), musicFolders);
    } else if ("starred".equals(type)) {
        albums = albumDao.getStarredAlbums(offset, size, securityService.getCurrentUser(request).getUsername(), musicFolders);
    } else if ("random".equals(type)) {
        albums = searchService.getRandomAlbumsId3(size, musicFolders);
    } else {
        throw new Exception("Invalid list type: " + type);
    }
    AlbumList2 result = new AlbumList2();
    for (Album album : albums) {
        result.getAlbum().add(createJaxbAlbum(new AlbumID3(), album, username));
    }
    Response res = createResponse();
    res.setAlbumList2(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)

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