Search in sources :

Example 11 with Player

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

the class PlayerService method clonePlayer.

/**
     * Creates and returns a clone of the given player.
     *
     * @param playerId The ID of the player to clone.
     * @return The cloned player.
     */
public Player clonePlayer(String playerId) {
    Player player = getPlayerById(playerId);
    if (player.getName() != null) {
        player.setName(player.getName() + " (copy)");
    }
    createPlayer(player);
    return player;
}
Also used : Player(org.libresonic.player.domain.Player)

Example 12 with Player

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

the class PlayerService method getNonRestPlayerByIpAddressAndUsername.

/**
     * Returns the (non-REST) player with the given IP address and username. If no username is given, only IP address is
     * used as search criteria.
     *
     * @param ipAddress The IP address.
     * @param username  The remote user.
     * @return The player with the given IP address, or <code>null</code> if no such player exists.
     */
private Player getNonRestPlayerByIpAddressAndUsername(final String ipAddress, final String username) {
    if (ipAddress == null) {
        return null;
    }
    for (Player player : getAllPlayers()) {
        boolean isRest = player.getClientId() != null;
        boolean ipMatches = ipAddress.equals(player.getIpAddress());
        boolean userMatches = username == null || username.equals(player.getUsername());
        if (!isRest && ipMatches && userMatches) {
            return player;
        }
    }
    return null;
}
Also used : Player(org.libresonic.player.domain.Player)

Example 13 with Player

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

the class ShareManagementController method getMediaFiles.

private List<MediaFile> getMediaFiles(HttpServletRequest request) throws Exception {
    Integer id = ServletRequestUtils.getIntParameter(request, "id");
    String playerId = request.getParameter("player");
    Integer playlistId = ServletRequestUtils.getIntParameter(request, "playlist");
    List<MediaFile> result = new ArrayList<>();
    if (id != null) {
        MediaFile album = mediaFileService.getMediaFile(id);
        int[] indexes = ServletRequestUtils.getIntParameters(request, "i");
        if (indexes.length == 0) {
            return Arrays.asList(album);
        }
        List<MediaFile> children = mediaFileService.getChildrenOf(album, true, false, true);
        for (int index : indexes) {
            result.add(children.get(index));
        }
    } else if (playerId != null) {
        Player player = playerService.getPlayerById(playerId);
        PlayQueue playQueue = player.getPlayQueue();
        result = playQueue.getFiles();
    } else if (playlistId != null) {
        result = playlistService.getFilesInPlaylist(playlistId);
    }
    return result;
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) Player(org.libresonic.player.domain.Player) PlayQueue(org.libresonic.player.domain.PlayQueue)

Example 14 with Player

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

the class NowPlayingController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    Player player = playerService.getPlayer(request, response);
    List<TransferStatus> statuses = statusService.getStreamStatusesForPlayer(player);
    MediaFile current = statuses.isEmpty() ? null : mediaFileService.getMediaFile(statuses.get(0).getFile());
    MediaFile dir = current == null ? null : mediaFileService.getParentOf(current);
    String url;
    if (dir != null && !mediaFileService.isRoot(dir)) {
        url = "main.view?id=" + dir.getId();
    } else {
        url = "home.view";
    }
    return new ModelAndView(new RedirectView(url));
}
Also used : MediaFile(org.libresonic.player.domain.MediaFile) Player(org.libresonic.player.domain.Player) TransferStatus(org.libresonic.player.domain.TransferStatus) ModelAndView(org.springframework.web.servlet.ModelAndView) RedirectView(org.springframework.web.servlet.view.RedirectView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with Player

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

the class PlayQueueController method handleRequestInternal.

@RequestMapping(method = RequestMethod.GET)
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
    User user = securityService.getCurrentUser(request);
    UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
    Player player = playerService.getPlayer(request, response);
    Map<String, Object> map = new HashMap<>();
    map.put("user", user);
    map.put("player", player);
    map.put("players", playerService.getPlayersForUserAndClientId(user.getUsername(), null));
    map.put("visibility", userSettings.getPlaylistVisibility());
    map.put("partyMode", userSettings.isPartyModeEnabled());
    map.put("notify", userSettings.isSongNotificationEnabled());
    map.put("autoHide", userSettings.isAutoHidePlayQueue());
    return new ModelAndView("playQueue", "model", map);
}
Also used : Player(org.libresonic.player.domain.Player) User(org.libresonic.player.domain.User) HashMap(java.util.HashMap) UserSettings(org.libresonic.player.domain.UserSettings) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Player (org.libresonic.player.domain.Player)25 Test (org.junit.Test)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 MediaFile (org.libresonic.player.domain.MediaFile)4 User (org.libresonic.player.domain.User)4 ModelAndView (org.springframework.web.servlet.ModelAndView)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Transcoding (org.libresonic.player.domain.Transcoding)3 File (java.io.File)2 PlayQueue (org.libresonic.player.domain.PlayQueue)2 Playlist (org.libresonic.player.domain.Playlist)2 TransferStatus (org.libresonic.player.domain.TransferStatus)2 UserSettings (org.libresonic.player.domain.UserSettings)2 RedirectView (org.springframework.web.servlet.view.RedirectView)2 PrintWriter (java.io.PrintWriter)1 DateFormat (java.text.DateFormat)1 Cookie (javax.servlet.http.Cookie)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1