src/main/java/org/intellimate/izou/sdk/frameworks/music/user/PlaylistSelector.java
@SuppressWarnings("unused")
    public static Optional<PlaylistSelector> getPlaylistsFromPlayer(Identification player, AddOnModule addOnModule) {
        if (player == null || addOnModule == null)
            return Optional.empty();
        Function<Capabilities, CompletableFuture<Optional<PlaylistSelector>>> getPlaylistSelector = capabilities ->
                addOnModule.getContext().getResources()
                .generateResource(new BroadcasterAvailablePlaylists(player))
                .orElse(CompletableFuture.completedFuture(new ArrayList<>()))
                .thenApply(list -> list.stream()
                                .filter(resourceModel -> resourceModel.getProvider().equals(player))
                                .findAny()
                                .flatMap(BroadcasterAvailablePlaylists::getPlaylists)
                                .map(playlists ->
                                        new PlaylistSelector(player, capabilities, playlists, addOnModule.getContext(), addOnModule))
                );


        Function<List<ResourceModel>, Optional<Capabilities>> getCapabilities = resourceModels -> resourceModels.stream()
                .filter(resourceModel -> resourceModel.getProvider().equals(player))
                .findAny()
                .flatMap(resource -> Capabilities.importFromResource(resource, addOnModule.getContext()))
                .filter(capabilities -> {
                    if (!capabilities.handlesPlayRequestFromOutside()) {
                        addOnModule.getContext().getLogger().error("player does not handle play-request from outside");
                        return false;
                    }
                    if (!capabilities.hasPlayRequestDetailed()) {
                        addOnModule.getContext().getLogger().error("player does not handle trackInfo-request from outside");
                        return false;
                    }
                    if (!capabilities.isBroadcasting()) {
                        addOnModule.getContext().getLogger().error("player is not broadcasting playlists");
                        return false;
                    }
                    return true;
                });

        try {
            return addOnModule.getContext().getResources()
                    .generateResource(new CapabilitiesResource(player))
                    .orElse(CompletableFuture.completedFuture(new ArrayList<>()))
                    .thenApply(getCapabilities::apply)
                    .thenCompose(capabilities -> capabilities.map(getPlaylistSelector::apply)
                            .orElseGet(() -> CompletableFuture.completedFuture(Optional.<PlaylistSelector>empty()))
                    ).get(1, TimeUnit.SECONDS);
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            addOnModule.getContext().getLogger().error("unable to get PlaylistSelector");
            return Optional.empty();
        }
    }
@SuppressWarnings("unused")
    public static Optional<PlaylistSelector> getPlaylistsFromPlayer(Identification player, AddOnModule addOnModule) {
        if (player == null || addOnModule == null)
            return Optional.empty();
        Function<Capabilities, CompletableFuture<Optional<PlaylistSelector>>> getPlaylistSelector = capabilities ->
                addOnModule.getContext().getResources()
                .generateResource(new BroadcasterAvailablePlaylists(player))
                .orElse(CompletableFuture.completedFuture(new ArrayList<>()))
                .thenApply(list -> list.stream()
                                .filter(resourceModel -> resourceModel.getProvider().equals(player))
                                .findAny()
                                .flatMap(BroadcasterAvailablePlaylists::getPlaylists)
                                .map(playlists ->
                                        new PlaylistSelector(player, capabilities, playlists, addOnModule.getContext(), addOnModule))
                );


        Function<List<ResourceModel>, Optional<Capabilities>> getCapabilities = resourceModels -> resourceModels.stream()
                .filter(resourceModel -> resourceModel.getProvider().equals(player))
                .findAny()
                .flatMap(resource -> Capabilities.importFromResource(resource, addOnModule.getContext()))
                .filter(capabilities -> {
                    if (!capabilities.handlesPlayRequestFromOutside()) {
                        addOnModule.getContext().getLogger().error("player does not handle play-request from outside");
                        return false;
                    }
                    if (!capabilities.hasPlayRequestDetailed()) {
                        addOnModule.getContext().getLogger().error("player does not handle trackInfo-request from outside");
                        return false;
                    }
                    if (!capabilities.isBroadcasting()) {
                        addOnModule.getContext().getLogger().error("player is not broadcasting playlists");
                        return false;
                    }
                    return true;
                });

        try {
            return addOnModule.getContext().getResources()
                    .generateResource(new CapabilitiesResource(player))
                    .orElse(CompletableFuture.completedFuture(new ArrayList<>()))
                    .thenApply(getCapabilities::apply)
                    .thenCompose(capabilities -> capabilities.map(getPlaylistSelector::apply)
                            .orElseGet(() -> CompletableFuture.completedFuture(Optional.<PlaylistSelector>empty()))
                    ).get(1, TimeUnit.SECONDS);
        } catch (InterruptedException | ExecutionException | TimeoutException e) {
            addOnModule.getContext().getLogger().error("unable to get PlaylistSelector");
            return Optional.empty();
        }
    }
creates a new PlaylistSelector.
<p>
For this method to return a non-empty Optional the following criteria must be met:<br>
<ul>
<li>the player must exist</li>
<li>the players-capabilities must allow requests from outside</li>
<li>the players-capabilities must allow a requests with specified a specified playlist</li>
<li>the players-capabilities signal its broadcasting playlists</li>
</ul>
@param player the specified player
@param addOnModule the addOnModule used for Context etc.
@return the optional PlaylistSelector.