diff --git a/.idea/.idea.SethDiscordBot/.idea/.name b/.idea/.idea.SethDiscordBot/.idea/.name new file mode 100644 index 0000000..ac07819 --- /dev/null +++ b/.idea/.idea.SethDiscordBot/.idea/.name @@ -0,0 +1 @@ +SethDiscordBot \ No newline at end of file diff --git a/.idea/.idea.SethDiscordBot/.idea/encodings.xml b/.idea/.idea.SethDiscordBot/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.SethDiscordBot/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.SethDiscordBot/.idea/indexLayout.xml b/.idea/.idea.SethDiscordBot/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.SethDiscordBot/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.SethDiscordBot/.idea/vcs.xml b/.idea/.idea.SethDiscordBot/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.SethDiscordBot/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/YoutubeExtension/Others/Data.cs b/YoutubeExtension/Others/Data.cs new file mode 100644 index 0000000..ef50961 --- /dev/null +++ b/YoutubeExtension/Others/Data.cs @@ -0,0 +1,12 @@ +using Discord; +using Discord.Audio; + +namespace YoutubeExtension.Downloader; + +internal static class Data +{ + internal static IAudioClient audioClient = null; + internal static IVoiceChannel voiceChannel = null; + + internal static MusicPlayer CurrentlyRunning = null; +} diff --git a/YoutubeExtension/Others/MusicPlayer.cs b/YoutubeExtension/Others/MusicPlayer.cs new file mode 100644 index 0000000..bfbafd9 --- /dev/null +++ b/YoutubeExtension/Others/MusicPlayer.cs @@ -0,0 +1,50 @@ +namespace YoutubeExtension.Downloader; + +internal class MusicPlayer +{ + public MusicPlayer(Stream input, Stream output) + { + inputStream = input; + outputStream = output; + } + + public Stream inputStream { get; } // from outside + public Stream outputStream { get; } // to Voice Channel + + public bool Paused { get; set; } + private bool _stop { get; set; } + + public void Stop() + { + _stop = true; + } + + public async Task StartSendAudio() + { + Paused = false; + _stop = false; + while (!_stop) + { + if (Paused) continue; + var bsize = 512; + var buffer = new byte[bsize]; + var bcount = await inputStream.ReadAsync(buffer, 0, bsize); + if (bcount <= 0) + { + Stop(); + Data.CurrentlyRunning = null; + break; + } + + try + { + await outputStream.WriteAsync(buffer, 0, bcount); + } + catch (Exception ex) + { + await outputStream.FlushAsync(); + PluginManager.Others.Functions.WriteLogFile(ex.ToString()); + } + } + } +} diff --git a/YoutubeExtension/Others/YTVideo.cs b/YoutubeExtension/Others/YTVideo.cs new file mode 100644 index 0000000..36bc4f9 --- /dev/null +++ b/YoutubeExtension/Others/YTVideo.cs @@ -0,0 +1,18 @@ +using MediaToolkit; +using MediaToolkit.Model; +using VideoLibrary; + +namespace YoutubeExtension.Downloader; + +public class YoutubeHandler +{ + + public static async Task GetVideoStream(string videoURL) + { + var youtube = YouTube.Default; + var video = await youtube.GetVideoAsync(videoURL); + + return await video.StreamAsync(); + + } +} diff --git a/YoutubeExtension/YoutubeExtension.csproj b/YoutubeExtension/YoutubeExtension.csproj new file mode 100644 index 0000000..eb2460e --- /dev/null +++ b/YoutubeExtension/YoutubeExtension.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/YoutubeExtension/ytPlay.cs b/YoutubeExtension/ytPlay.cs new file mode 100644 index 0000000..8e71e2a --- /dev/null +++ b/YoutubeExtension/ytPlay.cs @@ -0,0 +1,6 @@ +namespace YoutubeExtension; + +public class ytPlay +{ + +}