Java Code Examples for com.sedmelluq.discord.lavaplayer.track.AudioReference#NO_TRACK

The following examples show how to use com.sedmelluq.discord.lavaplayer.track.AudioReference#NO_TRACK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TwitchStreamAudioSourceManager.java    From kyoko with MIT License 6 votes vote down vote up
@Override
public AudioItem loadItem(DefaultAudioPlayerManager manager, AudioReference reference) {
    String streamName = getChannelIdentifierFromUrl(reference.identifier);
    if (streamName == null) {
        return null;
    }

    JsonBrowser channelInfo = fetchChannelInfo(streamName);

    if (channelInfo == null) {
        return AudioReference.NO_TRACK;
    } else {
        final String displayName = channelInfo.get("display_name").text();
        final String status = channelInfo.get("status").text();

        return new TwitchStreamAudioTrack(new AudioTrackInfo(
                status,
                displayName,
                Long.MAX_VALUE,
                reference.identifier,
                true,
                reference.identifier
        ), this);
    }
}
 
Example 2
Source File: YoutubeAudioSourceManager.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
/**
 * Loads a single track from video ID.
 *
 * @param videoId ID of the YouTube video.
 * @param mustExist True if it should throw an exception on missing track, otherwise returns AudioReference.NO_TRACK.
 * @return Loaded YouTube track.
 */
public AudioItem loadTrackWithVideoId(String videoId, boolean mustExist) {
  try (HttpInterface httpInterface = getHttpInterface()) {
    YoutubeTrackDetails details = trackDetailsLoader.loadDetails(httpInterface, videoId);

    if (details == null) {
      if (mustExist) {
        throw new FriendlyException("Video unavailable", COMMON, null);
      } else {
        return AudioReference.NO_TRACK;
      }
    }

    return new YoutubeAudioTrack(details.getTrackInfo(), this);
  } catch (Exception e) {
    throw ExceptionTools.wrapUnfriendlyExceptions("Loading information for a YouTube track failed.", FAULT, e);
  }
}
 
Example 3
Source File: VimeoAudioSourceManager.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
private AudioItem loadFromTrackPage(HttpInterface httpInterface, String trackUrl) throws IOException {
  try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(trackUrl))) {
    int statusCode = response.getStatusLine().getStatusCode();

    if (statusCode == HttpStatus.SC_NOT_FOUND) {
      return AudioReference.NO_TRACK;
    } else if (!HttpClientTools.isSuccessWithContent(statusCode)) {
      throw new FriendlyException("Server responded with an error.", SUSPICIOUS,
          new IllegalStateException("Response code is " + statusCode));
    }

    return loadTrackFromPageContent(trackUrl, IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8));
  }
}
 
Example 4
Source File: BeamAudioSourceManager.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
@Override
public AudioItem loadItem(DefaultAudioPlayerManager manager, AudioReference reference) {
  String streamName = getChannelNameFromUrl(reference.identifier);
  if (streamName == null) {
    return null;
  }

  JsonBrowser channelInfo = fetchStreamChannelInfo(streamName);

  if (channelInfo == null) {
    return AudioReference.NO_TRACK;
  } else {
    String displayName = channelInfo.get("name").text();
    String id = getPlayedStreamId(channelInfo);

    if (displayName == null || id == null) {
      throw new IllegalStateException("Expected id and name fields from Beam channel info.");
    }

    return new BeamAudioTrack(new AudioTrackInfo(
        displayName,
        streamName,
        Units.DURATION_MS_UNKNOWN,
        id + "|" + streamName + "|" + reference.identifier,
        true,
        "https://beam.pro/" + streamName
    ), this);
  }
}
 
Example 5
Source File: SoundCloudAudioSourceManager.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
private AudioItem loadFromLikedTracks(String likedListUrl) {
  try (HttpInterface httpInterface = getHttpInterface()) {
    UserInfo userInfo = findUserIdFromLikedList(httpInterface, likedListUrl);
    if (userInfo == null) {
      return AudioReference.NO_TRACK;
    }

    return extractTracksFromLikedList(loadLikedListForUserId(httpInterface, userInfo), userInfo);
  } catch (IOException e) {
    throw new FriendlyException("Loading liked tracks from SoundCloud failed.", SUSPICIOUS, e);
  }
}
 
Example 6
Source File: YoutubeSearchProvider.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
private AudioItem extractSearchResults(Document document, String query,
                                       Function<AudioTrackInfo, AudioTrack> trackFactory) {

  List<AudioTrack> tracks = new ArrayList<>();
  Elements resultsSelection = document.select("#page > #content #results");
  if (!resultsSelection.isEmpty()) {
    for (Element results : resultsSelection) {
      for (Element result : results.select(".yt-lockup-video")) {
        if (!result.hasAttr("data-ad-impressions") && result.select(".standalone-ypc-badge-renderer-label").isEmpty()) {
          extractTrackFromResultEntry(tracks, result, trackFactory);
        }
      }
    }
  } else {
    log.debug("Attempting to parse results page as polymer");
    try {
      tracks = polymerExtractTracks(document, trackFactory);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }

  if (tracks.isEmpty()) {
    return AudioReference.NO_TRACK;
  } else {
    return new BasicAudioPlaylist("Search results for: " + query, tracks, null, true);
  }
}
 
Example 7
Source File: TwitchStreamAudioSourceManager.java    From lavaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public AudioItem loadItem(DefaultAudioPlayerManager manager, AudioReference reference) {
  String streamName = getChannelIdentifierFromUrl(reference.identifier);
  if (streamName == null) {
    return null;
  }

  JsonBrowser channelInfo = fetchStreamChannelInfo(streamName);

  if (channelInfo == null || channelInfo.get("stream").isNull()) {
    return AudioReference.NO_TRACK;
  } else {
    //Use the stream name as the display name (we would require an additional call to the user to get the true display name)
    String displayName = streamName;

    /*
    --- HELIX STUFF
    //Retrieve the data value list; this will have only one element since we're getting only one stream's information
    List<JsonBrowser> dataList = channelInfo.get("data").values();
  
    //The value list is empty if the stream is offline, even when hosting another channel
    if (dataList.size() == 0){
        return null;
    }
  
    //The first one has the title of the broadcast
    JsonBrowser channelData = dataList.get(0);
    String status = channelData.get("title").text();
     */

    JsonBrowser channelData = channelInfo.get("stream").get("channel");
    String status = channelData.get("status").text();

    return new TwitchStreamAudioTrack(new AudioTrackInfo(
        status,
        displayName,
        Units.DURATION_MS_UNKNOWN,
        reference.identifier,
        true,
        reference.identifier
    ), this);
  }
}
 
Example 8
Source File: YoutubeAudioSourceManager.java    From lavaplayer with Apache License 2.0 4 votes vote down vote up
@Override
public AudioItem none() {
  return AudioReference.NO_TRACK;
}