com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager类的一些代码示例,展示了YoutubeAudioSourceManager类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YoutubeAudioSourceManager类的具体详情如下:
包路径:com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager
类名称:YoutubeAudioSourceManager

YoutubeAudioSourceManager介绍

[英]Audio source manager that implements finding Youtube videos or playlists based on an URL or ID.
[中]音频源管理器,实现基于URL或ID查找Youtube视频或播放列表。

代码示例

代码示例来源:origin: FlareBot/FlareBot

@Override
  public AudioSourceManager newSourceManagerInstance() throws Exception {
    YoutubeAudioSourceManager manager = new YoutubeAudioSourceManager();
    manager.setPlaylistPageCount(100);
    return manager;
  }
}

代码示例来源:origin: avaire/avaire

public AudioPlayerManager registerSourceManagers(AudioPlayerManager manager) {
  manager.registerSourceManager(new PlaylistImportSourceManager());
  YoutubeAudioSourceManager youtubeAudioSourceManager = new YoutubeAudioSourceManager();
  youtubeAudioSourceManager.configureRequests(config -> RequestConfig.copy(config)
    .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
    .build());
  manager.registerSourceManager(youtubeAudioSourceManager);
  manager.registerSourceManager(new SoundCloudAudioSourceManager());
  manager.registerSourceManager(new TwitchStreamAudioSourceManager());
  manager.registerSourceManager(new BandcampAudioSourceManager());
  manager.registerSourceManager(new VimeoAudioSourceManager());
  manager.registerSourceManager(new BeamAudioSourceManager());
  manager.registerSourceManager(new LocalAudioSourceManager());
  manager.registerSourceManager(new HttpAudioSourceManager());
  return manager;
}

代码示例来源:origin: sedmelluq/lavaplayer

/**
 * Registers all built-in remote audio sources to the specified player manager. Local file audio source must be
 * registered separately.
 *
 * @param playerManager Player manager to register the source managers to
 * @param containerRegistry Media container registry to be used by any probing sources.
 */
public static void registerRemoteSources(AudioPlayerManager playerManager, MediaContainerRegistry containerRegistry) {
 playerManager.registerSourceManager(new YoutubeAudioSourceManager(true));
 playerManager.registerSourceManager(new SoundCloudAudioSourceManager());
 playerManager.registerSourceManager(new BandcampAudioSourceManager());
 playerManager.registerSourceManager(new VimeoAudioSourceManager());
 playerManager.registerSourceManager(new TwitchStreamAudioSourceManager());
 playerManager.registerSourceManager(new BeamAudioSourceManager());
 playerManager.registerSourceManager(new HttpAudioSourceManager());
}

代码示例来源:origin: sedmelluq/lavaplayer

/**
 * @param httpInterface HTTP interface to use for performing any necessary request.
 * @param videoId ID of the video.
 * @param mustExist If <code>true</code>, throws an exception instead of returning <code>null</code> if the track does
 *                  not exist.
 * @return JSON information about the track if it exists. <code>null</code> if it does not and mustExist is
 *         <code>false</code>.
 * @throws IOException On network error.
 */
public JsonBrowser getTrackInfoFromMainPage(HttpInterface httpInterface, String videoId, boolean mustExist) throws IOException {
 try (CloseableHttpResponse response = httpInterface.execute(new HttpGet(getWatchUrl(videoId)))) {
  int statusCode = response.getStatusLine().getStatusCode();
  if (statusCode != 200) {
   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, "ytplayer.config = ", ";ytplayer.load");
  if (configJson != null) {
   return JsonBrowser.parse(configJson);
  }
 }
 if (determineFailureReason(httpInterface, videoId, mustExist)) {
  return null;
 }
 // In case main page does not give player configuration, but info page indicates an OK result, it is probably an
 // age-restricted video for which the complete track info can be combined from the embed page and the info page.
 return getTrackInfoFromEmbedPage(httpInterface, videoId);
}

代码示例来源:origin: jagrosh/MusicBot

public void init()
{
  AudioSourceManagers.registerRemoteSources(this);
  AudioSourceManagers.registerLocalSource(this);
  source(YoutubeAudioSourceManager.class).setPlaylistPageCount(10);
}

代码示例来源:origin: sedmelluq/lavaplayer

