cleanup
This commit is contained in:
		@@ -87,7 +87,6 @@ namespace NadekoBot.DataStructures
 | 
				
			|||||||
                        ReadPos = secondRead;
 | 
					                        ReadPos = secondRead;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                Console.WriteLine("Readpos: {0} WritePos: {1}", ReadPos, WritePos);
 | 
					 | 
				
			||||||
                return toRead;
 | 
					                return toRead;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            finally
 | 
					            finally
 | 
				
			||||||
@@ -99,12 +98,14 @@ namespace NadekoBot.DataStructures
 | 
				
			|||||||
        public Task WriteAsync(byte[] b, int offset, int toWrite, CancellationToken cancelToken) => Task.Run(async () =>
 | 
					        public Task WriteAsync(byte[] b, int offset, int toWrite, CancellationToken cancelToken) => Task.Run(async () =>
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            while (toWrite > RemainingCapacity)
 | 
					            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);
 | 
					            await _locker.WaitAsync(cancelToken);
 | 
				
			||||||
            try
 | 
					            try
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Console.WriteLine("Writing {0}", toWrite);
 | 
					 | 
				
			||||||
                if (WritePos < ReadPos)
 | 
					                if (WritePos < ReadPos)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    Buffer.BlockCopy(b, offset, buffer, WritePos, toWrite);
 | 
					                    Buffer.BlockCopy(b, offset, buffer, WritePos, toWrite);
 | 
				
			||||||
@@ -130,8 +131,6 @@ namespace NadekoBot.DataStructures
 | 
				
			|||||||
                            WritePos = 0;
 | 
					                            WritePos = 0;
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                Console.WriteLine("Readpos: {0} WritePos: {1} ({2})", ReadPos, WritePos, ReadPos - WritePos);
 | 
					 | 
				
			||||||
                return toWrite;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            finally
 | 
					            finally
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
using NadekoBot.Extensions;
 | 
					using NadekoBot.Extensions;
 | 
				
			||||||
using NadekoBot.Services;
 | 
					using NadekoBot.Services;
 | 
				
			||||||
using Newtonsoft.Json;
 | 
					using Newtonsoft.Json;
 | 
				
			||||||
 | 
					using NLog;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Collections.Concurrent;
 | 
					using System.Collections.Concurrent;
 | 
				
			||||||
using System.Collections.Generic;
 | 
					using System.Collections.Generic;
 | 
				
			||||||
@@ -19,9 +20,11 @@ namespace NadekoBot.DataStructures
 | 
				
			|||||||
        private readonly ConcurrentDictionary<DapiSearchType, SemaphoreSlim> _locks = new ConcurrentDictionary<DapiSearchType, SemaphoreSlim>();
 | 
					        private readonly ConcurrentDictionary<DapiSearchType, SemaphoreSlim> _locks = new ConcurrentDictionary<DapiSearchType, SemaphoreSlim>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private readonly SortedSet<ImageCacherObject> _cache;
 | 
					        private readonly SortedSet<ImageCacherObject> _cache;
 | 
				
			||||||
 | 
					        private readonly Logger _log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public SearchImageCacher()
 | 
					        public SearchImageCacher()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            _log = LogManager.GetCurrentClassLogger();
 | 
				
			||||||
            _rng = new NadekoRandom();
 | 
					            _rng = new NadekoRandom();
 | 
				
			||||||
            _cache = new SortedSet<ImageCacherObject>();
 | 
					            _cache = new SortedSet<ImageCacherObject>();
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
@@ -85,7 +88,7 @@ namespace NadekoBot.DataStructures
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public async Task<ImageCacherObject[]> DownloadImages(string tag, bool isExplicit, DapiSearchType type)
 | 
					        public async Task<ImageCacherObject[]> 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();
 | 
					            tag = tag?.Replace(" ", "_").ToLowerInvariant();
 | 
				
			||||||
            if (isExplicit)
 | 
					            if (isExplicit)
 | 
				
			||||||
                tag = "rating%3Aexplicit+" + tag;
 | 
					                tag = "rating%3Aexplicit+" + tag;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -136,7 +136,6 @@ namespace NadekoBot.Modules.Administration
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
            catch (Exception ex)
 | 
					            catch (Exception ex)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                Console.WriteLine(ex);
 | 
					 | 
				
			||||||
                await ReplyErrorLocalized("rar_err").ConfigureAwait(false);
 | 
					                await ReplyErrorLocalized("rar_err").ConfigureAwait(false);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -173,7 +173,6 @@ namespace NadekoBot.Modules.Searches
 | 
				
			|||||||
//                                              .FirstOrDefault(jt => jt["role"].ToString() == role)?["general"];
 | 
					//                                              .FirstOrDefault(jt => jt["role"].ToString() == role)?["general"];
 | 
				
			||||||
//                          if (general == null)
 | 
					//                          if (general == null)
 | 
				
			||||||
//                          {
 | 
					//                          {
 | 
				
			||||||
//                              //Console.WriteLine("General is null.");
 | 
					 | 
				
			||||||
//                              return;
 | 
					//                              return;
 | 
				
			||||||
//                          }
 | 
					//                          }
 | 
				
			||||||
//                          //get build data for this role
 | 
					//                          //get build data for this role
 | 
				
			||||||
@@ -309,7 +308,6 @@ namespace NadekoBot.Modules.Searches
 | 
				
			|||||||
//                      }
 | 
					//                      }
 | 
				
			||||||
//                      catch (Exception ex)
 | 
					//                      catch (Exception ex)
 | 
				
			||||||
//                      {
 | 
					//                      {
 | 
				
			||||||
//                          //Console.WriteLine(ex);
 | 
					 | 
				
			||||||
//                          await channel.SendMessageAsync("💢 Failed retreiving data for that champion.").ConfigureAwait(false);
 | 
					//                          await channel.SendMessageAsync("💢 Failed retreiving data for that champion.").ConfigureAwait(false);
 | 
				
			||||||
//                      }
 | 
					//                      }
 | 
				
			||||||
//                  });
 | 
					//                  });
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -352,7 +352,7 @@ namespace NadekoBot
 | 
				
			|||||||
#if GLOBAL_NADEKO
 | 
					#if GLOBAL_NADEKO
 | 
				
			||||||
            isPublicNadeko = true;
 | 
					            isPublicNadeko = true;
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
            //Console.WriteLine(string.Join(", ", CommandService.Commands
 | 
					            //_log.Info(string.Join(", ", CommandService.Commands
 | 
				
			||||||
            //    .Distinct(x => x.Name + x.Module.Name)
 | 
					            //    .Distinct(x => x.Name + x.Module.Name)
 | 
				
			||||||
            //    .SelectMany(x => x.Aliases)
 | 
					            //    .SelectMany(x => x.Aliases)
 | 
				
			||||||
            //    .GroupBy(x => x)
 | 
					            //    .GroupBy(x => x)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -78,13 +78,9 @@ namespace NadekoBot.Services.Music
 | 
				
			|||||||
                     }
 | 
					                     }
 | 
				
			||||||
                     try
 | 
					                     try
 | 
				
			||||||
                     {
 | 
					                     {
 | 
				
			||||||
                         _log.Info("Checking for songs");
 | 
					 | 
				
			||||||
                         if (data.Song == null)
 | 
					                         if (data.Song == null)
 | 
				
			||||||
                             continue;
 | 
					                             continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                         _log.Info("Connecting");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                         _log.Info("Starting");
 | 
					                         _log.Info("Starting");
 | 
				
			||||||
                         using (var b = new SongBuffer(data.Song.Uri, ""))
 | 
					                         using (var b = new SongBuffer(data.Song.Uri, ""))
 | 
				
			||||||
                         {
 | 
					                         {
 | 
				
			||||||
@@ -117,7 +113,6 @@ namespace NadekoBot.Services.Music
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                                     await (pauseTaskSource?.Task ?? Task.CompletedTask);
 | 
					                                     await (pauseTaskSource?.Task ?? Task.CompletedTask);
 | 
				
			||||||
                                 }
 | 
					                                 }
 | 
				
			||||||
                                 _log.Info(">>>>>>>>>READ 0<<<<<<<<<<");
 | 
					 | 
				
			||||||
                             }
 | 
					                             }
 | 
				
			||||||
                             catch (OperationCanceledException)
 | 
					                             catch (OperationCanceledException)
 | 
				
			||||||
                             {
 | 
					                             {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -172,7 +172,6 @@ namespace NadekoBot.Services.Music
 | 
				
			|||||||
    //            while (!cancelToken.IsCancellationRequested && //song canceled for whatever reason
 | 
					    //            while (!cancelToken.IsCancellationRequested && //song canceled for whatever reason
 | 
				
			||||||
    //                !(MusicPlayer.MaxPlaytimeSeconds != 0 && CurrentTime.TotalSeconds >= MusicPlayer.MaxPlaytimeSeconds)) // or exceedded max playtime
 | 
					    //                !(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);
 | 
					    //                var read = await inStream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false);
 | 
				
			||||||
    //                //await inStream.CopyToAsync(voiceClient.OutputStream);
 | 
					    //                //await inStream.CopyToAsync(voiceClient.OutputStream);
 | 
				
			||||||
    //                if (read < _frameBytes)
 | 
					    //                if (read < _frameBytes)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,5 @@
 | 
				
			|||||||
using NadekoBot.DataStructures;
 | 
					using NadekoBot.DataStructures;
 | 
				
			||||||
 | 
					using NLog;
 | 
				
			||||||
using System;
 | 
					using System;
 | 
				
			||||||
using System.Diagnostics;
 | 
					using System.Diagnostics;
 | 
				
			||||||
using System.IO;
 | 
					using System.IO;
 | 
				
			||||||
@@ -14,11 +15,13 @@ namespace NadekoBot.Services.Music
 | 
				
			|||||||
        private PoopyRingBuffer _outStream = new PoopyRingBuffer();
 | 
					        private PoopyRingBuffer _outStream = new PoopyRingBuffer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private readonly SemaphoreSlim _lock = new SemaphoreSlim(1, 1);
 | 
					        private readonly SemaphoreSlim _lock = new SemaphoreSlim(1, 1);
 | 
				
			||||||
 | 
					        private readonly Logger _log;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public string SongUri { get; private set; }
 | 
					        public string SongUri { get; private set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public SongBuffer(string songUri, string skipTo)
 | 
					        public SongBuffer(string songUri, string skipTo)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            _log = LogManager.GetCurrentClassLogger();
 | 
				
			||||||
            this.SongUri = songUri;
 | 
					            this.SongUri = songUri;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            this.p = Process.Start(new ProcessStartInfo
 | 
					            this.p = Process.Start(new ProcessStartInfo
 | 
				
			||||||
@@ -48,34 +51,31 @@ namespace NadekoBot.Services.Music
 | 
				
			|||||||
                    int bytesRead = -1;
 | 
					                    int bytesRead = -1;
 | 
				
			||||||
                    while (!cancelToken.IsCancellationRequested && bytesRead != 0)
 | 
					                    while (!cancelToken.IsCancellationRequested && bytesRead != 0)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        var toRead = buffer.Length;
 | 
					                        bytesRead = await p.StandardOutput.BaseStream.ReadAsync(buffer, 0, readSize, cancelToken).ConfigureAwait(false);
 | 
				
			||||||
                        //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);
 | 
					 | 
				
			||||||
                        await _outStream.WriteAsync(buffer, 0, bytesRead, cancelToken);
 | 
					                        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))
 | 
					                            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)
 | 
					                catch (Exception ex)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    Console.WriteLine(ex);
 | 
					                    _log.Info(ex);
 | 
				
			||||||
                    if(toReturn.TrySetResult(false))
 | 
					                }
 | 
				
			||||||
                        Console.WriteLine("Prebuffering failed");
 | 
					                finally
 | 
				
			||||||
                    //ignored
 | 
					                {
 | 
				
			||||||
 | 
					                    if (toReturn.TrySetResult(false))
 | 
				
			||||||
 | 
					                        _log.Info("Prebuffering failed");
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            }, cancelToken);
 | 
					            }, cancelToken);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -89,7 +89,6 @@ namespace NadekoBot.Services.Music
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        public void Dispose()
 | 
					        public void Dispose()
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            Console.WriteLine("DISPOSING");
 | 
					 | 
				
			||||||
            try { this.p.Kill(); }
 | 
					            try { this.p.Kill(); }
 | 
				
			||||||
            catch { }
 | 
					            catch { }
 | 
				
			||||||
            _outStream.Dispose();
 | 
					            _outStream.Dispose();
 | 
				
			||||||
@@ -203,7 +202,6 @@ namespace NadekoBot.Services.Music
 | 
				
			|||||||
//               {
 | 
					//               {
 | 
				
			||||||
//                   if (outStream != null)
 | 
					//                   if (outStream != null)
 | 
				
			||||||
//                       outStream.Dispose();
 | 
					//                       outStream.Dispose();
 | 
				
			||||||
//                   Console.WriteLine($"Buffering done.");
 | 
					 | 
				
			||||||
//                   if (p != null)
 | 
					//                   if (p != null)
 | 
				
			||||||
//                   {
 | 
					//                   {
 | 
				
			||||||
//                       try
 | 
					//                       try
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user