From b23d1aa71cec66e4c23ddf1bebeffc974ab7814a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20M=C3=BCller?= Date: Mon, 28 Mar 2022 20:46:48 +0200 Subject: [PATCH] change some structure again fixed Rewind not restarting song https://cloud.tomatentum.net/apps/deck/#/board/19/card/241 added song queue prepend position https://cloud.tomatentum.net/apps/deck/#/board/19/card/224 --- TomatenMusicCore/Commands/PlayCommandGroup.cs | 5 +++-- TomatenMusicCore/Music/Entitites/FullTrackContext.cs | 1 + TomatenMusicCore/Music/Entitites/ILavalinkPlaylist.cs | 1 + TomatenMusicCore/Music/{ => Entitites}/IPlayableItem.cs | 2 +- TomatenMusicCore/Music/Entitites/SpotifyPlaylist.cs | 3 +++ .../Music/{ => Entitites}/TomatenMusicTrack.cs | 9 ++++++--- TomatenMusicCore/Music/{ => Entitites}/TrackList.cs | 4 +++- TomatenMusicCore/Music/Entitites/YoutubePlaylist.cs | 4 ++++ TomatenMusicCore/Music/GuildPlayer.cs | 3 ++- TomatenMusicCore/Music/MusicActionResponse.cs | 1 + TomatenMusicCore/Music/PlayerQueue.cs | 1 + TomatenMusicCore/Prompt/Buttons/AddToQueueButton.cs | 1 + .../Prompt/Implementation/PlaylistSongSelectorPrompt.cs | 1 + .../Prompt/Implementation/SongActionPrompt.cs | 1 + .../Prompt/Implementation/SongListActionPrompt.cs | 1 + .../Prompt/Implementation/SongSelectorPrompt.cs | 1 + TomatenMusicCore/Services/SpotifyService.cs | 1 + TomatenMusicCore/Services/TrackProvider.cs | 1 + TomatenMusicCore/Services/YoutubeService.cs | 1 + 19 files changed, 34 insertions(+), 8 deletions(-) rename TomatenMusicCore/Music/{ => Entitites}/IPlayableItem.cs (91%) rename TomatenMusicCore/Music/{ => Entitites}/TomatenMusicTrack.cs (84%) rename TomatenMusicCore/Music/{ => Entitites}/TrackList.cs (98%) diff --git a/TomatenMusicCore/Commands/PlayCommandGroup.cs b/TomatenMusicCore/Commands/PlayCommandGroup.cs index bf455f1..736594d 100644 --- a/TomatenMusicCore/Commands/PlayCommandGroup.cs +++ b/TomatenMusicCore/Commands/PlayCommandGroup.cs @@ -13,6 +13,7 @@ using TomatenMusic.Music; using TomatenMusic.Music.Entitites; using TomatenMusic.Util; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusic.Commands { @@ -250,7 +251,7 @@ namespace TomatenMusic.Commands _ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(player.State == PlayerState.NotPlaying ? "Now Playing:" : "Added to Queue") .AddEmbed(Common.AsEmbed(track, player.PlayerQueue.LoopType, player.State == PlayerState.NotPlaying ? 0 : player.PlayerQueue.Queue.Count + 1))); - await player.PlayAsync(response.Track); + await player.PlayItemAsync(response.Track); } } catch (Exception ex) @@ -317,7 +318,7 @@ namespace TomatenMusic.Commands _ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(player.State == PlayerState.NotPlaying ? "Now Playing:" : "Added to Queue") .AddEmbed(Common.AsEmbed(track, player.PlayerQueue.LoopType, player.State == PlayerState.NotPlaying ? 0 : player.PlayerQueue.Queue.Count + 1))); - await player.PlayAsync(response.Track); + await player.PlayItemAsync(response.Track); sw.Stop(); _logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute."); diff --git a/TomatenMusicCore/Music/Entitites/FullTrackContext.cs b/TomatenMusicCore/Music/Entitites/FullTrackContext.cs index c4c44b1..03e6b19 100644 --- a/TomatenMusicCore/Music/Entitites/FullTrackContext.cs +++ b/TomatenMusicCore/Music/Entitites/FullTrackContext.cs @@ -9,6 +9,7 @@ using Lavalink4NET.Player; using Microsoft.Extensions.DependencyInjection; using Lavalink4NET; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusic.Music.Entitites { diff --git a/TomatenMusicCore/Music/Entitites/ILavalinkPlaylist.cs b/TomatenMusicCore/Music/Entitites/ILavalinkPlaylist.cs index 1cbf7a1..6b88c74 100644 --- a/TomatenMusicCore/Music/Entitites/ILavalinkPlaylist.cs +++ b/TomatenMusicCore/Music/Entitites/ILavalinkPlaylist.cs @@ -6,6 +6,7 @@ using TomatenMusic.Util; using DSharpPlus.Entities; using Lavalink4NET.Player; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusic.Music.Entitites { diff --git a/TomatenMusicCore/Music/IPlayableItem.cs b/TomatenMusicCore/Music/Entitites/IPlayableItem.cs similarity index 91% rename from TomatenMusicCore/Music/IPlayableItem.cs rename to TomatenMusicCore/Music/Entitites/IPlayableItem.cs index 7dd682a..d322170 100644 --- a/TomatenMusicCore/Music/IPlayableItem.cs +++ b/TomatenMusicCore/Music/Entitites/IPlayableItem.cs @@ -5,7 +5,7 @@ using System.Text; using System.Threading.Tasks; using TomatenMusic.Music; -namespace TomatenMusicCore.Music +namespace TomatenMusicCore.Music.Entities { public interface IPlayableItem { diff --git a/TomatenMusicCore/Music/Entitites/SpotifyPlaylist.cs b/TomatenMusicCore/Music/Entitites/SpotifyPlaylist.cs index ce90ff2..c2296c0 100644 --- a/TomatenMusicCore/Music/Entitites/SpotifyPlaylist.cs +++ b/TomatenMusicCore/Music/Entitites/SpotifyPlaylist.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Text; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusic.Music.Entitites { @@ -43,6 +44,8 @@ namespace TomatenMusic.Music.Entitites if (!player.PlayerQueue.Queue.Any()) player.PlayerQueue.CurrentPlaylist = this; + player.PlayerQueue.Queue = new Queue(player.PlayerQueue.Queue.Prepend(new TomatenMusicTrack(player.PlayerQueue.LastTrack.WithPosition(player.TrackPosition)))); + Queue reversedTracks = new Queue(Tracks); TomatenMusicTrack track = reversedTracks.Dequeue(); diff --git a/TomatenMusicCore/Music/TomatenMusicTrack.cs b/TomatenMusicCore/Music/Entitites/TomatenMusicTrack.cs similarity index 84% rename from TomatenMusicCore/Music/TomatenMusicTrack.cs rename to TomatenMusicCore/Music/Entitites/TomatenMusicTrack.cs index 47c7e10..658e0a6 100644 --- a/TomatenMusicCore/Music/TomatenMusicTrack.cs +++ b/TomatenMusicCore/Music/Entitites/TomatenMusicTrack.cs @@ -7,17 +7,18 @@ using System.Threading.Tasks; using TomatenMusic.Music; using TomatenMusic.Prompt.Implementation; -namespace TomatenMusicCore.Music +namespace TomatenMusicCore.Music.Entities { public class TomatenMusicTrack : LavalinkTrack, IPlayableItem { - + public override TimeSpan Position { get; } public TomatenMusicTrack (LavalinkTrack track) : base(track.Identifier, track.Author, track.Duration, track.IsLiveStream, track.IsSeekable, track.Source, track.Title, track.TrackIdentifier, track.Provider) { Context = track.Context; + Position = track.Position; } public string Title => base.Title; @@ -38,10 +39,12 @@ namespace TomatenMusicCore.Music public async Task PlayNow(GuildPlayer player, TimeSpan? startTime = null, TimeSpan? endTime = null, bool withoutQueuePrepend = false) { if (!withoutQueuePrepend) - player.PlayerQueue.Queue = new Queue(player.PlayerQueue.Queue.Prepend(player.PlayerQueue.LastTrack)); + player.PlayerQueue.Queue = new Queue(player.PlayerQueue.Queue.Prepend(new TomatenMusicTrack(player.PlayerQueue.LastTrack.WithPosition(player.TrackPosition)))); + player.PlayerQueue.LastTrack = this; await player.PlayAsync(this, startTime, endTime); } + } } diff --git a/TomatenMusicCore/Music/TrackList.cs b/TomatenMusicCore/Music/Entitites/TrackList.cs similarity index 98% rename from TomatenMusicCore/Music/TrackList.cs rename to TomatenMusicCore/Music/Entitites/TrackList.cs index d645a70..1ff34f4 100644 --- a/TomatenMusicCore/Music/TrackList.cs +++ b/TomatenMusicCore/Music/Entitites/TrackList.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; using System.Linq; using TomatenMusic.Music; -namespace TomatenMusicCore.Music +namespace TomatenMusicCore.Music.Entities { // // Summary: @@ -550,6 +550,8 @@ namespace TomatenMusicCore.Music { Queue reversedTracks = new Queue(this); + player.PlayerQueue.Queue = new Queue(player.PlayerQueue.Queue.Prepend(new TomatenMusicTrack(player.PlayerQueue.LastTrack.WithPosition(player.TrackPosition)))); + TomatenMusicTrack track = reversedTracks.Dequeue(); player.PlayerQueue.LastTrack = track; await player.PlayAsync(track, startTime, endTime); diff --git a/TomatenMusicCore/Music/Entitites/YoutubePlaylist.cs b/TomatenMusicCore/Music/Entitites/YoutubePlaylist.cs index ce804b7..641a21e 100644 --- a/TomatenMusicCore/Music/Entitites/YoutubePlaylist.cs +++ b/TomatenMusicCore/Music/Entitites/YoutubePlaylist.cs @@ -7,6 +7,7 @@ using Lavalink4NET.Player; using Microsoft.Extensions.DependencyInjection; using TomatenMusic.Services; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusic.Music.Entitites { @@ -56,6 +57,9 @@ namespace TomatenMusic.Music.Entitites if (!player.PlayerQueue.Queue.Any()) player.PlayerQueue.CurrentPlaylist = this; + player.PlayerQueue.Queue = new Queue(player.PlayerQueue.Queue.Prepend(new TomatenMusicTrack(player.PlayerQueue.LastTrack.WithPosition(player.TrackPosition)))); + + Queue reversedTracks = new Queue(Tracks); TomatenMusicTrack track = reversedTracks.Dequeue(); diff --git a/TomatenMusicCore/Music/GuildPlayer.cs b/TomatenMusicCore/Music/GuildPlayer.cs index cb72509..c104fee 100644 --- a/TomatenMusicCore/Music/GuildPlayer.cs +++ b/TomatenMusicCore/Music/GuildPlayer.cs @@ -16,6 +16,7 @@ using Lavalink4NET.Rest; using Microsoft.Extensions.DependencyInjection; using Lavalink4NET.Decoding; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusic.Music { @@ -87,7 +88,7 @@ namespace TomatenMusic.Music { EnsureNotDestroyed(); EnsureConnected(); - if (Position.Position.Seconds < 4) + if (Position.Position.Seconds > 5) { await ReplayAsync(); return; diff --git a/TomatenMusicCore/Music/MusicActionResponse.cs b/TomatenMusicCore/Music/MusicActionResponse.cs index c0bbd99..17cd5ff 100644 --- a/TomatenMusicCore/Music/MusicActionResponse.cs +++ b/TomatenMusicCore/Music/MusicActionResponse.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Text; using TomatenMusic.Music.Entitites; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusic.Music { diff --git a/TomatenMusicCore/Music/PlayerQueue.cs b/TomatenMusicCore/Music/PlayerQueue.cs index 7c8be69..b705f8a 100644 --- a/TomatenMusicCore/Music/PlayerQueue.cs +++ b/TomatenMusicCore/Music/PlayerQueue.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Logging; using Lavalink4NET.Player; using Microsoft.Extensions.DependencyInjection; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusic.Music { diff --git a/TomatenMusicCore/Prompt/Buttons/AddToQueueButton.cs b/TomatenMusicCore/Prompt/Buttons/AddToQueueButton.cs index 5ffcd42..31c1b95 100644 --- a/TomatenMusicCore/Prompt/Buttons/AddToQueueButton.cs +++ b/TomatenMusicCore/Prompt/Buttons/AddToQueueButton.cs @@ -10,6 +10,7 @@ using TomatenMusic.Music; using TomatenMusic.Music.Entitites; using Microsoft.Extensions.DependencyInjection; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusic.Prompt.Buttons { diff --git a/TomatenMusicCore/Prompt/Implementation/PlaylistSongSelectorPrompt.cs b/TomatenMusicCore/Prompt/Implementation/PlaylistSongSelectorPrompt.cs index 1d0d9a4..152b173 100644 --- a/TomatenMusicCore/Prompt/Implementation/PlaylistSongSelectorPrompt.cs +++ b/TomatenMusicCore/Prompt/Implementation/PlaylistSongSelectorPrompt.cs @@ -13,6 +13,7 @@ using TomatenMusic.Prompt; using TomatenMusic.Prompt.Model; using TomatenMusic.Util; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusicCore.Prompt.Implementation { diff --git a/TomatenMusicCore/Prompt/Implementation/SongActionPrompt.cs b/TomatenMusicCore/Prompt/Implementation/SongActionPrompt.cs index 05ee31a..7f12d52 100644 --- a/TomatenMusicCore/Prompt/Implementation/SongActionPrompt.cs +++ b/TomatenMusicCore/Prompt/Implementation/SongActionPrompt.cs @@ -9,6 +9,7 @@ using TomatenMusic.Prompt.Buttons; using TomatenMusic.Prompt.Model; using TomatenMusic.Util; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusic.Prompt.Implementation { diff --git a/TomatenMusicCore/Prompt/Implementation/SongListActionPrompt.cs b/TomatenMusicCore/Prompt/Implementation/SongListActionPrompt.cs index 2c68c2c..7d04a9e 100644 --- a/TomatenMusicCore/Prompt/Implementation/SongListActionPrompt.cs +++ b/TomatenMusicCore/Prompt/Implementation/SongListActionPrompt.cs @@ -12,6 +12,7 @@ using Microsoft.Extensions.Logging; using TomatenMusic.Prompt.Buttons; using Lavalink4NET.Player; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusic.Prompt.Implementation { diff --git a/TomatenMusicCore/Prompt/Implementation/SongSelectorPrompt.cs b/TomatenMusicCore/Prompt/Implementation/SongSelectorPrompt.cs index ea80ea2..830428d 100644 --- a/TomatenMusicCore/Prompt/Implementation/SongSelectorPrompt.cs +++ b/TomatenMusicCore/Prompt/Implementation/SongSelectorPrompt.cs @@ -13,6 +13,7 @@ using TomatenMusic.Music; using System.Linq; using Lavalink4NET.Player; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusic.Prompt.Implementation { diff --git a/TomatenMusicCore/Services/SpotifyService.cs b/TomatenMusicCore/Services/SpotifyService.cs index 463cab9..bf9814e 100644 --- a/TomatenMusicCore/Services/SpotifyService.cs +++ b/TomatenMusicCore/Services/SpotifyService.cs @@ -13,6 +13,7 @@ using Lavalink4NET; using Lavalink4NET.Player; using System.Runtime.Caching; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusic.Services { diff --git a/TomatenMusicCore/Services/TrackProvider.cs b/TomatenMusicCore/Services/TrackProvider.cs index 0523a4e..4811406 100644 --- a/TomatenMusicCore/Services/TrackProvider.cs +++ b/TomatenMusicCore/Services/TrackProvider.cs @@ -9,6 +9,7 @@ using System.Web; using TomatenMusic.Music.Entitites; using TomatenMusic.Services; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusic.Music { diff --git a/TomatenMusicCore/Services/YoutubeService.cs b/TomatenMusicCore/Services/YoutubeService.cs index 28e953b..abda1f3 100644 --- a/TomatenMusicCore/Services/YoutubeService.cs +++ b/TomatenMusicCore/Services/YoutubeService.cs @@ -13,6 +13,7 @@ using Lavalink4NET.Player; using Microsoft.Extensions.DependencyInjection; using Lavalink4NET; using TomatenMusicCore.Music; +using TomatenMusicCore.Music.Entities; namespace TomatenMusic.Services {