use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project lavaplayer by sedmelluq.
the class BeamSegmentUrlProvider 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);
String segment = chooseNextSegment(segments, lastSegment);
if (segment == null) {
return null;
}
lastSegment = segment;
return createSegmentUrl(streamSegmentPlaylistUrl, segment);
} catch (IOException e) {
throw new FriendlyException("Failed to get next part of the stream.", SUSPICIOUS, e);
}
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project SkyBot by duncte123.
the class ClypitAudioSourceManager method detectContainerWithClient.
private MediaContainerDetectionResult detectContainerWithClient(HttpInterface httpInterface, AudioReference reference) throws IOException {
try (PersistentHttpStream inputStream = new PersistentHttpStream(httpInterface, new URI(reference.identifier), Long.MAX_VALUE)) {
int statusCode = inputStream.checkStatusCode();
String redirectUrl = HttpClientTools.getRedirectLocation(reference.identifier, inputStream.getCurrentResponse());
if (redirectUrl != null) {
return new MediaContainerDetectionResult(null, new AudioReference(redirectUrl, null));
} else if (statusCode == HttpStatus.SC_NOT_FOUND) {
return null;
} else if (!HttpClientTools.isSuccessWithContent(statusCode)) {
throw new FriendlyException("That URL is not playable.", COMMON, new IllegalStateException("Status code " + statusCode));
}
MediaContainerHints hints = MediaContainerHints.from(getHeaderValue(inputStream.getCurrentResponse(), "Content-Type"), null);
return MediaContainerDetection.detectContainer(reference, inputStream, hints);
} catch (URISyntaxException e) {
throw new FriendlyException("Not a valid URL.", COMMON, e);
}
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project SkyBot by duncte123.
the class SpotifyAudioSourceManager method loadItem.
@Override
public AudioItem loadItem(DefaultAudioPlayerManager manager, AudioReference reference) {
if (isSpotifyAlbum(reference.identifier)) {
if (youtube == null)
return null;
Matcher res = SPOTIFY_ALBUM_REGEX.matcher(reference.identifier);
if (res.matches()) {
try {
final List<AudioTrack> playList = new ArrayList<>();
final Album album = api.getAlbum(res.group(res.groupCount())).build().get();
for (SimpleTrack t : album.getTracks().getItems()) {
List<SearchResult> results = searchYoutube(album.getArtists().get(0).getName() + " - " + t.getName());
playList.addAll(doThingWithPlaylist(results));
}
return new BasicAudioPlaylist(album.getName(), playList, playList.get(0), false);
} catch (Exception e) {
// logger.error("Something went wrong!", e);
throw new FriendlyException(e.getMessage(), FriendlyException.Severity.FAULT, e);
// return null;
}
}
} else if (isSpotifyPlaylist(reference.identifier)) {
if (youtube == null)
return null;
Matcher res = SPOTIFY_PLAYLIST_REGEX.matcher(reference.identifier);
if (res.matches()) {
try {
final List<AudioTrack> finalPlaylist = new ArrayList<>();
final Playlist spotifyPlaylist = api.getPlaylist(res.group(res.groupCount() - 1), res.group(res.groupCount())).build().get();
for (PlaylistTrack playlistTrack : spotifyPlaylist.getTracks().getItems()) {
List<SearchResult> results = searchYoutube(playlistTrack.getTrack().getArtists().get(0).getName() + " - " + playlistTrack.getTrack().getName());
finalPlaylist.addAll(doThingWithPlaylist(results));
}
return new BasicAudioPlaylist(spotifyPlaylist.getName(), finalPlaylist, finalPlaylist.get(0), false);
} catch (Exception e) {
// logger.error("Something went wrong!", e);
throw new FriendlyException(e.getMessage(), FriendlyException.Severity.FAULT, e);
// return null;
}
}
} else if (isSpotyfyTrack(reference.identifier)) {
if (youtube == null)
return null;
Matcher res = SPOTIFY_TRACK_REGEX.matcher(reference.identifier);
if (res.matches()) {
try {
final Track track = api.getTrack(res.group(res.groupCount())).build().get();
List<SearchResult> results = searchYoutube(track.getArtists().get(0).getName() + " - " + track.getName());
Video v = getVideoById(results.get(0).getId().getVideoId());
return new SpotifyAudioTrack(new AudioTrackInfo(v.getSnippet().getTitle(), v.getSnippet().getChannelId(), toLongDuration(v.getContentDetails().getDuration()), v.getId(), false, "https://youtube.com/watch?v=" + v.getId()), youtubeAudioSourceManager);
// return youtubeSearchProvider.loadSearchResult(track.getArtists().get(0).getName() + " - "+ track.getName());
} catch (Exception e) {
// logger.error("Something went wrong!", e);
throw new FriendlyException(e.getMessage(), FriendlyException.Severity.FAULT, e);
// return null;
}
}
}
/*if(isSpotifyAlbum(reference.identifier)) {
if(this.youtubeAudioSourceManager == null)
return null;
Matcher res = SPOTIFY_ALBUM_REGEX.matcher(reference.identifier);
if (res.matches()) {
try {
final List<AudioTrack> playList = new ArrayList<>();
final Album album = api.getAlbum(res.group(res.groupCount())).build().get();
for(SimpleTrack t : album.getTracks().getItems()){
String fakeUrl = album.getArtists().get(0).getName() + " - "+ t.getName();
List<AudioTrack> tracks = ((AudioPlaylist)youtubeSearchProvider.loadSearchResult(fakeUrl)).getTracks();
if(tracks.size() > 0)
playList.add(tracks.get(0));
}
return new BasicAudioPlaylist(album.getName(), playList, playList.get(0), false);
} catch (Exception e) {
//logger.error("Something went wrong!", e);
throw new FriendlyException(e.getMessage(), FriendlyException.Severity.FAULT, e);
//return null;
}
}
} else if(isSpotifyPlaylist(reference.identifier)) {
if(this.youtubeAudioSourceManager == null)
return null;
Matcher res = SPOTIFY_PLAYLIST_REGEX.matcher(reference.identifier);
if (res.matches()) {
try {
final List<AudioTrack> finalPlaylist = new ArrayList<>();
final Playlist spotifyPlaylist = api.getPlaylist(res.group(res.groupCount()-1), res.group(res.groupCount())).build().get();
for(PlaylistTrack playlistTrack : spotifyPlaylist.getTracks().getItems()){
String fakeUrl = playlistTrack.getTrack().getArtists().get(0).getName() + " - " + playlistTrack.getTrack().getName();
System.out.println(fakeUrl);
List<AudioTrack> tracks = ((AudioPlaylist)youtubeSearchProvider.loadSearchResult(fakeUrl)).getTracks();
if(tracks.size() > 0)
finalPlaylist.add(tracks.get(0));
}
return new BasicAudioPlaylist(spotifyPlaylist.getName(), finalPlaylist, finalPlaylist.get(0), false);
} catch (Exception e) {
//logger.error("Something went wrong!", e);
throw new FriendlyException(e.getMessage(), FriendlyException.Severity.FAULT, e);
//return null;
}
}
} else if(isSpotyfyTrack(reference.identifier)) {
if(this.youtubeAudioSourceManager == null)
return null;
Matcher res = SPOTIFY_TRACK_REGEX.matcher(reference.identifier);
if (res.matches()) {
try {
final Track track = api.getTrack(res.group(res.groupCount())).build().get();
return youtubeSearchProvider.loadSearchResult(track.getArtists().get(0).getName() + " - "+ track.getName());
} catch (Exception e) {
//logger.error("Something went wrong!", e);
throw new FriendlyException(e.getMessage(), FriendlyException.Severity.FAULT, e);
//return null;
}
}
}*/
return null;
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project FredBoat by Frederikam.
the class HttpSourceManager method checkHtmlResponse.
private MediaContainerDetectionResult checkHtmlResponse(AudioReference reference, PersistentHttpStream stream, MediaContainerHints hints) {
StringWriter writer = new StringWriter();
Matcher mimeMatcher = CHARSET_PATTERN.matcher(hints.mimeType);
String charset = mimeMatcher.find() ? mimeMatcher.group(1) : null;
try {
// reset position to start of stream to get full html content
stream.seek(0L);
if (charset != null)
IOUtils.copy(stream, writer, charset);
else
IOUtils.copy(stream, writer, StandardCharsets.UTF_8);
} catch (IOException ex) {
throw new FriendlyException("Could not read HTML body", SUSPICIOUS, ex);
}
String htmlBody = writer.toString();
Matcher matcher = PLAYLIST_PATTERN.matcher(htmlBody);
if (matcher.find()) {
return detectContainer(resolve(reference, matcher.group(1)), true);
}
return null;
}
use of com.sedmelluq.discord.lavaplayer.tools.FriendlyException in project FredBoat by Frederikam.
the class PlaylistImportSourceManager method loadAndParseTrackIds.
private List<String> loadAndParseTrackIds(String serviceName, String pasteId) {
String response;
try {
response = BotController.Companion.getHTTP().get(PasteServiceConstants.PASTE_SERVICE_URLS.get(serviceName) + pasteId).asString();
} catch (IOException ex) {
throw new FriendlyException("Couldn't load playlist. Either " + serviceName + " is down or the playlist does not exist.", FriendlyException.Severity.FAULT, ex);
}
String[] unfiltered = response.split("\\s");
ArrayList<String> filtered = new ArrayList<>();
for (String str : unfiltered) {
if (!str.equals("")) {
filtered.add(str);
}
}
return filtered;
}
Aggregations