From a55f61aa8cf799a7fe8a050cd8def07da7db0a5b Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Thu, 6 Jul 2017 19:34:16 +0200 Subject: [PATCH] Cleanup, should repull stream urls now, to prevent the link expired issue --- src/NadekoBot/Services/Impl/Ytdl.cs | 22 +++----------------- src/NadekoBot/Services/Music/MusicService.cs | 14 +++++++++++-- 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/NadekoBot/Services/Impl/Ytdl.cs b/src/NadekoBot/Services/Impl/Ytdl.cs index 526c5143..fd690d20 100644 --- a/src/NadekoBot/Services/Impl/Ytdl.cs +++ b/src/NadekoBot/Services/Impl/Ytdl.cs @@ -1,20 +1,13 @@ 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; } + private readonly Logger _log; public YtdlOperation() { @@ -25,7 +18,6 @@ namespace NadekoBot.Services.Impl { using (Process process = new Process() { - StartInfo = new ProcessStartInfo() { FileName = "youtube-dl", @@ -40,22 +32,14 @@ namespace NadekoBot.Services.Impl process.Start(); var str = await process.StandardOutput.ReadToEndAsync(); var err = await process.StandardError.ReadToEndAsync(); - _log.Info(str); - _log.Info(err); + _log.Warn(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 { } + } } } diff --git a/src/NadekoBot/Services/Music/MusicService.cs b/src/NadekoBot/Services/Music/MusicService.cs index 7b685fa2..648a5508 100644 --- a/src/NadekoBot/Services/Music/MusicService.cs +++ b/src/NadekoBot/Services/Music/MusicService.cs @@ -324,7 +324,6 @@ namespace NadekoBot.Services.Music private async Task GetYoutubeVideo(string query, string queuerName) { - _log.Info("Getting link"); string[] data; try @@ -346,7 +345,18 @@ namespace NadekoBot.Services.Music { Title = data[0], VideoId = data[1], - Uri = () => Task.FromResult(data[2]), + Uri = async () => { + using (var ytdl = new YtdlOperation()) + { + data = (await ytdl.GetDataAsync(query)).Split('\n'); + } + if (data.Length < 6) + { + _log.Info("No song found. Data less than 6"); + return null; + } + return data[2]; + }, AlbumArt = data[3], TotalTime = time, QueuerName = queuerName,