Fix author in playlist embeds and fix problem with playlists not having high res pictures leading to error.

changed LavalinkPlaylist to ILavallinkPlaylist
This commit is contained in:
EkiciLP 2022-03-24 08:51:40 +01:00
parent fbd8f3566d
commit 8720bf9f88
9 changed files with 27 additions and 18 deletions

@ -81,7 +81,7 @@ namespace TomatenMusic.Commands
{ {
if (response.isPlaylist) if (response.isPlaylist)
{ {
LavalinkPlaylist playlist = response.Playlist; ILavalinkPlaylist playlist = response.Playlist;
await player.PlayPlaylistNowAsync(playlist); await player.PlayPlaylistNowAsync(playlist);
_ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Now Playing:").AddEmbed( _ = ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Now Playing:").AddEmbed(
@ -234,7 +234,7 @@ namespace TomatenMusic.Commands
{ {
if (response.isPlaylist) if (response.isPlaylist)
{ {
LavalinkPlaylist playlist = response.Playlist; ILavalinkPlaylist playlist = response.Playlist;
await player.PlayPlaylistAsync(playlist); await player.PlayPlaylistAsync(playlist);
await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Now Playing:").AddEmbed( await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Now Playing:").AddEmbed(

@ -8,7 +8,7 @@ using Lavalink4NET.Player;
namespace TomatenMusic.Music.Entitites namespace TomatenMusic.Music.Entitites
{ {
public interface LavalinkPlaylist public interface ILavalinkPlaylist
{ {
public string Name { get; } public string Name { get; }
public IEnumerable<LavalinkTrack> Tracks { get; } public IEnumerable<LavalinkTrack> Tracks { get; }

@ -5,7 +5,7 @@ using System.Text;
namespace TomatenMusic.Music.Entitites namespace TomatenMusic.Music.Entitites
{ {
public class SpotifyPlaylist : LavalinkPlaylist public class SpotifyPlaylist : ILavalinkPlaylist
{ {
public string Name { get; } public string Name { get; }
public IEnumerable<LavalinkTrack> Tracks { get; } public IEnumerable<LavalinkTrack> Tracks { get; }

@ -9,7 +9,7 @@ using TomatenMusic.Services;
namespace TomatenMusic.Music.Entitites namespace TomatenMusic.Music.Entitites
{ {
public class YoutubePlaylist : LavalinkPlaylist public class YoutubePlaylist : ILavalinkPlaylist
{ {
public string Name { get; } public string Name { get; }

@ -114,7 +114,7 @@ namespace TomatenMusic.Music
QueuePrompt.UpdateFor(GuildId); QueuePrompt.UpdateFor(GuildId);
} }
public async Task PlayPlaylistAsync(LavalinkPlaylist playlist) public async Task PlayPlaylistAsync(ILavalinkPlaylist playlist)
{ {
EnsureNotDestroyed(); EnsureNotDestroyed();
EnsureConnected(); EnsureConnected();
@ -132,7 +132,7 @@ namespace TomatenMusic.Music
QueuePrompt.UpdateFor(GuildId); QueuePrompt.UpdateFor(GuildId);
} }
public async Task PlayPlaylistNowAsync(LavalinkPlaylist playlist) public async Task PlayPlaylistNowAsync(ILavalinkPlaylist playlist)
{ {
EnsureConnected(); EnsureConnected();
EnsureNotDestroyed(); EnsureNotDestroyed();

@ -8,11 +8,11 @@ namespace TomatenMusic.Music
{ {
public class MusicActionResponse public class MusicActionResponse
{ {
public LavalinkPlaylist Playlist { get; } public ILavalinkPlaylist Playlist { get; }
public LavalinkTrack Track { get; } public LavalinkTrack Track { get; }
public IEnumerable<LavalinkTrack> Tracks { get; } public IEnumerable<LavalinkTrack> Tracks { get; }
public bool isPlaylist { get; } public bool isPlaylist { get; }
public MusicActionResponse(LavalinkTrack track = null, LavalinkPlaylist playlist = null, IEnumerable<LavalinkTrack> tracks = null) public MusicActionResponse(LavalinkTrack track = null, ILavalinkPlaylist playlist = null, IEnumerable<LavalinkTrack> tracks = null)
{ {
Playlist = playlist; Playlist = playlist;
Track = track; Track = track;

@ -18,7 +18,7 @@ namespace TomatenMusic.Music
public Queue<LavalinkTrack> Queue { get; set; } = new Queue<LavalinkTrack>(); public Queue<LavalinkTrack> Queue { get; set; } = new Queue<LavalinkTrack>();
public Queue<LavalinkTrack> PlayedTracks { get; set; } = new Queue<LavalinkTrack>(); public Queue<LavalinkTrack> PlayedTracks { get; set; } = new Queue<LavalinkTrack>();
public ILogger<PlayerQueue> _logger { get; set; } = TomatenMusicBot.ServiceProvider.GetRequiredService<ILogger<PlayerQueue>>(); public ILogger<PlayerQueue> _logger { get; set; } = TomatenMusicBot.ServiceProvider.GetRequiredService<ILogger<PlayerQueue>>();
public LavalinkPlaylist CurrentPlaylist { get; set; } public ILavalinkPlaylist CurrentPlaylist { get; set; }
public LoopType LoopType { get; private set; } = LoopType.NONE; public LoopType LoopType { get; private set; } = LoopType.NONE;
@ -36,7 +36,7 @@ namespace TomatenMusic.Music
QueueLoopList.Add(track); QueueLoopList.Add(track);
} }
public Task QueuePlaylistAsync(LavalinkPlaylist playlist) public Task QueuePlaylistAsync(ILavalinkPlaylist playlist)
{ {
return Task.Run(() => return Task.Run(() =>
{ {

@ -37,7 +37,7 @@ namespace TomatenMusic.Services
if (channel.Statistics.SubscriberCount != null) if (channel.Statistics.SubscriberCount != null)
context.YoutubeAuthorSubs = (ulong) channel.Statistics.SubscriberCount; 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}"); context.YoutubeAuthorUri = new Uri($"https://www.youtube.com/channel/{channel.Id}");
string desc = video.Snippet.Description; string desc = video.Snippet.Description;
@ -45,7 +45,12 @@ namespace TomatenMusic.Services
if (video.Statistics.LikeCount != null) if (video.Statistics.LikeCount != null)
context.YoutubeLikes = (ulong) video.Statistics.LikeCount; context.YoutubeLikes = (ulong) video.Statistics.LikeCount;
context.YoutubeTags = video.Snippet.Tags; 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.YoutubeUploadDate = (DateTime)video.Snippet.PublishedAt;
context.YoutubeViews = (ulong)video.Statistics.ViewCount; context.YoutubeViews = (ulong)video.Statistics.ViewCount;
context.YoutubeCommentCount = video.Statistics.CommentCount; context.YoutubeCommentCount = video.Statistics.CommentCount;
@ -61,7 +66,7 @@ namespace TomatenMusic.Services
return newTracks; return newTracks;
} }
public async Task<LavalinkPlaylist> PopulatePlaylistAsync(YoutubePlaylist playlist) public async Task<ILavalinkPlaylist> PopulatePlaylistAsync(YoutubePlaylist playlist)
{ {
var list = await GetPlaylistAsync(playlist.Identifier); var list = await GetPlaylistAsync(playlist.Identifier);
var channel = await GetChannelAsync(list.Snippet.ChannelId); var channel = await GetChannelAsync(list.Snippet.ChannelId);
@ -72,10 +77,14 @@ namespace TomatenMusic.Services
if (playlist.Description.Length < 2) if (playlist.Description.Length < 2)
playlist.Description = "None"; 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.CreationTime = (DateTime)list.Snippet.PublishedAt;
playlist.YoutubeItem = list; 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}"); playlist.AuthorUri = new Uri($"https://www.youtube.com/channels/{channel.Id}");
return playlist; return playlist;

@ -92,7 +92,7 @@ namespace TomatenMusic.Util
return builder; return builder;
} }
public static DiscordEmbed AsEmbed(LavalinkPlaylist playlist) public static DiscordEmbed AsEmbed(ILavalinkPlaylist playlist)
{ {
DiscordEmbedBuilder builder = new DiscordEmbedBuilder(); DiscordEmbedBuilder builder = new DiscordEmbedBuilder();
@ -100,7 +100,7 @@ namespace TomatenMusic.Util
if (playlist is YoutubePlaylist) if (playlist is YoutubePlaylist)
{ {
YoutubePlaylist youtubePlaylist = (YoutubePlaylist)playlist; 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.WithAuthor(playlist.AuthorName, playlist.AuthorUri.ToString(), youtubePlaylist.AuthorThumbnail.ToString());
builder.WithTitle(playlist.Name); builder.WithTitle(playlist.Name);
builder.WithUrl(playlist.Url); builder.WithUrl(playlist.Url);