Cleanup, should repull stream urls now, to prevent the link expired issue
This commit is contained in:
parent
5d6b0f44ae
commit
a55f61aa8c
@ -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<string> _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 { }
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -324,7 +324,6 @@ namespace NadekoBot.Services.Music
|
||||
|
||||
private async Task<SongInfo> 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,
|
||||
|
Loading…
Reference in New Issue
Block a user