com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager Java Examples

The following examples show how to use com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager. 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: SoundPlayerImpl.java    From DiscordSoundboard with Apache License 2.0 6 votes vote down vote up
private void init() {
    loadProperties();
    initializeDiscordBot();
    updateFileList();
    getUsers();

    playerManager = new DefaultAudioPlayerManager();
    playerManager.registerSourceManager(new LocalAudioSourceManager());
    playerManager.registerSourceManager(new YoutubeAudioSourceManager());
    playerManager.registerSourceManager(new VimeoAudioSourceManager());
    playerManager.registerSourceManager(new SoundCloudAudioSourceManager());

    musicPlayer = playerManager.createPlayer();
    musicPlayer.setVolume(75);

    leaveAfterPlayback = Boolean.parseBoolean(appProperties.getProperty("leaveAfterPlayback"));

    ConnectorNativeLibLoader.loadConnectorLibrary();

    initialized = true;
}
 
Example #2
Source File: BotApplicationManager.java    From lavaplayer with Apache License 2.0 6 votes vote down vote up
public BotApplicationManager() {
  guildContexts = new HashMap<>();
  controllerManager = new BotControllerManager();

  controllerManager.registerController(new MusicController.Factory());

  playerManager = new DefaultAudioPlayerManager();
  //playerManager.useRemoteNodes("localhost:8080");
  playerManager.getConfiguration().setResamplingQuality(AudioConfiguration.ResamplingQuality.LOW);
  playerManager.registerSourceManager(new YoutubeAudioSourceManager());
  playerManager.registerSourceManager(SoundCloudAudioSourceManager.createDefault());
  playerManager.registerSourceManager(new BandcampAudioSourceManager());
  playerManager.registerSourceManager(new VimeoAudioSourceManager());
  playerManager.registerSourceManager(new TwitchStreamAudioSourceManager());
  playerManager.registerSourceManager(new BeamAudioSourceManager());
  playerManager.registerSourceManager(new HttpAudioSourceManager());
  playerManager.registerSourceManager(new LocalAudioSourceManager());

  executorService = Executors.newScheduledThreadPool(1, new DaemonThreadFactory("bot"));
}
 
Example #3
Source File: JbAudioPlayerManagerImpl.java    From JuniperBot with GNU General Public License v3.0 6 votes vote down vote up
@PostConstruct
public void init() {
    WorkerProperties.Audio configuration = workerProperties.getAudio();
    getConfiguration().setResamplingQuality(AudioConfiguration.ResamplingQuality
            .valueOf(configuration.getResamplingQuality()));
    setFrameBufferDuration(configuration.getFrameBufferDuration());
    setItemLoaderThreadPoolSize(configuration.getItemLoaderThreadPoolSize());
    registerSourceManager(new YoutubeAudioSourceManager(true));
    registerSourceManager(new SoundCloudAudioSourceManager());
    registerSourceManager(new BandcampAudioSourceManager());
    registerSourceManager(new VimeoAudioSourceManager());
    registerSourceManager(new TwitchStreamAudioSourceManager());
    registerSourceManager(new BeamAudioSourceManager());
    if (CollectionUtils.isNotEmpty(audioSourceManagers)) {
        audioSourceManagers.forEach(this::registerSourceManager);
    }
}
 
Example #4
Source File: MusicManager.java    From Shadbot with GNU General Public License v3.0 6 votes vote down vote up
private MusicManager() {
    this.audioPlayerManager = new DefaultAudioPlayerManager();
    this.audioPlayerManager.getConfiguration().setFrameBufferFactory(NonAllocatingAudioFrameBuffer::new);
    this.audioPlayerManager.getConfiguration().setFilterHotSwapEnabled(true);
    AudioSourceManagers.registerRemoteSources(this.audioPlayerManager);
    this.guildMusics = new ConcurrentHashMap<>();
    this.guildJoining = new ConcurrentHashMap<>();

    //IPv6 rotation config
    final String ipv6Block = CredentialManager.getInstance().get(Credential.IPV6_BLOCK);
    if (!Config.IS_SNAPSHOT && ipv6Block != null && !ipv6Block.isBlank()) {
        LOGGER.info("Configuring YouTube IP rotator");
        final List<IpBlock> blocks = Collections.singletonList(new Ipv6Block(ipv6Block));
        final AbstractRoutePlanner planner = new RotatingNanoIpRoutePlanner(blocks);

        new YoutubeIpRotatorSetup(planner)
                .forSource(this.audioPlayerManager.source(YoutubeAudioSourceManager.class))
                .setup();
    }
}
 
