mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-12 18:28:27 -04:00
.btr and .sclr added, cleanup
This commit is contained in:
@@ -38,4 +38,5 @@ public interface IMusicPlayer : IDisposable
|
||||
void SetRepeat(PlayerRepeatType type);
|
||||
void ShuffleQueue();
|
||||
void SetFairplay();
|
||||
Task<IQueuedTrackInfo?> RemoveLastQueuedTrack();
|
||||
}
|
@@ -20,4 +20,5 @@ public interface IMusicQueue
|
||||
void Shuffle(Random rng);
|
||||
bool IsLast();
|
||||
void ReorderFairly();
|
||||
int? GetLastQueuedIndex();
|
||||
}
|
@@ -260,7 +260,6 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
IsStopped = true;
|
||||
Log.Error("Please install ffmpeg and make sure it's added to your "
|
||||
+ "PATH environment variable before trying again");
|
||||
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
@@ -313,7 +312,7 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
{
|
||||
if (track.TrackInfo is SimpleTrackInfo sti)
|
||||
return sti.StreamUrl;
|
||||
|
||||
|
||||
return await _ytResolverFactory.GetYoutubeResolver().GetStreamUrl(track.TrackInfo.Id);
|
||||
}
|
||||
|
||||
@@ -420,20 +419,20 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
break;
|
||||
|
||||
await chunk.Select(async data =>
|
||||
{
|
||||
var (query, platform) = data;
|
||||
try
|
||||
{
|
||||
await TryEnqueueTrackAsync(query, queuer, false, platform);
|
||||
errorCount = 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Error resolving {MusicPlatform} Track {TrackQuery}", platform, query);
|
||||
++errorCount;
|
||||
}
|
||||
})
|
||||
.WhenAll();
|
||||
{
|
||||
var (query, platform) = data;
|
||||
try
|
||||
{
|
||||
await TryEnqueueTrackAsync(query, queuer, false, platform);
|
||||
errorCount = 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Error resolving {MusicPlatform} Track {TrackQuery}", platform, query);
|
||||
++errorCount;
|
||||
}
|
||||
})
|
||||
.WhenAll();
|
||||
|
||||
await Task.Delay(1000);
|
||||
|
||||
@@ -542,4 +541,15 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
{
|
||||
_queue.ReorderFairly();
|
||||
}
|
||||
|
||||
public Task<IQueuedTrackInfo?> RemoveLastQueuedTrack()
|
||||
{
|
||||
var last = _queue.GetLastQueuedIndex();
|
||||
if (last is null)
|
||||
return Task.FromResult<IQueuedTrackInfo?>(null);
|
||||
|
||||
return TryRemoveTrackAt(last.Value, out var trackInfo)
|
||||
? Task.FromResult(trackInfo)
|
||||
: Task.FromResult<IQueuedTrackInfo?>(null);
|
||||
}
|
||||
}
|
@@ -60,6 +60,7 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
private LinkedList<QueuedTrackInfo> tracks;
|
||||
|
||||
private int index;
|
||||
private int? _lastQueued = null;
|
||||
|
||||
private readonly object _locker = new();
|
||||
|
||||
@@ -74,7 +75,7 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
lock (_locker)
|
||||
{
|
||||
var added = new QueuedTrackInfo(trackInfo, queuer);
|
||||
enqueuedAt = tracks.Count;
|
||||
_lastQueued = enqueuedAt = tracks.Count;
|
||||
tracks.AddLast(added);
|
||||
|
||||
return added;
|
||||
@@ -99,6 +100,8 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
|
||||
tracks.AddAfter(currentNode, added);
|
||||
|
||||
_lastQueued = i;
|
||||
|
||||
return added;
|
||||
}
|
||||
}
|
||||
@@ -112,6 +115,8 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
var added = new QueuedTrackInfo(track, queuer);
|
||||
tracks.AddLast(added);
|
||||
}
|
||||
|
||||
_lastQueued = tracks.Count;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,6 +151,7 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
lock (_locker)
|
||||
{
|
||||
tracks.Clear();
|
||||
_lastQueued = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,6 +183,18 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
if (index < 0)
|
||||
index = Count;
|
||||
|
||||
if (i < _lastQueued)
|
||||
{
|
||||
if (_lastQueued is not null)
|
||||
{
|
||||
_lastQueued -= 1;
|
||||
}
|
||||
}
|
||||
else if (i == _lastQueued)
|
||||
{
|
||||
_lastQueued = null;
|
||||
}
|
||||
|
||||
// if it was the last song in the queue
|
||||
// // wrap back to start
|
||||
// if (_index == Count)
|
||||
@@ -207,6 +225,11 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
if (from >= Count || to >= Count)
|
||||
return null;
|
||||
|
||||
if (from == _lastQueued)
|
||||
_lastQueued = to;
|
||||
else if (to == _lastQueued)
|
||||
_lastQueued += 1;
|
||||
|
||||
// update current track index
|
||||
if (from == index)
|
||||
{
|
||||
@@ -267,6 +290,7 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
var list = tracks.ToArray();
|
||||
rng.Shuffle(list);
|
||||
tracks = new(list);
|
||||
_lastQueued = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,6 +342,8 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
if (queuers.Count == 0)
|
||||
break;
|
||||
}
|
||||
|
||||
_lastQueued = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,4 +365,6 @@ public sealed partial class MusicQueue : IMusicQueue
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public int? GetLastQueuedIndex() => _lastQueued;
|
||||
}
|
Reference in New Issue
Block a user