From 62326da5b5d5a5128c2b9271cad5905557656d86 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Thu, 6 Jul 2017 19:25:38 +0200 Subject: [PATCH] Ytdl class --- src/NadekoBot/Services/Impl/Ytdl.cs | 61 +++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 src/NadekoBot/Services/Impl/Ytdl.cs diff --git a/src/NadekoBot/Services/Impl/Ytdl.cs b/src/NadekoBot/Services/Impl/Ytdl.cs new file mode 100644 index 00000000..526c5143 --- /dev/null +++ b/src/NadekoBot/Services/Impl/Ytdl.cs @@ -0,0 +1,61 @@ +using NLog; +using NYoutubeDL; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace NadekoBot.Services.Impl +{ + public class YtdlOperation : IDisposable + { + private readonly TaskCompletionSource _endedCompletionSource; + private string output { get; set; } + + public YtdlOperation() + { + _log = LogManager.GetCurrentClassLogger(); + } + + public async Task 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 \"ytsearch:{url}\"", + UseShellExecute = false, + RedirectStandardError = true, + RedirectStandardOutput = true, + CreateNoWindow = true, + }, + }) + { + process.Start(); + var str = await process.StandardOutput.ReadToEndAsync(); + var err = await process.StandardError.ReadToEndAsync(); + _log.Info(str); + _log.Info(err); + return str; + } + } + + private int cnt; + private Timer _timeoutTimer; + private Process p; + private readonly Logger _log; + + public void Dispose() + { + //_timeoutTimer.Change(Timeout.Infinite, Timeout.Infinite); + //_timeoutTimer.Dispose(); + try { this.p?.Kill(); } catch { } + } + } +}