use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class Main method loadAndPlay.
private void loadAndPlay(final IChannel channel, final String trackUrl) {
GuildMusicManager musicManager = getGuildAudioPlayer(channel.getGuild());
playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
sendMessageToChannel(channel, "Adding to queue " + track.getInfo().title);
play(channel.getGuild(), musicManager, track);
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
AudioTrack firstTrack = playlist.getSelectedTrack();
if (firstTrack == null) {
firstTrack = playlist.getTracks().get(0);
}
sendMessageToChannel(channel, "Adding to queue " + firstTrack.getInfo().title + " (first track of playlist " + playlist.getName() + ")");
play(channel.getGuild(), musicManager, firstTrack);
}
@Override
public void noMatches() {
sendMessageToChannel(channel, "Nothing found by " + trackUrl);
}
@Override
public void loadFailed(FriendlyException exception) {
sendMessageToChannel(channel, "Could not play: " + exception.getMessage());
}
});
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class Main method loadAndPlay.
private void loadAndPlay(final TextChannel channel, final String trackUrl) {
GuildMusicManager musicManager = getGuildAudioPlayer(channel.getGuild());
playerManager.loadItemOrdered(musicManager, trackUrl, new AudioLoadResultHandler() {
@Override
public void trackLoaded(AudioTrack track) {
channel.sendMessage("Adding to queue " + track.getInfo().title).queue();
play(channel.getGuild(), musicManager, track);
}
@Override
public void playlistLoaded(AudioPlaylist playlist) {
AudioTrack firstTrack = playlist.getSelectedTrack();
if (firstTrack == null) {
firstTrack = playlist.getTracks().get(0);
}
channel.sendMessage("Adding to queue " + firstTrack.getInfo().title + " (first track of playlist " + playlist.getName() + ")").queue();
play(channel.getGuild(), musicManager, firstTrack);
}
@Override
public void noMatches() {
channel.sendMessage("Nothing found by " + trackUrl).queue();
}
@Override
public void loadFailed(FriendlyException exception) {
channel.sendMessage("Could not play: " + exception.getMessage()).queue();
}
});
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class NicoAudioSourceManager method checkLoggedIn.
void checkLoggedIn() {
synchronized (loggedIn) {
if (loggedIn.get()) {
return;
}
HttpPost loginRequest = new HttpPost("https://secure.nicovideo.jp/secure/login");
loginRequest.setEntity(new UrlEncodedFormEntity(Arrays.asList(new BasicNameValuePair("mail", email), new BasicNameValuePair("password", password)), StandardCharsets.UTF_8));
try (HttpInterface httpInterface = getHttpInterface()) {
try (CloseableHttpResponse response = httpInterface.execute(loginRequest)) {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 302) {
throw new IOException("Unexpected response code " + statusCode);
}
Header location = response.getFirstHeader("Location");
if (location == null || location.getValue().contains("message=")) {
throw new FriendlyException("Login details for NicoNico are invalid.", COMMON, null);
}
loggedIn.set(true);
}
} catch (IOException e) {
throw new FriendlyException("Exception when trying to log into NicoNico", SUSPICIOUS, e);
}
}
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class SoundCloudAudioSourceManager method loadPageConfigJson.
private JsonBrowser loadPageConfigJson(HttpInterface httpInterface, String url) throws IOException {
try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(url))) {
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_NOT_FOUND) {
throw new FriendlyException("That track does not exist.", COMMON, null);
} else if (statusCode != HttpStatus.SC_OK) {
throw new IOException("Invalid status code for video page response: " + statusCode);
}
String html = IOUtils.toString(response.getEntity().getContent(), Charset.forName(CHARSET));
String configJson = DataFormatTools.extractBetween(html, "e}var c=", ",o=Date.now()");
if (configJson == null) {
throw new FriendlyException("This url does not appear to be a playable track.", SUSPICIOUS, null);
}
return JsonBrowser.parse(configJson);
}
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class TwitchStreamSegmentUrlProvider method getNextSegmentUrl.
/**
* @param httpInterface Http interface to use for requests.
* @return The URL of the next TS segment.
*/
@Override
public String getNextSegmentUrl(HttpInterface httpInterface) {
try {
if (!obtainSegmentPlaylistUrl(httpInterface)) {
return null;
}
List<String> segments = loadStreamSegmentsList(httpInterface, streamSegmentPlaylistUrl);
lastSegment = chooseNextSegment(segments, lastSegment);
if (lastSegment == null) {
return null;
}
return createSegmentUrl(streamSegmentPlaylistUrl, lastSegment);
} catch (IOException e) {
throw new FriendlyException("Failed to get next part of the stream.", SUSPICIOUS, e);
}
}
Aggregations