Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Stream Branch to Main Branch #14

Merged
merged 36 commits into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
515fda2
✨ Added Basic Stream Support for Library (Need to Add for Plugin)
PulseBeat02 Sep 23, 2021
639f79c
✨ Fixed Bug in BotConfiguration
PulseBeat02 Sep 23, 2021
dedb78a
✨ Added Stream Support for Plugin (Supposedly Working, Need to Test +…
PulseBeat02 Sep 23, 2021
bedbf94
🐛 Fixed NullPointerException + Changed Message (From Master)
PulseBeat02 Sep 23, 2021
5edc309
🐛 Fixed a Ton of Video Bugs
PulseBeat02 Sep 23, 2021
62c73e7
Merge branch 'stream' of https://github.com/MinecraftMediaLibrary/EzM…
PulseBeat02 Sep 23, 2021
d25e5a0
🐛 Added Support for All youtube-dl Videos!
PulseBeat02 Sep 24, 2021
3b234fc
✨ Worked on Discord Bot
PulseBeat02 Sep 24, 2021
29094c5
✨ Discord Bot Plays Music Now
PulseBeat02 Sep 24, 2021
7c75913
✨ Some Stream Issues... Will Fix Soon
PulseBeat02 Sep 24, 2021
f8b5bc9
Merge branch 'stream' of https://github.com/MinecraftMediaLibrary/EzM…
PulseBeat02 Sep 25, 2021
a3b1761
🐛 One Step Closer to Streams...
PulseBeat02 Sep 25, 2021
81b45be
✨ Experimental Commit
PulseBeat02 Sep 25, 2021
fec1a2f
✨ HTTP Stream Support Works!
PulseBeat02 Sep 25, 2021
6f4e913
✨ Fixed Normal Video Issue
PulseBeat02 Sep 25, 2021
e273ba9
🐛 Fixed Windows Bug + URL Component Bug
PulseBeat02 Sep 26, 2021
14ff9f6
✨ Removed Unnecessary Class
PulseBeat02 Sep 26, 2021
92566b8
✨ Added Support for More Platforms + Cleaned Up Links
PulseBeat02 Sep 26, 2021
d158eaa
Merge branch 'stream' of https://github.com/MinecraftMediaLibrary/EzM…
PulseBeat02 Sep 26, 2021
0dfab25
✨ Cleaned Up Code
PulseBeat02 Sep 27, 2021
37256bd
✨ Refactored Some Code
PulseBeat02 Sep 27, 2021
702b4d9
✨ Fixed CompletableFuture Bug - Still Many Need to Fix
PulseBeat02 Sep 28, 2021
f912584
🐛 HTTP Live Stream Bug Fixed
PulseBeat02 Sep 29, 2021
5e23422
🐛 Added Thread Dump Command + Properly Released VLC Players
PulseBeat02 Sep 29, 2021
1c76291
🐛 Patched FFmpegMediaPlayer + Linux Support Fixed
PulseBeat02 Sep 30, 2021
db5af6b
🐛 Patched FFmpegMediaPlayer Bug
PulseBeat02 Sep 30, 2021
43ce191
✨ General Logger Improvements
PulseBeat02 Sep 30, 2021
b326724
🐛 Fixed Public Port Issue on Linux
PulseBeat02 Sep 30, 2021
9c93e02
🐛 Fixed Log Output
PulseBeat02 Sep 30, 2021
79a08e3
🐛 Overrided Progress Listener
PulseBeat02 Sep 30, 2021
1856179
✨ Update README.md
PulseBeat02 Oct 1, 2021
9a6a386
🐛 Added Support for Normal Video Playback in HTTP Stream
PulseBeat02 Oct 1, 2021
05a7038
✨ Disallowed Users from Using Buggy Discord Bot Feature
PulseBeat02 Oct 1, 2021
efd543d
Merge branch 'stream' of https://github.com/MinecraftMediaLibrary/EzM…
PulseBeat02 Oct 1, 2021
bea38be
✨ Added Clauses to Switch Statement
PulseBeat02 Oct 1, 2021
fb5106a
✨ Added Licensing
PulseBeat02 Oct 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✨ HTTP Stream Support Works!
  • Loading branch information
PulseBeat02 committed Sep 25, 2021
commit fec1a2fe9722ec37b5ceaff1c1393851ec12f281
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public interface MediaLibraryCore {

void setFFmpegPath(@NotNull final Path path);

@NotNull
Path getRTPPath();

void setRTPPath(@NotNull final Path path);

@NotNull
Diagnostic getDiagnostics();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ public interface Diagnostic {
@NotNull
String getVlcUrl();

/**
* Gets the proper RTP installation link based on the current server hardware.
*
* @return the RTP installation url
*/
@NotNull
String getRtpUrl();

/**
* Gets the information surrounding the Operating System.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface EnhancedExecution {
public interface EnhancedExecution extends AutoCloseable {

void execute();

Expand All @@ -47,7 +47,5 @@ public interface EnhancedExecution {
CompletableFuture<Void> executeAsyncWithLogging(
@NotNull final Consumer<String> logger, @NotNull final Executor executor);

void cancelProcess();

boolean isCancelled();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* MIT License
*
* Copyright (c) 2021 Brandon Li
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.pulsebeat02.ezmediacore.rtp;

import io.github.pulsebeat02.ezmediacore.ffmpeg.EnhancedExecution;
import org.jetbrains.annotations.NotNull;

public interface StreamingServer extends EnhancedExecution {

@NotNull
String getAddress();
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@
import io.github.pulsebeat02.deluxemediaplugin.command.video.VideoCommandAttributes;
import io.github.pulsebeat02.deluxemediaplugin.config.BotConfiguration;
import io.github.pulsebeat02.deluxemediaplugin.config.EncoderConfiguration;
import io.github.pulsebeat02.deluxemediaplugin.config.HttpAudioConfiguration;
import io.github.pulsebeat02.deluxemediaplugin.config.HttpConfiguration;
import io.github.pulsebeat02.deluxemediaplugin.config.PersistentPictureManager;
import io.github.pulsebeat02.deluxemediaplugin.config.ServerInfo;
import io.github.pulsebeat02.deluxemediaplugin.update.UpdateChecker;
import io.github.pulsebeat02.deluxemediaplugin.utility.CommandUtils;
import io.github.pulsebeat02.ezmediacore.LibraryProvider;
Expand Down Expand Up @@ -76,6 +78,7 @@ public final class DeluxeMediaPlugin {
private AudioConfiguration audioConfiguration;
private HttpServer server;
private MediaBot mediaBot;
private ServerInfo httpAudioServer;

private VideoCommandAttributes attributes;

Expand Down Expand Up @@ -141,7 +144,7 @@ private void printLogo() {
}
}

public void disable() {
public void disable() throws Exception {
this.log("DeluxeMediaPlugin is shutting down!");

if (this.library != null) {
Expand All @@ -163,12 +166,12 @@ public void disable() {

final EnhancedExecution extractor = this.attributes.getExtractor();
if (extractor != null) {
extractor.cancelProcess();
extractor.close();
}

final EnhancedExecution streamExtractor = this.attributes.getStreamExtractor();
if (streamExtractor != null) {
streamExtractor.cancelProcess();
streamExtractor.close();
}

this.log("Good Bye :(");
Expand All @@ -181,12 +184,15 @@ private void loadPersistentData() {
final HttpConfiguration httpConfiguration = new HttpConfiguration(this);
final EncoderConfiguration encoderConfiguration = new EncoderConfiguration(this);
final BotConfiguration botConfiguration = new BotConfiguration(this);
final HttpAudioConfiguration audioConfiguration = new HttpAudioConfiguration(this);
httpConfiguration.read();
encoderConfiguration.read();
botConfiguration.read();
audioConfiguration.read();
this.server = httpConfiguration.getSerializedValue();
this.audioConfiguration = encoderConfiguration.getSerializedValue();
this.mediaBot = botConfiguration.getSerializedValue();
this.httpAudioServer = audioConfiguration.getSerializedValue();
this.manager = new PersistentPictureManager(this);
this.manager.startTask();
} catch (final IOException e) {
Expand Down Expand Up @@ -238,12 +244,16 @@ private void registerCommands() {
return this.audiences;
}

public VideoCommandAttributes getAttributes() {
public @NotNull VideoCommandAttributes getAttributes() {
return this.attributes;
}

public void setAttributes(
@NotNull final VideoCommandAttributes attributes) {
this.attributes = attributes;
}

public @NotNull ServerInfo getHttpAudioServer() {
return this.httpAudioServer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public void onEnable() {

@Override
public void onDisable() {
this.plugin.disable();
try {
this.plugin.disable();
} catch (final Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
/*
* MIT License
*
* Copyright (c) 2021 Brandon Li
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.pulsebeat02.deluxemediaplugin.bot.audio;

import java.nio.ByteBuffer;
Expand All @@ -6,8 +29,6 @@

public class AudioByteHandler implements AudioSendHandler {



@Override
public boolean canProvide() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@

public enum AudioOutputType {
RESOURCEPACK,
DISCORD;
DISCORD,
HTTP;

private static final Map<String, AudioOutputType> KEYS;

static {
KEYS =
Map.of(
"RESOURCEPACK", RESOURCEPACK,
"DISCORD", DISCORD);
"DISCORD", DISCORD,
"HTTP", HTTP);
}

public static @NotNull Optional<AudioOutputType> ofKey(@NotNull final String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@
import static io.github.pulsebeat02.deluxemediaplugin.utility.ChatUtils.red;
import static java.util.Map.entry;
import static net.kyori.adventure.text.Component.text;
import static net.kyori.adventure.text.event.ClickEvent.openUrl;
import static net.kyori.adventure.text.format.NamedTextColor.AQUA;
import static net.kyori.adventure.text.format.NamedTextColor.GOLD;
import static net.kyori.adventure.text.format.NamedTextColor.RED;
import static net.kyori.adventure.text.format.Style.style;
import static net.kyori.adventure.text.format.TextDecoration.BOLD;
import static net.kyori.adventure.text.format.TextDecoration.UNDERLINED;

import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.tree.LiteralCommandNode;
import io.github.pulsebeat02.deluxemediaplugin.DeluxeMediaPlugin;
import io.github.pulsebeat02.deluxemediaplugin.bot.MediaBot;
import io.github.pulsebeat02.deluxemediaplugin.bot.audio.MusicManager;
import io.github.pulsebeat02.deluxemediaplugin.command.BaseCommand;
import io.github.pulsebeat02.deluxemediaplugin.config.ServerInfo;
import io.github.pulsebeat02.deluxemediaplugin.utility.ChatUtils;
import io.github.pulsebeat02.ezmediacore.ffmpeg.EnhancedExecution;
import io.github.pulsebeat02.ezmediacore.ffmpeg.FFmpegAudioTrimmer;
Expand All @@ -48,7 +55,6 @@
import io.github.pulsebeat02.ezmediacore.player.VideoPlayer;
import io.github.pulsebeat02.ezmediacore.resourcepack.ResourcepackSoundWrapper;
import io.github.pulsebeat02.ezmediacore.resourcepack.hosting.HttpServer;
import io.github.pulsebeat02.ezmediacore.utility.FastStringUtils;
import io.github.pulsebeat02.ezmediacore.utility.HashingUtils;
import io.github.pulsebeat02.ezmediacore.utility.RequestUtils;
import io.github.pulsebeat02.ezmediacore.utility.ResourcepackUtils;
Expand Down Expand Up @@ -154,63 +160,65 @@ private int playVideo(@NotNull final CommandContext<CommandSender> context) {
p.playSound(p.getLocation(), sound, SoundCategory.MASTER, 100.0F, 1.0F);
}
});
case DISCORD -> player.setCustomAudioPlayback((mrl) -> {
case DISCORD, HTTP -> player.setCustomAudioPlayback((mrl) -> {
});
default -> throw new IllegalArgumentException("Illegal Audio Output!");
}

final String mrl = this.attributes.getVideoMrl().getMrl();
if (this.attributes.getAudioOutputType() == AudioOutputType.DISCORD) {
CompletableFuture.runAsync(() -> {
final EnhancedExecution process = this.attributes.getStreamExtractor();
if (process != null) {
try {
process.close();
} catch (final Exception e) {
e.printStackTrace();
}
}

final String mrl = this.attributes.getVideoMrl().getMrl();
switch (this.attributes.getAudioOutputType()) {
case DISCORD -> {
final MediaBot bot = plugin.getMediaBot();
final MusicManager manager = bot.getMusicManager();
manager.destroyTrack();
final EnhancedExecution process = this.attributes.getStreamExtractor();
if (process != null) {
process.cancelProcess();
}

final String url = "udp://localhost:1234/audio.ogg";
final FFmpegMediaStreamer extractor = new FFmpegMediaStreamer(
player.getCore(),
plugin.getAudioConfiguration(),
RequestUtils.getAudioURLs(mrl).get(0),
url);
this.attributes.setStreamExtractor(extractor);
extractor.executeAsync();

manager.joinVoiceChannel();
manager.addTrack(url);

//manager.addTrack(url);
this.attributes.getPlayer().setPlayerState(PlayerControls.START, this.attributes.getVideoMrl());
}
case HTTP -> {
final ServerInfo info = plugin.getHttpAudioServer();
final FFmpegMediaStreamer streamer = new FFmpegMediaStreamer(
plugin.library(), plugin.getAudioConfiguration(), RequestUtils.getAudioURLs(this.attributes.getVideoMrl().getMrl()).get(0), info.getIp(), info.getPort());
this.attributes.setStreamExtractor(streamer);
streamer.executeAsync();
Bukkit.getOnlinePlayers().parallelStream()
.forEach(
p ->
plugin
.audience()
.player(p)
.sendMessage(
text()
.append(text("Click ", GOLD))
.append(
text(
"this message",
style(
AQUA,
BOLD,
UNDERLINED,
openUrl(streamer.getOutput()),
text("Click to get the link!", GOLD)
.asHoverEvent())))
.append(text(" to retrieve the audio HTTP link!", GOLD))
.build()));
this.attributes.getPlayer().setPlayerState(PlayerControls.START, mrl);

});
} else {
this.attributes.getPlayer().setPlayerState(PlayerControls.START, mrl);
}

return SINGLE_SUCCESS;
}

private final Set<String> keywords = Set.of("youtube", "soundcloud", "bandcamp", "vimeo",
"twitch");
private final Set<String> extensions = Set.of("mp3", "flac", "wav", "mkv", "webm", "mp4", "m4a",
"ogg", "aac", "m3u", "pls");

private boolean isSupported(@NotNull final MrlConfiguration configuration) {
final String mrl = configuration.getMrl().toLowerCase(Locale.ROOT);
for (final String str : this.keywords) {
if (FastStringUtils.fastQuerySearch(mrl, str) != -1) {
return true;
}
default -> throw new IllegalArgumentException("Illegal Audio Output!");
}
for (final String str : this.extensions) {
if (FastStringUtils.fastQuerySearch(mrl, str) != -1) {
return true;
}
if (this.attributes.getAudioOutputType() == AudioOutputType.RESOURCEPACK) {
this.attributes.getPlayer().setPlayerState(PlayerControls.START, mrl);
}
return false;
return SINGLE_SUCCESS;
}

private int stopVideo(@NotNull final CommandContext<CommandSender> context) {
Expand All @@ -226,7 +234,11 @@ private int stopVideo(@NotNull final CommandContext<CommandSender> context) {
bot.getMusicManager().pauseTrack();
final EnhancedExecution process = this.attributes.getStreamExtractor();
if (process != null) {
process.cancelProcess();
try {
process.close();
} catch (final Exception e) {
e.printStackTrace();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ public EnhancedExecution getStreamExtractor() {
return this.streamExtractor;
}

public void setStreamExtractor(
final EnhancedExecution streamExtractor) {
public void setStreamExtractor(final EnhancedExecution streamExtractor) {
this.streamExtractor = streamExtractor;
}
}
Loading