use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.
the class AbstractPlayableLoadingCommand method loadLocalList.
private void loadLocalList(AudioManager audioManager) throws Exception {
Playlist playlist = SearchEngine.searchLocalList(getContext().getSession(), getCommandInput());
if (playlist == null) {
throw new NoResultsFoundException(String.format("No local playlist found for '%s'", getCommandInput()));
}
List<Object> items = runWithCredentials(() -> playlist.getTracks(getContext().getSpotifyApi()));
if (items.isEmpty()) {
throw new NoResultsFoundException("Playlist is empty");
}
PlayableFactory playableFactory = audioManager.createPlayableFactory(getSpotifyService(), trackLoadingExecutor);
List<Playable> playables = playableFactory.createPlayables(shouldRedirectSpotify(), items);
handleResults(playables);
loadedLocalList = playlist;
}
use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.
the class CreateCommand method doRun.
@Override
public void doRun() {
Session session = getContext().getSession();
Playlist existingPlaylist = SearchEngine.searchLocalList(session, getCommandInput());
if (existingPlaylist != null) {
throw new InvalidCommandException("Playlist " + getCommandInput() + " already exists");
}
Playlist playlist = new Playlist(getCommandInput(), getContext().getUser(), getContext().getGuild());
invoke(() -> session.persist(playlist));
}
use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.
the class EmptyCommand method doRun.
@Override
public void doRun() {
Session session = getContext().getSession();
Playlist playlist = SearchEngine.searchLocalList(session, getCommandInput());
if (playlist == null) {
throw new NoResultsFoundException(String.format("No aiode playlist found for '%s'", getCommandInput()));
}
if (playlist.isEmpty()) {
throw new InvalidCommandException("Playlist is already empty");
}
invoke(() -> {
for (PlaylistItem item : playlist.getItems()) {
session.delete(item);
}
});
}
use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.
the class RemoveCommand method doRun.
@Override
public void doRun() {
Session session = getContext().getSession();
String playlistName = getArgumentValue("from");
Playlist playlist = SearchEngine.searchLocalList(session, playlistName);
if (playlist == null) {
throw new NoResultsFoundException(String.format("No local list found for '%s'", playlistName));
} else if (playlist.isEmpty()) {
throw new InvalidCommandException("Playlist is empty");
}
if (argumentSet("index")) {
StringList indices = StringList.createWithRegex(getCommandInput(), "-");
if (indices.size() == 1 || indices.size() == 2) {
indices.applyForEach(String::trim);
if (indices.size() == 1) {
int index = parse(indices.get(0));
checkIndex(index, playlist);
invoke(() -> session.delete(playlist.getItemsSorted().get(index - 1)));
} else {
int start = parse(indices.get(0));
int end = parse(indices.get(1));
checkIndex(start, playlist);
checkIndex(end, playlist);
if (end <= start) {
throw new InvalidCommandException("End index needs to be greater than start.");
}
invoke(() -> playlist.getItemsSorted().subList(start - 1, end).forEach(session::delete));
}
} else {
throw new InvalidCommandException("Expected one or two indices but found " + indices.size());
}
} else {
List<PlaylistItem> playlistItems = SearchEngine.searchPlaylistItems(playlist, getCommandInput());
if (playlistItems.size() == 1) {
invoke(() -> session.delete(playlistItems.get(0)));
} else if (playlistItems.isEmpty()) {
throw new NoResultsFoundException(String.format("No tracks found for '%s' on list '%s'", getCommandInput(), playlistName));
} else {
askQuestion(playlistItems, PlaylistItem::display, item -> valueOf(item.getIndex() + 1));
}
}
}
use of net.robinfriedli.aiode.entities.Playlist in project aiode by robinfriedli.
the class MigratePlaylistsTask method migrateFile.
private void migrateFile(Session session, Context context, Guild guild, SpotifyApi spotifyApi) throws Exception {
HibernatePlaylistMigrator hibernatePlaylistMigrator = new HibernatePlaylistMigrator(context, guild, spotifyApi, session);
Map<Playlist, List<PlaylistItem>> playlistMap = hibernatePlaylistMigrator.perform();
for (Playlist playlist : playlistMap.keySet()) {
playlistMap.get(playlist).forEach(item -> {
item.add();
session.persist(item);
});
session.persist(playlist);
}
File directory = new File("./resources/archive");
if (!directory.exists()) {
directory.mkdir();
}
File file = context.getFile();
Objects.requireNonNull(file);
Files.move(file, new File(directory.getPath() + "/" + file.getName()));
}
Aggregations