Search in sources :

Example 1 with PlayableTrackWrapper

use of net.robinfriedli.aiode.audio.spotify.PlayableTrackWrapper 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 2 with PlayableTrackWrapper

use of net.robinfriedli.aiode.audio.spotify.PlayableTrackWrapper in project aiode by robinfriedli.

the class PlayableFactory method handleTrack.

private void handleTrack(SpotifyTrack track, boolean redirectSpotify, List<HollowYouTubeVideo> tracksToRedirect, List<Playable> playables) {
    if (track == null) {
        return;
    }
    if (redirectSpotify) {
        HollowYouTubeVideo youTubeVideo = new HollowYouTubeVideo(youTubeService, track);
        tracksToRedirect.add(youTubeVideo);
        playables.add(youTubeVideo);
    } else {
        playables.add(new PlayableTrackWrapper(track));
    }
}
Also used : PlayableTrackWrapper(net.robinfriedli.aiode.audio.spotify.PlayableTrackWrapper) HollowYouTubeVideo(net.robinfriedli.aiode.audio.youtube.HollowYouTubeVideo)

Aggregations

PlayableTrackWrapper (net.robinfriedli.aiode.audio.spotify.PlayableTrackWrapper)2 FriendlyException (com.sedmelluq.discord.lavaplayer.tools.FriendlyException)1 Playable (net.robinfriedli.aiode.audio.Playable)1 SpotifyService (net.robinfriedli.aiode.audio.spotify.SpotifyService)1 SpotifyTrack (net.robinfriedli.aiode.audio.spotify.SpotifyTrack)1 SpotifyTrackKind (net.robinfriedli.aiode.audio.spotify.SpotifyTrackKind)1 HollowYouTubeVideo (net.robinfriedli.aiode.audio.youtube.HollowYouTubeVideo)1 YouTubeService (net.robinfriedli.aiode.audio.youtube.YouTubeService)1 PlaybackHistorySource (net.robinfriedli.aiode.entities.PlaybackHistorySource)1 SpotifyItemKind (net.robinfriedli.aiode.entities.SpotifyItemKind)1