Updated bootstrap and merged gitlab project

This commit is contained in:
2024-09-17 15:30:08 +03:00
parent a584423939
commit be75ef03cb
2097 changed files with 14141 additions and 148 deletions

View File

@@ -1,42 +1,47 @@
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace MusicPlayer;
public class YoutubeDLP
public class YoutubeDlp
{
public static async Task<string?> DownloadMelody(string url)
public static async Task DownloadMelody(string url, string downloadId)
{
Console.WriteLine("Downloading melody: " + url);
var process = new Process();
var process = new Process();
var baseMusicDirectory = DiscordBotCore.Application.GetResourceFullPath("Music/Melodies/");
process.StartInfo.FileName = await DiscordBotCore.Application.CurrentApplication.PluginManager.GetDependencyLocation("yt-dlp");
process.StartInfo.Arguments = $"-x --force-overwrites -o \"{DiscordBotCore.Application.GetResourceFullPath("/Music/Melodies")}/%(title)s.%(ext)s\" --audio-format mp3 {url}";
process.StartInfo.Arguments = $"-x --force-overwrites -o \"{baseMusicDirectory}/{downloadId}.%(ext)s\" --audio-quality 3 --audio-format mp3 {url}";
process.StartInfo.RedirectStandardOutput = true;
var title = "";
process.OutputDataReceived += (sender, args) =>
process.OutputDataReceived += (_, args) =>
{
if (args.Data != null)
{
if (args.Data.StartsWith("[ExtractAudio] Destination: "))
{
title = args.Data.Replace("[ExtractAudio] Destination: ", "").Replace(".mp3", "");
title = title.Replace("\\", "/");
title = title.Split('/').Last().Replace(".mp3", "").TrimEnd();
Console.WriteLine("Output title: " + title);
return;
}
Console.WriteLine(args.Data);
}
};
process.Start();
Console.WriteLine("Waiting for process to exit ...");
process.BeginOutputReadLine();
await process.WaitForExitAsync();
}
public static async Task<string?> GetMusicTitle(string youtubeUrl)
{
Process p = new Process();
p.StartInfo.FileName=await DiscordBotCore.Application.CurrentApplication.PluginManager.GetDependencyLocation("yt-dlp");
p.StartInfo.Arguments = $"--print \"%(title)s\" {youtubeUrl}";
p.StartInfo.RedirectStandardOutput = true;
p.Start();
string output = await p.StandardOutput.ReadToEndAsync();
await p.WaitForExitAsync();
output = Regex.Replace(output, @"[\p{L}-[a-zA-Z]]+", "");
output = output.TrimEnd();
return title ?? null;
return output;
}
}