Search in sources :

Example 1 with Playable

use of net.robinfriedli.aiode.audio.Playable in project aiode by robinfriedli.

the class QueueViewHandler method appendList.

private void appendList(StringBuilder listBuilder, List<Playable> playables, String title) {
    listBuilder.append("<h3>").append(title).append("</h3>").append(System.lineSeparator());
    listBuilder.append("<table class=\"content-table\">").append(System.lineSeparator());
    listBuilder.append("<tbody>").append(System.lineSeparator());
    for (Playable playable : playables) {
        listBuilder.append("<tr>").append(System.lineSeparator());
        listBuilder.append("<td>").append(playable.getDisplayNow()).append("</td>").append(System.lineSeparator());
        listBuilder.append("<td>").append(Util.normalizeMillis(playable.getDurationNow())).append("</td>").append(System.lineSeparator());
        listBuilder.append("</tr>").append(System.lineSeparator());
    }
    listBuilder.append("</tbody>").append(System.lineSeparator());
    listBuilder.append("</table>");
}
Also used : Playable(net.robinfriedli.aiode.audio.Playable)

Example 2 with Playable

use of net.robinfriedli.aiode.audio.Playable in project aiode by robinfriedli.

the class ChartsCommand method getTrackForRecord.

private Playable getTrackForRecord(Object[] record, Session session) throws Exception {
    long sourceEntityPk = (Long) record[0];
    PlaybackHistorySource sourceEntity = session.load(PlaybackHistorySource.class, sourceEntityPk);
    Playable.Source source = sourceEntity.asEnum();
    String id = (String) record[1];
    Long spotifyItemKindPk = (Long) record[3];
    SpotifyItemKind spotifyItemKind = spotifyItemKindPk != null ? session.load(SpotifyItemKind.class, spotifyItemKindPk) : null;
    switch(source) {
        case SPOTIFY:
            return runWithCredentials(() -> {
                if (spotifyItemKind == null) {
                    throw new IllegalStateException("spotifyItemKind cannot be null for PlaybackHistory entries of source SPOTIFY");
                }
                SpotifyTrackKind kind = spotifyItemKind.asEnum();
                SpotifyService spotifyService = getSpotifyService();
                SpotifyTrack track = kind.loadSingleItem(spotifyService, id);
                if (track == null) {
                    return null;
                }
                return new PlayableTrackWrapper(track);
            });
        case YOUTUBE:
            YouTubeService youTubeService = Aiode.get().getAudioManager().getYouTubeService();
            try {
                return youTubeService.getVideoForId(id);
            } catch (FriendlyException e) {
                return null;
            }
        case URL:
            return playableFactory.createPlayable(id, getContext().getSpotifyApi(), false);
    }
    throw new UnsupportedOperationException("Unsupported source " + sourceEntity);
}
Also used : SpotifyItemKind(net.robinfriedli.aiode.entities.SpotifyItemKind) SpotifyService(net.robinfriedli.aiode.audio.spotify.SpotifyService) YouTubeService(net.robinfriedli.aiode.audio.youtube.YouTubeService) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException) PlayableTrackWrapper(net.robinfriedli.aiode.audio.spotify.PlayableTrackWrapper) Playable(net.robinfriedli.aiode.audio.Playable) SpotifyTrackKind(net.robinfriedli.aiode.audio.spotify.SpotifyTrackKind) SpotifyTrack(net.robinfriedli.aiode.audio.spotify.SpotifyTrack) PlaybackHistorySource(net.robinfriedli.aiode.entities.PlaybackHistorySource)

Example 3 with Playable

use of net.robinfriedli.aiode.audio.Playable in project aiode by robinfriedli.

the class ChartsCommand method addTrackCharts.

