This commit is contained in:
2023-07-31 20:47:44 -03:00
parent 9df9090812
commit 0b9f96460f
8 changed files with 84 additions and 40 deletions

View File

@@ -0,0 +1,28 @@
using System.Diagnostics;
namespace Kasbot.Services.Internal
{
public class AudioService
{
public AudioService() { }
public Process CreateStream()
{
var process = Process.Start(new ProcessStartInfo
{
FileName = "ffmpeg",
Arguments = $"-hide_banner -loglevel panic -i pipe:0 -ac 2 -f s16le -ar 48000 pipe:1",
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true
});
if (process == null || process.HasExited)
{
throw new Exception("Sorry, ffmpeg killed itself in a tragic accident!");
}
return process;
}
}
}

View File

@@ -5,7 +5,7 @@ using Discord.Rest;
using YoutubeExplode.Videos.Streams;
using Kasbot.Models;
namespace Kasbot.Services
namespace Kasbot.Services.Internal
{
public class YoutubeService
{
@@ -120,7 +120,7 @@ namespace Kasbot.Services
public VideoId? VideoId { get; set; }
public RestUserMessage PlayMessage { get; set; }
public RestUserMessage? QueueMessage { get; set; }
private SocketUserMessage message;
public SocketUserMessage Message
{
@@ -128,7 +128,7 @@ namespace Kasbot.Services
set
{
message = value;
this.Channel = value.Channel;
Channel = value.Channel;
}
}
public ISocketMessageChannel Channel { get; private set; }

View File

@@ -3,7 +3,7 @@ using Discord.Audio;
using Discord.Commands;
using Kasbot.Extensions;
using Kasbot.Models;
using System.Diagnostics;
using Kasbot.Services.Internal;
namespace Kasbot.Services
{
@@ -11,10 +11,12 @@ namespace Kasbot.Services
{
public Dictionary<ulong, Connection> Clients { get; set; }
public YoutubeService YoutubeService { get; set; }
public AudioService AudioService { get; set; }
public PlayerService(YoutubeService youtubeService)
public PlayerService(YoutubeService youtubeService, AudioService audioService)
{
this.YoutubeService = youtubeService;
YoutubeService = youtubeService;
AudioService = audioService;
Clients = new Dictionary<ulong, Connection>();
}
@@ -141,7 +143,7 @@ namespace Kasbot.Services
}
var audioClient = Clients[guildId].AudioClient;
var ffmpeg = CreateStream();
var ffmpeg = AudioService.CreateStream();
if (!nextMedia.Flags.Silent)
{
@@ -220,25 +222,6 @@ namespace Kasbot.Services
await PlayNext(guildId);
}
private Process CreateStream()
{
var process = Process.Start(new ProcessStartInfo
{
FileName = "ffmpeg",
Arguments = $"-hide_banner -loglevel panic -i pipe:0 -ac 2 -f s16le -ar 48000 pipe:1",
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true
});
if (process == null || process.HasExited)
{
throw new Exception("Sorry, ffmpeg killed itself in a tragic accident!");
}
return process;
}
public Task Skip(ulong guildId)
{
if (!Clients.ContainsKey(guildId))