NadekoBot/NadekoBot.Core/Services/Impl/Ytdl.cs

47 lines
1.3 KiB
C#
Raw Normal View History

2017-07-06 17:25:38 +00:00
using NLog;
using System;
using System.Diagnostics;
using System.Threading.Tasks;
namespace NadekoBot.Services.Impl
{
public class YtdlOperation : IDisposable
{
private readonly Logger _log;
2017-07-06 17:25:38 +00:00
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}\"",
2017-07-06 17:25:38 +00:00
UseShellExecute = false,
RedirectStandardError = true,
RedirectStandardOutput = true,
CreateNoWindow = true,
},
})
{
process.Start();
var str = await process.StandardOutput.ReadToEndAsync();
var err = await process.StandardError.ReadToEndAsync();
2017-07-06 17:46:23 +00:00
if(!string.IsNullOrEmpty(err))
_log.Warn(err);
2017-07-06 17:25:38 +00:00
return str;
}
}
public void Dispose()
{
2017-07-06 17:25:38 +00:00
}
}
}