2017-07-06 17:25:38 +00:00
|
|
|
|
using NLog;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2017-10-13 04:14:54 +00:00
|
|
|
|
namespace NadekoBot.Core.Services.Impl
|
2017-07-06 17:25:38 +00:00
|
|
|
|
{
|
|
|
|
|
public class YtdlOperation : IDisposable
|
|
|
|
|
{
|
2017-07-06 17:34:16 +00:00
|
|
|
|
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",
|
2017-07-10 19:08:11 +00:00
|
|
|
|
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:34:16 +00:00
|
|
|
|
|
2017-07-06 17:25:38 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|