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