Cleanup, should repull stream urls now, to prevent the link expired issue

This commit is contained in:
Master Kwoth 2017-07-06 19:34:16 +02:00
parent 5d6b0f44ae
commit a55f61aa8c
2 changed files with 15 additions and 21 deletions

View File

@ -1,20 +1,13 @@
using NLog; using NLog;
using NYoutubeDL;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace NadekoBot.Services.Impl namespace NadekoBot.Services.Impl
{ {
public class YtdlOperation : IDisposable public class YtdlOperation : IDisposable
{ {
private readonly TaskCompletionSource<string> _endedCompletionSource; private readonly Logger _log;
private string output { get; set; }
public YtdlOperation() public YtdlOperation()
{ {
@ -25,7 +18,6 @@ namespace NadekoBot.Services.Impl
{ {
using (Process process = new Process() using (Process process = new Process()
{ {
StartInfo = new ProcessStartInfo() StartInfo = new ProcessStartInfo()
{ {
FileName = "youtube-dl", FileName = "youtube-dl",
@ -40,22 +32,14 @@ namespace NadekoBot.Services.Impl
process.Start(); process.Start();
var str = await process.StandardOutput.ReadToEndAsync(); var str = await process.StandardOutput.ReadToEndAsync();
var err = await process.StandardError.ReadToEndAsync(); var err = await process.StandardError.ReadToEndAsync();
_log.Info(str); _log.Warn(err);
_log.Info(err);
return str; return str;
} }
} }
private int cnt;
private Timer _timeoutTimer;
private Process p;
private readonly Logger _log;
public void Dispose() public void Dispose()
{ {
//_timeoutTimer.Change(Timeout.Infinite, Timeout.Infinite);
//_timeoutTimer.Dispose();
try { this.p?.Kill(); } catch { }
} }
} }
} }

View File

@ -324,7 +324,6 @@ namespace NadekoBot.Services.Music
private async Task<SongInfo> GetYoutubeVideo(string query, string queuerName) private async Task<SongInfo> GetYoutubeVideo(string query, string queuerName)
{ {
_log.Info("Getting link"); _log.Info("Getting link");
string[] data; string[] data;
try try
@ -346,7 +345,18 @@ namespace NadekoBot.Services.Music
{ {
Title = data[0], Title = data[0],
VideoId = data[1], 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], AlbumArt = data[3],
TotalTime = time, TotalTime = time,
QueuerName = queuerName, QueuerName = queuerName,