a lot of logs to pinpoint cpu usage on some systems
This commit is contained in:
parent
269a4e3157
commit
42923c5272
@ -108,6 +108,7 @@ namespace NadekoBot.Modules.Music
|
||||
int index;
|
||||
try
|
||||
{
|
||||
_log.Info("Added");
|
||||
index = mp.Enqueue(songInfo);
|
||||
}
|
||||
catch (QueueFullException)
|
||||
@ -169,11 +170,13 @@ namespace NadekoBot.Modules.Music
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task Queue([Remainder] string query)
|
||||
{
|
||||
_log.Info("Getting player");
|
||||
var mp = await _music.GetOrCreatePlayer(Context);
|
||||
_log.Info("Resolving song");
|
||||
var songInfo = await _music.ResolveSong(query, Context.User.ToString());
|
||||
|
||||
_log.Info("Queueing song");
|
||||
try { await InternalQueue(mp, songInfo, false); } catch (QueueFullException) { return; }
|
||||
|
||||
_log.Info("--------------");
|
||||
if ((await Context.Guild.GetCurrentUserAsync()).GetPermissions((IGuildChannel)Context.Channel).ManageMessages)
|
||||
{
|
||||
Context.Message.DeleteAfter(10);
|
||||
|
@ -156,6 +156,7 @@ namespace NadekoBot.Services.Music
|
||||
_log.Info("Starting");
|
||||
using (var b = new SongBuffer(await data.Song.Uri(), ""))
|
||||
{
|
||||
_log.Info("Created buffer, buffering...");
|
||||
AudioOutStream pcm = null;
|
||||
try
|
||||
{
|
||||
@ -171,16 +172,19 @@ namespace NadekoBot.Services.Music
|
||||
_log.Info("Buffering failed due to a cancel or error.");
|
||||
continue;
|
||||
}
|
||||
|
||||
_log.Info("Buffered. Getting audio client...");
|
||||
var ac = await GetAudioClient();
|
||||
_log.Info("Got Audio client");
|
||||
if (ac == null)
|
||||
{
|
||||
_log.Info("Can't join");
|
||||
await Task.Delay(900, cancelToken);
|
||||
// just wait some time, maybe bot doesn't even have perms to join that voice channel,
|
||||
// i don't want to spam connection attempts
|
||||
continue;
|
||||
}
|
||||
pcm = ac.CreatePCMStream(AudioApplication.Music, bufferMillis: 500);
|
||||
_log.Info("Created pcm stream");
|
||||
OnStarted?.Invoke(this, data);
|
||||
|
||||
byte[] buffer = new byte[3840];
|
||||
@ -189,6 +193,7 @@ namespace NadekoBot.Services.Music
|
||||
while ((bytesRead = b.Read(buffer, 0, buffer.Length)) > 0
|
||||
&& (MaxPlaytimeSeconds <= 0 || MaxPlaytimeSeconds >= CurrentTime.TotalSeconds))
|
||||
{
|
||||
_log.Info("Sending stuff");
|
||||
AdjustVolume(buffer, Volume);
|
||||
await pcm.WriteAsync(buffer, 0, bytesRead, cancelToken).ConfigureAwait(false);
|
||||
unchecked { _bytesSent += bytesRead; }
|
||||
@ -309,6 +314,7 @@ namespace NadekoBot.Services.Music
|
||||
do
|
||||
{
|
||||
await Task.Delay(500);
|
||||
_log.Info("Waiting for something to happen");
|
||||
}
|
||||
while ((Queue.Count == 0 || Stopped) && !Exited);
|
||||
}
|
||||
|
@ -282,6 +282,7 @@ namespace NadekoBot.Services.Music
|
||||
|
||||
public async Task<SongInfo> ResolveYoutubeSong(string query, string queuerName)
|
||||
{
|
||||
_log.Info("Getting video");
|
||||
var (link, video) = await GetYoutubeVideo(query);
|
||||
|
||||
if (video == null) // do something with this error
|
||||
@ -294,6 +295,7 @@ namespace NadekoBot.Services.Music
|
||||
//if (m.Captures.Count > 0)
|
||||
// int.TryParse(m.Groups["t"].ToString(), out gotoTime);
|
||||
|
||||
_log.Info("Creating song info");
|
||||
var song = new SongInfo
|
||||
{
|
||||
Title = video.Title.Substring(0, video.Title.Length - 10), // removing trailing "- You Tube"
|
||||
@ -314,12 +316,14 @@ namespace NadekoBot.Services.Music
|
||||
|
||||
private async Task<(string, YouTubeVideo)> GetYoutubeVideo(string query)
|
||||
{
|
||||
_log.Info("Getting link");
|
||||
var link = (await _google.GetVideoLinksByKeywordAsync(query).ConfigureAwait(false)).FirstOrDefault();
|
||||
if (string.IsNullOrWhiteSpace(link))
|
||||
{
|
||||
_log.Info("No song found.");
|
||||
return (null, null);
|
||||
}
|
||||
_log.Info("Getting all videos");
|
||||
var allVideos = await Task.Run(async () => { try { return await YouTube.Default.GetAllVideosAsync(link).ConfigureAwait(false); } catch { return Enumerable.Empty<YouTubeVideo>(); } }).ConfigureAwait(false);
|
||||
var videos = allVideos.Where(v => v.AdaptiveKind == AdaptiveKind.Audio);
|
||||
var video = videos
|
||||
|
Loading…
Reference in New Issue
Block a user