mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 17:58:26 -04:00
- Re-added .qap / .queueautoplay
- Several strings and commands related to music have been changed - Changed .ms / .movesong to .tm / .trackmove but kept old aliases - Changed ~~song~~ -> rack throughout music module strings - Updated CHANGELOG.md
This commit is contained in:
@@ -10,6 +10,7 @@ public interface IMusicPlayer : IDisposable
|
||||
bool IsKilled { get; }
|
||||
int CurrentIndex { get; }
|
||||
public PlayerRepeatType Repeat { get; }
|
||||
bool AutoPlay { get; set; }
|
||||
|
||||
void Stop();
|
||||
void Clear();
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
public interface ITrackInfo
|
||||
{
|
||||
public string Id => string.Empty;
|
||||
public string Title { get; }
|
||||
public string Url { get; }
|
||||
public string Thumbnail { get; }
|
||||
|
@@ -28,6 +28,7 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
private readonly IMusicQueue _queue;
|
||||
private readonly ITrackResolveProvider _trackResolveProvider;
|
||||
private readonly IVoiceProxy _proxy;
|
||||
private readonly IGoogleApiService _googleApiService;
|
||||
private readonly ISongBuffer _songBuffer;
|
||||
|
||||
private bool skipped;
|
||||
@@ -35,15 +36,21 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
private readonly Thread _thread;
|
||||
private readonly Random _rng;
|
||||
|
||||
public bool AutoPlay { get; set; }
|
||||
|
||||
public MusicPlayer(
|
||||
IMusicQueue queue,
|
||||
ITrackResolveProvider trackResolveProvider,
|
||||
IVoiceProxy proxy,
|
||||
QualityPreset qualityPreset)
|
||||
IGoogleApiService googleApiService,
|
||||
QualityPreset qualityPreset,
|
||||
bool autoPlay)
|
||||
{
|
||||
_queue = queue;
|
||||
_trackResolveProvider = trackResolveProvider;
|
||||
_proxy = proxy;
|
||||
_googleApiService = googleApiService;
|
||||
AutoPlay = autoPlay;
|
||||
_rng = new NadekoRandom();
|
||||
|
||||
_vc = GetVoiceClient(qualityPreset);
|
||||
@@ -265,7 +272,29 @@ public sealed class MusicPlayer : IMusicPlayer
|
||||
{
|
||||
cancellationTokenSource.Cancel();
|
||||
// turn off green in vc
|
||||
|
||||
_ = OnCompleted?.Invoke(this, track);
|
||||
|
||||
// todo update when settings are changed
|
||||
if (AutoPlay && track.Platform == MusicPlatform.Youtube)
|
||||
{
|
||||
try
|
||||
{
|
||||
var relatedSongs = await _googleApiService.GetRelatedVideosAsync(track.TrackInfo.Id, 5);
|
||||
var related = relatedSongs.Shuffle().FirstOrDefault();
|
||||
if (related is not null)
|
||||
{
|
||||
var relatedTrack = await _trackResolveProvider.QuerySongAsync(related, MusicPlatform.Youtube);
|
||||
if (relatedTrack is not null)
|
||||
EnqueueTrack(relatedTrack, "Autoplay");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Warning(ex, "Failed queueing a related song via autoplay");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
HandleQueuePostTrack();
|
||||
skipped = false;
|
||||
|
@@ -1,30 +1,15 @@
|
||||
namespace NadekoBot.Modules.Music;
|
||||
|
||||
public sealed class RemoteTrackInfo : ITrackInfo
|
||||
public sealed record RemoteTrackInfo(
|
||||
string Id,
|
||||
string Title,
|
||||
string Url,
|
||||
string Thumbnail,
|
||||
TimeSpan Duration,
|
||||
MusicPlatform Platform,
|
||||
Func<Task<string?>> _streamFactory) : ITrackInfo
|
||||
{
|
||||
public string Title { get; }
|
||||
public string Url { get; }
|
||||
public string Thumbnail { get; }
|
||||
public TimeSpan Duration { get; }
|
||||
public MusicPlatform Platform { get; }
|
||||
|
||||
private readonly Func<Task<string?>> _streamFactory;
|
||||
|
||||
public RemoteTrackInfo(
|
||||
string title,
|
||||
string url,
|
||||
string thumbnail,
|
||||
TimeSpan duration,
|
||||
MusicPlatform platform,
|
||||
Func<Task<string?>> streamFactory)
|
||||
{
|
||||
_streamFactory = streamFactory;
|
||||
Title = title;
|
||||
Url = url;
|
||||
Thumbnail = thumbnail;
|
||||
Duration = duration;
|
||||
Platform = platform;
|
||||
}
|
||||
private readonly Func<Task<string?>> _streamFactory = _streamFactory;
|
||||
|
||||
public async ValueTask<string?> GetStreamUrl()
|
||||
=> await _streamFactory();
|
||||
|
@@ -94,7 +94,9 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver
|
||||
}
|
||||
|
||||
private ITrackInfo DataToInfo(in YtTrackData trackData)
|
||||
=> new RemoteTrackInfo(trackData.Title,
|
||||
=> new RemoteTrackInfo(
|
||||
trackData.Id,
|
||||
trackData.Title,
|
||||
$"https://youtube.com/watch?v={trackData.Id}",
|
||||
trackData.Thumbnail,
|
||||
trackData.Duration,
|
||||
|
Reference in New Issue
Block a user