From 5015b6ad95d8d594fd8607db1033659ef15df70d Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sun, 2 Jul 2017 13:53:09 +0200 Subject: [PATCH] cleanup --- .../DataStructures/PoopyRingBuffer.cs | 9 ++-- .../DataStructures/SearchImageCacher.cs | 5 ++- .../Modules/Administration/Administration.cs | 1 - .../Modules/Searches/Commands/LoLCommands.cs | 2 - src/NadekoBot/NadekoBot.cs | 2 +- src/NadekoBot/Services/Music/MusicPlayer.cs | 5 --- src/NadekoBot/Services/Music/Song.cs | 1 - src/NadekoBot/Services/Music/SongBuffer.cs | 44 +++++++++---------- 8 files changed, 30 insertions(+), 39 deletions(-) diff --git a/src/NadekoBot/DataStructures/PoopyRingBuffer.cs b/src/NadekoBot/DataStructures/PoopyRingBuffer.cs index 214ee110..b0b9f19c 100644 --- a/src/NadekoBot/DataStructures/PoopyRingBuffer.cs +++ b/src/NadekoBot/DataStructures/PoopyRingBuffer.cs @@ -87,7 +87,6 @@ namespace NadekoBot.DataStructures ReadPos = secondRead; } } - Console.WriteLine("Readpos: {0} WritePos: {1}", ReadPos, WritePos); return toRead; } finally @@ -99,12 +98,14 @@ namespace NadekoBot.DataStructures public Task WriteAsync(byte[] b, int offset, int toWrite, CancellationToken cancelToken) => Task.Run(async () => { while (toWrite > RemainingCapacity) - await Task.Delay(50, cancelToken); + await Task.Delay(1000, cancelToken); // wait a lot, buffer should be large anyway + + if (toWrite == 0) + return; await _locker.WaitAsync(cancelToken); try { - Console.WriteLine("Writing {0}", toWrite); if (WritePos < ReadPos) { Buffer.BlockCopy(b, offset, buffer, WritePos, toWrite); @@ -130,8 +131,6 @@ namespace NadekoBot.DataStructures WritePos = 0; } } - Console.WriteLine("Readpos: {0} WritePos: {1} ({2})", ReadPos, WritePos, ReadPos - WritePos); - return toWrite; } finally { diff --git a/src/NadekoBot/DataStructures/SearchImageCacher.cs b/src/NadekoBot/DataStructures/SearchImageCacher.cs index 1296c311..c9795ecf 100644 --- a/src/NadekoBot/DataStructures/SearchImageCacher.cs +++ b/src/NadekoBot/DataStructures/SearchImageCacher.cs @@ -1,6 +1,7 @@ using NadekoBot.Extensions; using NadekoBot.Services; using Newtonsoft.Json; +using NLog; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -19,9 +20,11 @@ namespace NadekoBot.DataStructures private readonly ConcurrentDictionary _locks = new ConcurrentDictionary(); private readonly SortedSet _cache; + private readonly Logger _log; public SearchImageCacher() { + _log = LogManager.GetCurrentClassLogger(); _rng = new NadekoRandom(); _cache = new SortedSet(); } @@ -85,7 +88,7 @@ namespace NadekoBot.DataStructures public async Task DownloadImages(string tag, bool isExplicit, DapiSearchType type) { - Console.WriteLine($"Loading extra images from {type}"); + _log.Info($"Loading extra images from {type}"); tag = tag?.Replace(" ", "_").ToLowerInvariant(); if (isExplicit) tag = "rating%3Aexplicit+" + tag; diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index 56a0affc..129970e1 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -136,7 +136,6 @@ namespace NadekoBot.Modules.Administration } catch (Exception ex) { - Console.WriteLine(ex); await ReplyErrorLocalized("rar_err").ConfigureAwait(false); } } diff --git a/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs b/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs index d7697a5c..0225725c 100644 --- a/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs +++ b/src/NadekoBot/Modules/Searches/Commands/LoLCommands.cs @@ -173,7 +173,6 @@ namespace NadekoBot.Modules.Searches // .FirstOrDefault(jt => jt["role"].ToString() == role)?["general"]; // if (general == null) // { -// //Console.WriteLine("General is null."); // return; // } // //get build data for this role @@ -309,7 +308,6 @@ namespace NadekoBot.Modules.Searches // } // catch (Exception ex) // { -// //Console.WriteLine(ex); // await channel.SendMessageAsync("💢 Failed retreiving data for that champion.").ConfigureAwait(false); // } // }); diff --git a/src/NadekoBot/NadekoBot.cs b/src/NadekoBot/NadekoBot.cs index d75cd963..00bf8319 100644 --- a/src/NadekoBot/NadekoBot.cs +++ b/src/NadekoBot/NadekoBot.cs @@ -352,7 +352,7 @@ namespace NadekoBot #if GLOBAL_NADEKO isPublicNadeko = true; #endif - //Console.WriteLine(string.Join(", ", CommandService.Commands + //_log.Info(string.Join(", ", CommandService.Commands // .Distinct(x => x.Name + x.Module.Name) // .SelectMany(x => x.Aliases) // .GroupBy(x => x) diff --git a/src/NadekoBot/Services/Music/MusicPlayer.cs b/src/NadekoBot/Services/Music/MusicPlayer.cs index 1ac0cbad..b31831e8 100644 --- a/src/NadekoBot/Services/Music/MusicPlayer.cs +++ b/src/NadekoBot/Services/Music/MusicPlayer.cs @@ -78,13 +78,9 @@ namespace NadekoBot.Services.Music } try { - _log.Info("Checking for songs"); if (data.Song == null) continue; - _log.Info("Connecting"); - - _log.Info("Starting"); using (var b = new SongBuffer(data.Song.Uri, "")) { @@ -117,7 +113,6 @@ namespace NadekoBot.Services.Music await (pauseTaskSource?.Task ?? Task.CompletedTask); } - _log.Info(">>>>>>>>>READ 0<<<<<<<<<<"); } catch (OperationCanceledException) { diff --git a/src/NadekoBot/Services/Music/Song.cs b/src/NadekoBot/Services/Music/Song.cs index 074238d6..a9567f9c 100644 --- a/src/NadekoBot/Services/Music/Song.cs +++ b/src/NadekoBot/Services/Music/Song.cs @@ -172,7 +172,6 @@ namespace NadekoBot.Services.Music // while (!cancelToken.IsCancellationRequested && //song canceled for whatever reason // !(MusicPlayer.MaxPlaytimeSeconds != 0 && CurrentTime.TotalSeconds >= MusicPlayer.MaxPlaytimeSeconds)) // or exceedded max playtime // { - // //Console.WriteLine($"Read: {songBuffer.ReadPosition}\nWrite: {songBuffer.WritePosition}\nContentLength:{songBuffer.ContentLength}\n---------"); // var read = await inStream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false); // //await inStream.CopyToAsync(voiceClient.OutputStream); // if (read < _frameBytes) diff --git a/src/NadekoBot/Services/Music/SongBuffer.cs b/src/NadekoBot/Services/Music/SongBuffer.cs index 1d9fa9ef..953e640a 100644 --- a/src/NadekoBot/Services/Music/SongBuffer.cs +++ b/src/NadekoBot/Services/Music/SongBuffer.cs @@ -1,4 +1,5 @@ using NadekoBot.DataStructures; +using NLog; using System; using System.Diagnostics; using System.IO; @@ -14,11 +15,13 @@ namespace NadekoBot.Services.Music private PoopyRingBuffer _outStream = new PoopyRingBuffer(); private readonly SemaphoreSlim _lock = new SemaphoreSlim(1, 1); + private readonly Logger _log; public string SongUri { get; private set; } public SongBuffer(string songUri, string skipTo) { + _log = LogManager.GetCurrentClassLogger(); this.SongUri = songUri; this.p = Process.Start(new ProcessStartInfo @@ -48,34 +51,31 @@ namespace NadekoBot.Services.Music int bytesRead = -1; while (!cancelToken.IsCancellationRequested && bytesRead != 0) { - var toRead = buffer.Length; - //var remCap = _outStream.RemainingCapacity; - //if (remCap < readSize) - //{ - // if (_outStream.RemainingCapacity == 0) - // { - // Console.WriteLine("Buffer full, not gonnna read from ffmpeg"); - // await Task.Delay(20); - // continue; - // } - // toRead = remCap; - //} - - bytesRead = await p.StandardOutput.BaseStream.ReadAsync(buffer, 0, toRead, cancelToken).ConfigureAwait(false); + bytesRead = await p.StandardOutput.BaseStream.ReadAsync(buffer, 0, readSize, cancelToken).ConfigureAwait(false); await _outStream.WriteAsync(buffer, 0, bytesRead, cancelToken); - if (_outStream.RemainingCapacity < _outStream.Capacity * 0.9f) + if (_outStream.RemainingCapacity < _outStream.Capacity * 0.5f) if (toReturn.TrySetResult(true)) - Console.WriteLine("Prebuffering finished"); + _log.Info("Prebuffering finished"); } - Console.WriteLine("FFMPEG killed or song canceled"); + _log.Info("FFMPEG killed, song canceled, or song fully downloaded"); + } + catch (System.ComponentModel.Win32Exception) + { + _log.Error(@"You have not properly installed or configured FFMPEG. +Please install and configure FFMPEG to play music. +Check the guides for your platform on how to setup ffmpeg correctly: + Windows Guide: https://goo.gl/OjKk8F + Linux Guide: https://goo.gl/ShjCUo"); } catch (Exception ex) { - Console.WriteLine(ex); - if(toReturn.TrySetResult(false)) - Console.WriteLine("Prebuffering failed"); - //ignored + _log.Info(ex); + } + finally + { + if (toReturn.TrySetResult(false)) + _log.Info("Prebuffering failed"); } }, cancelToken); @@ -89,7 +89,6 @@ namespace NadekoBot.Services.Music public void Dispose() { - Console.WriteLine("DISPOSING"); try { this.p.Kill(); } catch { } _outStream.Dispose(); @@ -203,7 +202,6 @@ namespace NadekoBot.Services.Music // { // if (outStream != null) // outStream.Dispose(); -// Console.WriteLine($"Buffering done."); // if (p != null) // { // try