Initial split of the modules
This commit is contained in:
46
NadekoBot.Core/Services/Impl/Ytdl.cs
Normal file
46
NadekoBot.Core/Services/Impl/Ytdl.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Services.Impl
|
||||
{
|
||||
public class YtdlOperation : IDisposable
|
||||
{
|
||||
private readonly Logger _log;
|
||||
|
||||
public YtdlOperation()
|
||||
{
|
||||
_log = LogManager.GetCurrentClassLogger();
|
||||
}
|
||||
|
||||
public async Task<string> GetDataAsync(string url)
|
||||
{
|
||||
using (Process process = new Process()
|
||||
{
|
||||
StartInfo = new ProcessStartInfo()
|
||||
{
|
||||
FileName = "youtube-dl",
|
||||
Arguments = $"-f bestaudio -e --get-url --get-id --get-thumbnail --get-duration --no-check-certificate --default-search \"ytsearch:\" \"{url}\"",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardError = true,
|
||||
RedirectStandardOutput = true,
|
||||
CreateNoWindow = true,
|
||||
},
|
||||
})
|
||||
{
|
||||
process.Start();
|
||||
var str = await process.StandardOutput.ReadToEndAsync();
|
||||
var err = await process.StandardError.ReadToEndAsync();
|
||||
if(!string.IsNullOrEmpty(err))
|
||||
_log.Warn(err);
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user