/**
 * 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()) {
  JsonBrowser info = getTrackInfoFromMainPage(httpInterface, videoId, mustExist);
  if (info == null) {
   return AudioReference.NO_TRACK;
  }
  JsonBrowser args = info.get("args");
  if ("fail".equals(args.get("status").text())) {
   throw new FriendlyException(args.get("reason").text(), COMMON, null);
  }
  boolean isStream = "1".equals(args.get("live_playback").text());
  long duration = isStream ? Long.MAX_VALUE : args.get("length_seconds").as(Long.class) * 1000;
  return buildTrackObject(videoId, args.get("title").text(), args.get("author").text(), isStream, duration);
 } catch (Exception e) {
  throw ExceptionTools.wrapUnfriendlyExceptions("Loading information for a YouTube track failed.", FAULT, e);
 }
}

代码示例来源:origin: sedmelluq/lavaplayer

private AudioPlaylist loadPlaylistWithId(String playlistId, String selectedVideoId) {
 log.debug("Starting to load playlist with ID {}", playlistId);
 try (HttpInterface httpInterface = getHttpInterface()) {
  try (CloseableHttpResponse response = httpInterface.execute(new HttpGet("https://www.youtube.com/playlist?list=" + playlistId))) {
   int statusCode = response.getStatusLine().getStatusCode();
   if (statusCode != 200) {
    throw new IOException("Invalid status code for playlist response: " + statusCode);
   }
   Document document = Jsoup.parse(response.getEntity().getContent(), CHARSET, "");
   return buildPlaylist(httpInterface, document, selectedVideoId);
  }
 } catch (Exception e) {
  throw ExceptionTools.wrapUnfriendlyExceptions(e);
 }
}

代码示例来源:origin: sedmelluq/lavaplayer

private void extractTrackFromResultEntry(List<AudioTrack> tracks, Element element) {
 Element durationElement = element.select("[class^=video-time]").first();
 Element contentElement = element.select(".yt-lockup-content").first();
 String videoId = element.attr("data-context-item-id");
 if (durationElement == null || contentElement == null || videoId.isEmpty()) {
  return;
 }
 long duration = DataFormatTools.durationTextToMillis(durationElement.text());
 String title = contentElement.select(".yt-lockup-title > a").text();
 String author = contentElement.select(".yt-lockup-byline > a").text();
 tracks.add(sourceManager.buildTrackObject(videoId, title, author, false, duration));
}

代码示例来源:origin: sedmelluq/lavaplayer

private boolean determineFailureReason(HttpInterface httpInterface, String videoId, boolean mustExist) throws IOException {
 try (CloseableHttpResponse response = httpInterface.execute(new HttpGet("https://www.youtube.com/get_video_info?hl=en_GB&video_id=" + videoId))) {
  int statusCode = response.getStatusLine().getStatusCode();
  if (statusCode != 200) {
   throw new IOException("Invalid status code for video info response: " + statusCode);
  }
  Map<String, String> format = convertToMapLayout(URLEncodedUtils.parse(response.getEntity()));
  return determineFailureReasonFromStatus(format.get("status"), format.get("reason"), mustExist);
 }
}

代码示例来源:origin: sedmelluq/lavaplayer

private String extractPlaylistTracks(Element videoContainer, Element loadMoreContainer, List<AudioTrack> tracks) {
 for (Element video : videoContainer.select(".pl-video")) {
  Elements lengthElements = video.select(".timestamp span");
  // If the timestamp element does not exist, it means the video is private
  if (!lengthElements.isEmpty()) {
   String videoId = video.attr("data-video-id").trim();
   String title = video.attr("data-title").trim();
   String author = video.select(".pl-video-owner a").text().trim();
   long duration = DataFormatTools.durationTextToMillis(lengthElements.first().text());
   tracks.add(buildTrackObject(videoId, title, author, false, duration));
  }
 }
 if (loadMoreContainer != null) {
  Elements more = loadMoreContainer.select(".load-more-button");
  if (!more.isEmpty()) {
   return more.first().attr("data-uix-load-more-href");
  }
 }
 return null;
}

代码示例来源:origin: FlareBot/FlareBot

@Override
  public AudioSourceManager newSourceManagerInstance() throws Exception {
    YoutubeAudioSourceManager manager = new YoutubeAudioSourceManager();
    manager.setPlaylistPageCount(100);
    return manager;
  }
}

代码示例来源:origin: FlareBot/FlareBot

@Override
  public AudioSourceManager newSourceManagerInstance() throws Exception {
    YoutubeAudioSourceManager manager = new YoutubeAudioSourceManager();
    manager.setPlaylistPageCount(100);
    return manager;
  }
}

代码示例来源:origin: FlareBot/FlareBot

@Override
  public AudioSourceManager newSourceManagerInstance() throws Exception {
    YoutubeAudioSourceManager manager = new YoutubeAudioSourceManager();
    manager.setPlaylistPageCount(100);
    return manager;
  }
}

代码示例来源:origin: dabbotorg/java-music-bot

YoutubeAudioSourceManager youtubeAudioSourceManager = new YoutubeAudioSourceManager();
if (bot.getConfigs().config.patreon) {
  youtubeAudioSourceManager.setPlaylistPageCount(25);

相关文章