private void addTrackCharts(List<Object[]> queryResults, EmbedBuilder embedBuilder, String period, Session session) {
    Map<Playable, Long> tracksWithPlayedAmount = new HashMap<>();
    List<Playable> tracks = Lists.newArrayList();
    for (Object[] record : queryResults) {
        long playedAmount = (Long) record[2];
        try {
            Playable track = getTrackForRecord(record, session);
            if (track != null) {
                tracksWithPlayedAmount.put(track, playedAmount);
                tracks.add(track);
            }
        } catch (UnsupportedOperationException e) {
            throw e;
        } catch (Exception e) {
            LoggerFactory.getLogger(getClass()).error(String.format("Error loading charts item from source %s: %s", record[0], record[1]), e);
        }
    }
    String title = period + " - Track Charts";
    if (!tracks.isEmpty()) {
        Util.appendEmbedList(embedBuilder, tracks, track -> tracksWithPlayedAmount.get(track) + " - " + track.display(), title, true);
    } else {
        embedBuilder.addField(title, "No data", true);
    }
}
Also used : Playable(net.robinfriedli.aiode.audio.Playable) HashMap(java.util.HashMap) FriendlyException(com.sedmelluq.discord.lavaplayer.tools.FriendlyException)

Example 4 with Playable

use of net.robinfriedli.aiode.audio.Playable in project aiode by robinfriedli.

the class AbstractPlayableLoadingCommand method createPlayableForTrack.

private void createPlayableForTrack(Track track, AudioManager audioManager) {
    PlayableFactory playableFactory = audioManager.createPlayableFactory(getSpotifyService(), trackLoadingExecutor);
    Playable playable = playableFactory.createPlayable(shouldRedirectSpotify(), track);
    handleResults(Lists.newArrayList(playable));
    loadedTrack = playable;
}
Also used : PlayableFactory(net.robinfriedli.aiode.audio.PlayableFactory) UrlPlayable(net.robinfriedli.aiode.audio.UrlPlayable) Playable(net.robinfriedli.aiode.audio.Playable)

Example 5 with Playable

use of net.robinfriedli.aiode.audio.Playable in project aiode by robinfriedli.

the class AbstractPlayableLoadingCommand method loadUrlItems.

private void loadUrlItems(AudioManager audioManager, AudioPlayback playback) throws IOException {
    PlayableFactory playableFactory = audioManager.createPlayableFactory(getSpotifyService(), trackLoadingExecutor);
    List<Playable> playables = playableFactory.createPlayables(getCommandInput(), getContext().getSpotifyApi(), shouldRedirectSpotify());
    if (playables.isEmpty()) {
        throw new NoResultsFoundException("Result is empty!");
    }
    handleResults(playables);
    loadedAmount = playables.size();
}
Also used : PlayableFactory(net.robinfriedli.aiode.audio.PlayableFactory) NoResultsFoundException(net.robinfriedli.aiode.exceptions.NoResultsFoundException) UrlPlayable(net.robinfriedli.aiode.audio.UrlPlayable) Playable(net.robinfriedli.aiode.audio.Playable)

Aggregations

Playable (net.robinfriedli.aiode.audio.Playable)20 PlayableFactory (net.robinfriedli.aiode.audio.PlayableFactory)13 UrlPlayable (net.robinfriedli.aiode.audio.UrlPlayable)9 NoResultsFoundException (net.robinfriedli.aiode.exceptions.NoResultsFoundException)7 Playlist (net.robinfriedli.aiode.entities.Playlist)6 AudioManager (net.robinfriedli.aiode.audio.AudioManager)5 AudioQueue (net.robinfriedli.aiode.audio.AudioQueue)5 YouTubePlaylist (net.robinfriedli.aiode.audio.youtube.YouTubePlaylist)5 AudioPlaylist (com.sedmelluq.discord.lavaplayer.track.AudioPlaylist)4 AudioTrack (com.sedmelluq.discord.lavaplayer.track.AudioTrack)4 List (java.util.List)4 Guild (net.dv8tion.jda.api.entities.Guild)4 AudioPlayback (net.robinfriedli.aiode.audio.AudioPlayback)4 SpotifyService (net.robinfriedli.aiode.audio.spotify.SpotifyService)4 SpotifyTrack (net.robinfriedli.aiode.audio.spotify.SpotifyTrack)4 YouTubeService (net.robinfriedli.aiode.audio.youtube.YouTubeService)4 Episode (se.michaelthelin.spotify.model_objects.specification.Episode)4 AudioItem (com.sedmelluq.discord.lavaplayer.track.AudioItem)3 IOException (java.io.IOException)3 Aiode (net.robinfriedli.aiode.Aiode)3