From 8720bf9f888c3c6a586a123f769f0cf5f4e76526 Mon Sep 17 00:00:00 2001 From: EkiciLP Date: Thu, 24 Mar 2022 08:51:40 +0100 Subject: [PATCH] Fix author in playlist embeds and fix problem with playlists not having high res pictures leading to error. changed LavalinkPlaylist to ILavallinkPlaylist --- TomatenMusicCore/Commands/PlayCommandGroup.cs | 4 ++-- ...valinkPlaylist.cs => ILavalinkPlaylist.cs} | 2 +- .../Music/Entitites/SpotifyPlaylist.cs | 2 +- .../Music/Entitites/YoutubePlaylist.cs | 2 +- TomatenMusicCore/Music/GuildPlayer.cs | 4 ++-- TomatenMusicCore/Music/MusicActionResponse.cs | 4 ++-- TomatenMusicCore/Music/PlayerQueue.cs | 4 ++-- TomatenMusicCore/Services/YoutubeService.cs | 19 ++++++++++++++----- TomatenMusicCore/Util/Common.cs | 4 ++-- 9 files changed, 27 insertions(+), 18 deletions(-) rename TomatenMusicCore/Music/Entitites/{LavalinkPlaylist.cs => ILavalinkPlaylist.cs} (95%) diff --git a/TomatenMusicCore/Commands/PlayCommandGroup.cs b/TomatenMusicCore/Commands/PlayCommandGroup.cs index 0d89f20..07b79ab 100644 --- a/TomatenMusicCore/Commands/PlayCommandGroup.cs +++ b/TomatenMusicCore/Commands/PlayCommandGroup.cs @@ -81,7 +81,7 @@ namespace TomatenMusic.Commands { if (response.isPlaylist) { - LavalinkPlaylist playlist = response.Playlist; + ILavalinkPlaylist playlist = response.Playlist; await player.PlayPlaylistNowAsync(playlist); _ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Now Playing:").AddEmbed( @@ -234,7 +234,7 @@ namespace TomatenMusic.Commands { if (response.isPlaylist) { - LavalinkPlaylist playlist = response.Playlist; + ILavalinkPlaylist playlist = response.Playlist; await player.PlayPlaylistAsync(playlist); await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Now Playing:").AddEmbed( diff --git a/TomatenMusicCore/Music/Entitites/LavalinkPlaylist.cs b/TomatenMusicCore/Music/Entitites/ILavalinkPlaylist.cs similarity index 95% rename from TomatenMusicCore/Music/Entitites/LavalinkPlaylist.cs rename to TomatenMusicCore/Music/Entitites/ILavalinkPlaylist.cs index 33eb033..bca38a2 100644 --- a/TomatenMusicCore/Music/Entitites/LavalinkPlaylist.cs +++ b/TomatenMusicCore/Music/Entitites/ILavalinkPlaylist.cs @@ -8,7 +8,7 @@ using Lavalink4NET.Player; namespace TomatenMusic.Music.Entitites { - public interface LavalinkPlaylist + public interface ILavalinkPlaylist { public string Name { get; } public IEnumerable Tracks { get; } diff --git a/TomatenMusicCore/Music/Entitites/SpotifyPlaylist.cs b/TomatenMusicCore/Music/Entitites/SpotifyPlaylist.cs index ed4745d..ef0840f 100644 --- a/TomatenMusicCore/Music/Entitites/SpotifyPlaylist.cs +++ b/TomatenMusicCore/Music/Entitites/SpotifyPlaylist.cs @@ -5,7 +5,7 @@ using System.Text; namespace TomatenMusic.Music.Entitites { - public class SpotifyPlaylist : LavalinkPlaylist + public class SpotifyPlaylist : ILavalinkPlaylist { public string Name { get; } public IEnumerable Tracks { get; } diff --git a/TomatenMusicCore/Music/Entitites/YoutubePlaylist.cs b/TomatenMusicCore/Music/Entitites/YoutubePlaylist.cs index ac5e880..5699ab2 100644 --- a/TomatenMusicCore/Music/Entitites/YoutubePlaylist.cs +++ b/TomatenMusicCore/Music/Entitites/YoutubePlaylist.cs @@ -9,7 +9,7 @@ using TomatenMusic.Services; namespace TomatenMusic.Music.Entitites { - public class YoutubePlaylist : LavalinkPlaylist + public class YoutubePlaylist : ILavalinkPlaylist { public string Name { get; } diff --git a/TomatenMusicCore/Music/GuildPlayer.cs b/TomatenMusicCore/Music/GuildPlayer.cs index e8c54cf..91711a9 100644 --- a/TomatenMusicCore/Music/GuildPlayer.cs +++ b/TomatenMusicCore/Music/GuildPlayer.cs @@ -114,7 +114,7 @@ namespace TomatenMusic.Music QueuePrompt.UpdateFor(GuildId); } - public async Task PlayPlaylistAsync(LavalinkPlaylist playlist) + public async Task PlayPlaylistAsync(ILavalinkPlaylist playlist) { EnsureNotDestroyed(); EnsureConnected(); @@ -132,7 +132,7 @@ namespace TomatenMusic.Music QueuePrompt.UpdateFor(GuildId); } - public async Task PlayPlaylistNowAsync(LavalinkPlaylist playlist) + public async Task PlayPlaylistNowAsync(ILavalinkPlaylist playlist) { EnsureConnected(); EnsureNotDestroyed(); diff --git a/TomatenMusicCore/Music/MusicActionResponse.cs b/TomatenMusicCore/Music/MusicActionResponse.cs index 2c58b47..e4f9eef 100644 --- a/TomatenMusicCore/Music/MusicActionResponse.cs +++ b/TomatenMusicCore/Music/MusicActionResponse.cs @@ -8,11 +8,11 @@ namespace TomatenMusic.Music { public class MusicActionResponse { - public LavalinkPlaylist Playlist { get; } + public ILavalinkPlaylist Playlist { get; } public LavalinkTrack Track { get; } public IEnumerable Tracks { get; } public bool isPlaylist { get; } - public MusicActionResponse(LavalinkTrack track = null, LavalinkPlaylist playlist = null, IEnumerable tracks = null) + public MusicActionResponse(LavalinkTrack track = null, ILavalinkPlaylist playlist = null, IEnumerable tracks = null) { Playlist = playlist; Track = track; diff --git a/TomatenMusicCore/Music/PlayerQueue.cs b/TomatenMusicCore/Music/PlayerQueue.cs index 9ab8453..7bc84f5 100644 --- a/TomatenMusicCore/Music/PlayerQueue.cs +++ b/TomatenMusicCore/Music/PlayerQueue.cs @@ -18,7 +18,7 @@ namespace TomatenMusic.Music public Queue Queue { get; set; } = new Queue(); public Queue PlayedTracks { get; set; } = new Queue(); public ILogger _logger { get; set; } = TomatenMusicBot.ServiceProvider.GetRequiredService>(); - public LavalinkPlaylist CurrentPlaylist { get; set; } + public ILavalinkPlaylist CurrentPlaylist { get; set; } public LoopType LoopType { get; private set; } = LoopType.NONE; @@ -36,7 +36,7 @@ namespace TomatenMusic.Music QueueLoopList.Add(track); } - public Task QueuePlaylistAsync(LavalinkPlaylist playlist) + public Task QueuePlaylistAsync(ILavalinkPlaylist playlist) { return Task.Run(() => { diff --git a/TomatenMusicCore/Services/YoutubeService.cs b/TomatenMusicCore/Services/YoutubeService.cs index 26fbd28..7f45f5b 100644 --- a/TomatenMusicCore/Services/YoutubeService.cs +++ b/TomatenMusicCore/Services/YoutubeService.cs @@ -37,7 +37,7 @@ namespace TomatenMusic.Services if (channel.Statistics.SubscriberCount != null) context.YoutubeAuthorSubs = (ulong) channel.Statistics.SubscriberCount; - context.YoutubeAuthorThumbnail = new Uri(channel.Snippet.Thumbnails.High.Url); + context.YoutubeAuthorThumbnail = new Uri(channel.Snippet.Thumbnails.Default__.Url); context.YoutubeAuthorUri = new Uri($"https://www.youtube.com/channel/{channel.Id}"); string desc = video.Snippet.Description; @@ -45,7 +45,12 @@ namespace TomatenMusic.Services if (video.Statistics.LikeCount != null) context.YoutubeLikes = (ulong) video.Statistics.LikeCount; context.YoutubeTags = video.Snippet.Tags; - context.YoutubeThumbnail = new Uri(video.Snippet.Thumbnails.High.Url); + + try + { + context.YoutubeThumbnail = new Uri(video.Snippet.Thumbnails.High.Url); + }catch (Exception ex) { } + context.YoutubeUploadDate = (DateTime)video.Snippet.PublishedAt; context.YoutubeViews = (ulong)video.Statistics.ViewCount; context.YoutubeCommentCount = video.Statistics.CommentCount; @@ -61,7 +66,7 @@ namespace TomatenMusic.Services return newTracks; } - public async Task PopulatePlaylistAsync(YoutubePlaylist playlist) + public async Task PopulatePlaylistAsync(YoutubePlaylist playlist) { var list = await GetPlaylistAsync(playlist.Identifier); var channel = await GetChannelAsync(list.Snippet.ChannelId); @@ -72,10 +77,14 @@ namespace TomatenMusic.Services if (playlist.Description.Length < 2) playlist.Description = "None"; - playlist.Thumbnail = new Uri(list.Snippet.Thumbnails.High.Url); + try + { + playlist.Thumbnail = new Uri(list.Snippet.Thumbnails.Maxres.Url); + }catch (Exception ex) { } + playlist.AuthorName = channel.Snippet.Title; playlist.CreationTime = (DateTime)list.Snippet.PublishedAt; playlist.YoutubeItem = list; - playlist.AuthorThumbnail = new Uri(channel.Snippet.Thumbnails.High.Url); + playlist.AuthorThumbnail = new Uri(channel.Snippet.Thumbnails.Default__.Url); playlist.AuthorUri = new Uri($"https://www.youtube.com/channels/{channel.Id}"); return playlist; diff --git a/TomatenMusicCore/Util/Common.cs b/TomatenMusicCore/Util/Common.cs index 2258a7e..531cf59 100644 --- a/TomatenMusicCore/Util/Common.cs +++ b/TomatenMusicCore/Util/Common.cs @@ -92,7 +92,7 @@ namespace TomatenMusic.Util return builder; } - public static DiscordEmbed AsEmbed(LavalinkPlaylist playlist) + public static DiscordEmbed AsEmbed(ILavalinkPlaylist playlist) { DiscordEmbedBuilder builder = new DiscordEmbedBuilder(); @@ -100,7 +100,7 @@ namespace TomatenMusic.Util if (playlist is YoutubePlaylist) { YoutubePlaylist youtubePlaylist = (YoutubePlaylist)playlist; - + Console.WriteLine($"{playlist.AuthorName}, {playlist.AuthorUri.ToString()}, {playlist.AuthorThumbnail.ToString()}"); builder.WithAuthor(playlist.AuthorName, playlist.AuthorUri.ToString(), youtubePlaylist.AuthorThumbnail.ToString()); builder.WithTitle(playlist.Name); builder.WithUrl(playlist.Url);