Search in sources :

Example 31 with MusicFolder

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

the class RESTController method getRelativePath.

private String getRelativePath(MediaFile musicFile) {
    String filePath = musicFile.getPath();
    // Convert slashes.
    filePath = filePath.replace('\\', '/');
    String filePathLower = filePath.toLowerCase();
    List<MusicFolder> musicFolders = settingsService.getAllMusicFolders(false, true);
    for (MusicFolder musicFolder : musicFolders) {
        String folderPath = musicFolder.getPath().getPath();
        folderPath = folderPath.replace('\\', '/');
        String folderPathLower = folderPath.toLowerCase();
        if (!folderPathLower.endsWith("/")) {
            folderPathLower += "/";
        }
        if (filePathLower.startsWith(folderPathLower)) {
            String relativePath = filePath.substring(folderPath.length());
            return relativePath.startsWith("/") ? relativePath.substring(1) : relativePath;
        }
    }
    return null;
}
Also used : MusicFolder(org.libresonic.player.domain.MusicFolder)

Example 32 with MusicFolder

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

the class ShareSettingsController method getShareInfos.

private List<ShareInfo> getShareInfos(HttpServletRequest request) {
    List<ShareInfo> result = new ArrayList<ShareInfo>();
    User user = securityService.getCurrentUser(request);
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(user.getUsername());
    for (Share share : shareService.getSharesForUser(user)) {
        List<MediaFile> files = shareService.getSharedFiles(share.getId(), musicFolders);
        if (!files.isEmpty()) {
            MediaFile file = files.get(0);
            result.add(new ShareInfo(shareService.getShareUrl(request, share), share, file.isDirectory() ? file : mediaFileService.getParentOf(file)));
        }
    }
    return result;
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) User(org.libresonic.player.domain.User) MusicFolder(org.libresonic.player.domain.MusicFolder) Share(org.libresonic.player.domain.Share)

Example 33 with MusicFolder

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

the class RESTController method getStarred2.

@RequestMapping(value = "/rest/getStarred2", method = { RequestMethod.GET, RequestMethod.POST })
public void getStarred2(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    Integer musicFolderId = getIntParameter(request, "musicFolderId");
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username, musicFolderId);
    Starred2 result = new Starred2();
    for (Artist artist : artistDao.getStarredArtists(0, Integer.MAX_VALUE, username, musicFolders)) {
        result.getArtist().add(createJaxbArtist(new ArtistID3(), artist, username));
    }
    for (Album album : albumDao.getStarredAlbums(0, Integer.MAX_VALUE, username, musicFolders)) {
        result.getAlbum().add(createJaxbAlbum(new AlbumID3(), album, username));
    }
    for (MediaFile song : mediaFileDao.getStarredFiles(0, Integer.MAX_VALUE, username, musicFolders)) {
        result.getSong().add(createJaxbChild(player, song, username));
    }
    Response res = createResponse();
    res.setStarred2(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 34 with MusicFolder

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

the class RESTController method search2.

@RequestMapping(value = "/rest/search2", method = { RequestMethod.GET, RequestMethod.POST })
public void search2(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    Player player = playerService.getPlayer(request, response);
    String username = securityService.getCurrentUsername(request);
    Integer musicFolderId = getIntParameter(request, "musicFolderId");
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username, musicFolderId);
    SearchResult2 searchResult = new SearchResult2();
    String query = request.getParameter("query");
    SearchCriteria criteria = new SearchCriteria();
    criteria.setQuery(StringUtils.trimToEmpty(query));
    criteria.setCount(getIntParameter(request, "artistCount", 20));
    criteria.setOffset(getIntParameter(request, "artistOffset", 0));
    SearchResult artists = searchService.search(criteria, musicFolders, SearchService.IndexType.ARTIST);
    for (MediaFile mediaFile : artists.getMediaFiles()) {
        searchResult.getArtist().add(createJaxbArtist(mediaFile, username));
    }
    criteria.setCount(getIntParameter(request, "albumCount", 20));
    criteria.setOffset(getIntParameter(request, "albumOffset", 0));
    SearchResult albums = searchService.search(criteria, musicFolders, SearchService.IndexType.ALBUM);
    for (MediaFile mediaFile : albums.getMediaFiles()) {
        searchResult.getAlbum().add(createJaxbChild(player, mediaFile, username));
    }
    criteria.setCount(getIntParameter(request, "songCount", 20));
    criteria.setOffset(getIntParameter(request, "songOffset", 0));
    SearchResult songs = searchService.search(criteria, musicFolders, SearchService.IndexType.SONG);
    for (MediaFile mediaFile : songs.getMediaFiles()) {
        searchResult.getSong().add(createJaxbChild(player, mediaFile, username));
    }
    Response res = createResponse();
    res.setSearchResult2(searchResult);
    jaxbWriter.writeResponse(request, response, res);
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) SearchResult(org.libresonic.player.domain.SearchResult) MusicFolder(org.libresonic.player.domain.MusicFolder) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 35 with MusicFolder

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

the class RESTController method getArtist.

@RequestMapping(value = "/rest/getArtist", method = { RequestMethod.GET, RequestMethod.POST })
public void getArtist(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request = wrapRequest(request);
    String username = securityService.getCurrentUsername(request);
    int id = getRequiredIntParameter(request, "id");
    Artist artist = artistDao.getArtist(id);
    if (artist == null) {
        error(request, response, ErrorCode.NOT_FOUND, "Artist not found.");
        return;
    }
    List<MusicFolder> musicFolders = settingsService.getMusicFoldersForUser(username);
    ArtistWithAlbumsID3 result = createJaxbArtist(new ArtistWithAlbumsID3(), artist, username);
    for (Album album : albumDao.getAlbumsForArtist(artist.getName(), musicFolders)) {
        result.getAlbum().add(createJaxbAlbum(new AlbumID3(), album, username));
    }
    Response res = createResponse();
    res.setArtist(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)

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