Example #5
Source File: SpotifyAudioSourceManager.java    From SkyBot with GNU Affero General Public License v3.0 6 votes vote down vote up
public SpotifyAudioSourceManager(YoutubeAudioSourceManager youtubeAudioSourceManager, DunctebotConfig.Apis config) {
    this.config = config;

    final String clientId = config.spotify.clientId;
    final String clientSecret = config.spotify.clientSecret;
    final String youtubeApiKey = config.googl;

    if (clientId == null || clientSecret == null || youtubeApiKey == null) {
        logger.error("Could not load Spotify keys");
        this.spotifyApi = null;
        this.service = null;
        this.youtubeAudioSourceManager = null;
    } else {
        this.youtubeAudioSourceManager = youtubeAudioSourceManager;
        this.spotifyApi = new SpotifyApi.Builder()
            .setClientId(clientId)
            .setClientSecret(clientSecret)
            .build();

        this.service = Executors.newScheduledThreadPool(2, (r) -> new Thread(r, "Spotify-Token-Update-Thread"));
        service.scheduleAtFixedRate(this::updateAccessToken, 0, 1, TimeUnit.HOURS);
    }
}
 
Example #6
Source File: PlayerControl.java    From Yui with Apache License 2.0 5 votes vote down vote up
public PlayerControl()
{
    java.util.logging.Logger.getLogger("org.apache.http.client.protocol.ResponseProcessCookies").setLevel(Level.OFF);

    this.playerManager = new DefaultAudioPlayerManager();
    playerManager.registerSourceManager(new YoutubeAudioSourceManager());
    playerManager.registerSourceManager(new SoundCloudAudioSourceManager());
    playerManager.registerSourceManager(new BandcampAudioSourceManager());
    playerManager.registerSourceManager(new VimeoAudioSourceManager());
    playerManager.registerSourceManager(new TwitchStreamAudioSourceManager());
    playerManager.registerSourceManager(new HttpAudioSourceManager());
    playerManager.registerSourceManager(new LocalAudioSourceManager());

    musicManagers = new HashMap<String, GuildMusicManager>();
}
 
Example #7
Source File: YoutubeIpRotatorSetup.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
public YoutubeIpRotatorSetup forManager(AudioPlayerManager playerManager) {
  YoutubeAudioSourceManager sourceManager = playerManager.source(YoutubeAudioSourceManager.class);

  if (sourceManager != null) {
    forSource(sourceManager);
  }

  return this;
}
 
