use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project legendarybot by greatman.
the class MusicManager method loadAndPlay.
/**
* Load a song
* @param channel The channel to send the alert in.
* @param trackUrl The song URL
* @param voiceChannel the voice channel to play the music in.
*/
public void loadAndPlay(final TextChannel channel, final String trackUrl, VoiceChannel voiceChannel) {
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, voiceChannel);
}
@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, voiceChannel);
}
@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 YoutubeMpegStreamAudioTrack method processSegmentStream.
private void processSegmentStream(SeekableInputStream stream, AudioProcessingContext context, TrackState state) throws InterruptedException {
MpegFileLoader file = new MpegFileLoader(stream);
file.parseHeaders();
state.absoluteSequence = extractAbsoluteSequenceFromEvent(file.getLastEventMessage());
if (state.trackConsumer == null) {
state.trackConsumer = loadAudioTrack(file, context);
}
MpegFileTrackProvider fileReader = file.loadReader(state.trackConsumer);
if (fileReader == null) {
throw new FriendlyException("Unknown MP4 format.", SUSPICIOUS, null);
}
fileReader.provideFrames();
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class GetyarnAudioSourceManager method extractVideoUrlFromPage.
private AudioTrack extractVideoUrlFromPage(AudioReference reference) {
try (final CloseableHttpResponse response = getHttpInterface().execute(new HttpGet(reference.identifier))) {
final String html = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Document document = Jsoup.parse(html);
final AudioTrackInfo trackInfo = AudioTrackInfoBuilder.empty().setUri(reference.identifier).setAuthor("Unknown").setIsStream(false).setIdentifier(document.selectFirst("meta[property=og:video:secure_url]").attr("content")).setTitle(document.selectFirst("meta[property=og:title]").attr("content")).build();
return createTrack(trackInfo);
} catch (IOException e) {
throw new FriendlyException("Failed to load info for yarn clip", SUSPICIOUS, null);
}
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class M3uStreamSegmentUrlProvider method getNextSegmentUrl.
/**
* Logic for getting the URL for the next segment.
*
* @param httpInterface HTTP interface to use for any requests required to perform to find the segment URL.
* @return The direct stream URL of the next segment.
*/
protected String getNextSegmentUrl(HttpInterface httpInterface) {
try {
String streamSegmentPlaylistUrl = fetchSegmentPlaylistUrl(httpInterface);
if (streamSegmentPlaylistUrl == null) {
return null;
}
long startTime = System.currentTimeMillis();
SegmentInfo nextSegment;
while (true) {
List<SegmentInfo> segments = loadStreamSegmentsList(httpInterface, streamSegmentPlaylistUrl);
nextSegment = chooseNextSegment(segments, lastSegment);
if (nextSegment != null || !shouldWaitForSegment(startTime, segments)) {
break;
}
Thread.sleep(SEGMENT_WAIT_STEP_MS);
}
if (nextSegment == null) {
return null;
}
lastSegment = nextSegment;
return createSegmentUrl(streamSegmentPlaylistUrl, lastSegment.url);
} catch (IOException e) {
throw new FriendlyException("Failed to get next part of the stream.", SUSPICIOUS, e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class VimeoAudioTrack method loadPlaybackUrl.
private String loadPlaybackUrl(HttpInterface httpInterface) throws IOException {
JsonBrowser config = loadPlayerConfig(httpInterface);
if (config == null) {
throw new FriendlyException("Track information not present on the page.", SUSPICIOUS, null);
}
String trackConfigUrl = config.get("player").get("config_url").text();
JsonBrowser trackConfig = loadTrackConfig(httpInterface, trackConfigUrl);
return trackConfig.get("request").get("files").get("progressive").index(0).get("url").text();
}
Aggregations