updated music
This commit is contained in:
1
.idea/.idea.SethDiscordBot/.idea/.name
generated
Normal file
1
.idea/.idea.SethDiscordBot/.idea/.name
generated
Normal file
@@ -0,0 +1 @@
|
||||
SethDiscordBot
|
||||
4
.idea/.idea.SethDiscordBot/.idea/encodings.xml
generated
Normal file
4
.idea/.idea.SethDiscordBot/.idea/encodings.xml
generated
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
||||
</project>
|
||||
8
.idea/.idea.SethDiscordBot/.idea/indexLayout.xml
generated
Normal file
8
.idea/.idea.SethDiscordBot/.idea/indexLayout.xml
generated
Normal file
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="UserContentModel">
|
||||
<attachedFolders />
|
||||
<explicitIncludes />
|
||||
<explicitExcludes />
|
||||
</component>
|
||||
</project>
|
||||
6
.idea/.idea.SethDiscordBot/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.SethDiscordBot/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
12
YoutubeExtension/Others/Data.cs
Normal file
12
YoutubeExtension/Others/Data.cs
Normal file
@@ -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;
|
||||
}
|
||||
50
YoutubeExtension/Others/MusicPlayer.cs
Normal file
50
YoutubeExtension/Others/MusicPlayer.cs
Normal file
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
YoutubeExtension/Others/YTVideo.cs
Normal file
18
YoutubeExtension/Others/YTVideo.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using MediaToolkit;
|
||||
using MediaToolkit.Model;
|
||||
using VideoLibrary;
|
||||
|
||||
namespace YoutubeExtension.Downloader;
|
||||
|
||||
public class YoutubeHandler
|
||||
{
|
||||
|
||||
public static async Task<Stream> GetVideoStream(string videoURL)
|
||||
{
|
||||
var youtube = YouTube.Default;
|
||||
var video = await youtube.GetVideoAsync(videoURL);
|
||||
|
||||
return await video.StreamAsync();
|
||||
|
||||
}
|
||||
}
|
||||
9
YoutubeExtension/YoutubeExtension.csproj
Normal file
9
YoutubeExtension/YoutubeExtension.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
6
YoutubeExtension/ytPlay.cs
Normal file
6
YoutubeExtension/ytPlay.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace YoutubeExtension;
|
||||
|
||||
public class ytPlay
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user