Example #8
Source File: AudioSourceManagers.java    From lavaplayer with Apache License 2.0 5 votes vote down vote up
/**
 * 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(SoundCloudAudioSourceManager.createDefault());
  playerManager.registerSourceManager(new BandcampAudioSourceManager());
  playerManager.registerSourceManager(new VimeoAudioSourceManager());
  playerManager.registerSourceManager(new TwitchStreamAudioSourceManager());
  playerManager.registerSourceManager(new BeamAudioSourceManager());
  playerManager.registerSourceManager(new GetyarnAudioSourceManager());
  playerManager.registerSourceManager(new HttpAudioSourceManager(containerRegistry));
}
 
Example #9
Source File: Andesite.java    From andesite-node with MIT License 5 votes vote down vote up
private static void configureYt(@Nonnull AudioPlayerManager manager, @Nonnull Config config) {
    var yt = manager.source(YoutubeAudioSourceManager.class);
    if(yt == null) {
        return;
    }
    yt.setPlaylistPageCount(config.getInt("lavaplayer.youtube.max-playlist-page-count"));
    yt.setMixLoaderMaximumPoolSize(config.getInt("lavaplayer.youtube.mix-loader-max-pool-size"));
}
 
Example #10
Source File: YoutubeUtils.java    From SkyBot with GNU Affero General Public License v3.0 4 votes vote down vote up
public static YoutubeAudioTrack videoToTrack(Video video, YoutubeAudioSourceManager sourceManager) {
    return new YoutubeAudioTrack(videoToTrackInfo(video), sourceManager);
}
 
Example #11
Source File: MantaroAudioManager.java    From MantaroBot with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
public MantaroAudioManager() {
    this.musicManagers = new ConcurrentHashMap<>();
    this.playerManager = new DefaultAudioPlayerManager();

    //Youtube is special because rotation stuff.
    YoutubeAudioSourceManager youtubeAudioSourceManager = new YoutubeAudioSourceManager(true);

    //IPv6 rotation config start
    Config config = MantaroData.config().get();
    if (!config.getIpv6Block().isEmpty()) {
        AbstractRoutePlanner planner;
        String block = config.getIpv6Block();
        List<IpBlock> blocks = Collections.singletonList(new Ipv6Block(block));

        //Damn you, YouTube.
        if (config.getExcludeAddress().isEmpty())
            planner = new RotatingNanoIpRoutePlanner(blocks);
        else {
            try {
                InetAddress blacklistedGW = InetAddress.getByName(config.getExcludeAddress());
                planner = new RotatingNanoIpRoutePlanner(blocks, inetAddress -> !inetAddress.equals(blacklistedGW));
            } catch (Exception e) {
                //Fallback: did I screw up putting the IP in? lmao
                planner = new RotatingNanoIpRoutePlanner(blocks);
                e.printStackTrace();
            }
        }

        new YoutubeIpRotatorSetup(planner)
                .forSource(youtubeAudioSourceManager)
                .setup();
    }
    //IPv6 rotation config end

    //Register source manager and configure the Player
    playerManager.registerSourceManager(youtubeAudioSourceManager);
    playerManager.registerSourceManager(SoundCloudAudioSourceManager.createDefault());
    playerManager.registerSourceManager(new BandcampAudioSourceManager());
    playerManager.registerSourceManager(new VimeoAudioSourceManager());
    playerManager.registerSourceManager(new TwitchStreamAudioSourceManager());
    playerManager.registerSourceManager(new BeamAudioSourceManager());
    if (!ExtraRuntimeOptions.DISABLE_NON_ALLOCATING_BUFFER) {
        log.info("Enabled non-allocating audio buffer.");
        playerManager.getConfiguration().setFrameBufferFactory(NonAllocatingAudioFrameBuffer::new);
    }
}
 
Example #12
Source File: MusicController.java    From lavaplayer with Apache License 2.0 4 votes vote down vote up
@BotCommandHandler
private void hex(Message message, int pageCount) {
  manager.source(YoutubeAudioSourceManager.class).setPlaylistPageCount(pageCount);
}
 
Example #13
Source File: YoutubeIpRotatorSetup.java    From lavaplayer with Apache License 2.0 4 votes vote down vote up
public YoutubeIpRotatorSetup forSource(YoutubeAudioSourceManager sourceManager) {
  forConfiguration(sourceManager.getMainHttpConfiguration(), false);
  forConfiguration(sourceManager.getSearchHttpConfiguration(), true);
  return this;
}
 
Example #14
Source File: SpotifyAudioTrack.java    From SkyBot with GNU Affero General Public License v3.0 4 votes vote down vote up
SpotifyAudioTrack(AudioTrackInfo trackInfo, YoutubeAudioSourceManager sourceManager) {
    super(trackInfo, sourceManager);
}
 
Example #15
Source File: SavedPlaylistExtractor.java    From FlareBot with MIT License 4 votes vote down vote up
@Override
public AudioSourceManager newSourceManagerInstance() throws Exception {
    YoutubeAudioSourceManager manager = new YoutubeAudioSourceManager();
    manager.setPlaylistPageCount(100);
    return manager;
}
 
Example #16
Source File: SavedPlaylistExtractor.java    From FlareBot with MIT License 4 votes vote down vote up
@Override
public Class<? extends AudioSourceManager> getSourceManagerClass() {
    return YoutubeAudioSourceManager.class;
}
 
Example #17
Source File: RandomExtractor.java    From FlareBot with MIT License 4 votes vote down vote up
@Override
public AudioSourceManager newSourceManagerInstance() throws Exception {
    YoutubeAudioSourceManager manager = new YoutubeAudioSourceManager();
    manager.setPlaylistPageCount(100);
    return manager;
}
 
Example #18
Source File: RandomExtractor.java    From FlareBot with MIT License 4 votes vote down vote up
@Override
public Class<? extends AudioSourceManager> getSourceManagerClass() {
    return YoutubeAudioSourceManager.class;
}
 
Example #19
Source File: YouTubeSearchExtractor.java    From FlareBot with MIT License 4 votes vote down vote up
@Override
public AudioSourceManager newSourceManagerInstance() throws Exception {
    YoutubeAudioSourceManager manager = new YoutubeAudioSourceManager();
    manager.setPlaylistPageCount(100);
    return manager;
}
 
Example #20
Source File: YouTubeExtractor.java    From FlareBot with MIT License 4 votes vote down vote up
@Override
public AudioSourceManager newSourceManagerInstance() throws Exception {
    YoutubeAudioSourceManager manager = new YoutubeAudioSourceManager();
    manager.setPlaylistPageCount(100);
    return manager;
}
 
Example #21
Source File: YouTubeExtractor.java    From FlareBot with MIT License 4 votes vote down vote up
@Override
public Class<? extends AudioSourceManager> getSourceManagerClass() {
    return YoutubeAudioSourceManager.class;
}
 
Example #22
Source File: SpotifyAudioTrack.java    From kyoko with MIT License 4 votes vote down vote up
public SpotifyAudioTrack(AudioTrackInfo trackInfo, YoutubeAudioSourceManager manager) {
    super(trackInfo);
    this.manager = manager;
}
 
Example #23
Source File: SpotifyAudioSourceManager.java    From kyoko with MIT License 4 votes vote down vote up
public SpotifyAudioSourceManager(SpotifyCredentials credentials, YoutubeAudioSourceManager youtubeManager) {
    this.api = SpotifyApi.builder().setClientId(credentials.id).setClientSecret(credentials.secret).build();
    this.youtubeManager = youtubeManager;
    this.loaders = Arrays.asList(this::getSpotifyTrack, this::getSpotifyAlbum, this::getSpotifyPlaylist);
}
 
Example #24
Source File: LocalPlayerWrapper.java    From kyoko with MIT License 4 votes vote down vote up
private boolean canChangeSpeed(AudioTrack track) {
    if (track == null) return false;
    if (track.getSourceManager() instanceof YoutubeAudioSourceManager && track.getDuration() == Long.MAX_VALUE)
        return false;
    return !(track.getSourceManager() instanceof TwitchStreamAudioSourceManager);
}