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);
}
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));
}
}
Aggregations