diff --git a/TomatenMusic/Program.cs b/TomatenMusic/Program.cs index a9be93b..a17217f 100644 --- a/TomatenMusic/Program.cs +++ b/TomatenMusic/Program.cs @@ -4,11 +4,9 @@ using TomatenMusic_Api.Auth.Services; var builder = WebApplication.CreateBuilder(args); -// Add services to the container. builder.Services.AddControllers(); builder.Services.AddCors(); -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); diff --git a/TomatenMusicCore/Music/Entitites/FullTrackContext.cs b/TomatenMusicCore/Music/Entitites/FullTrackContext.cs index 44b5ee9..df899c7 100644 --- a/TomatenMusicCore/Music/Entitites/FullTrackContext.cs +++ b/TomatenMusicCore/Music/Entitites/FullTrackContext.cs @@ -46,7 +46,6 @@ namespace TomatenMusic.Music.Entitites context.SpotifyIdentifier = spotifyIdentifier; context.YoutubeUri = new Uri($"https://youtu.be/{track.TrackIdentifier}"); track.Context = context; - Console.WriteLine(context); await youtubeService.PopulateTrackInfoAsync(track); await spotifyService.PopulateTrackAsync(track); diff --git a/TomatenMusicCore/Music/Entitites/YoutubePlaylist.cs b/TomatenMusicCore/Music/Entitites/YoutubePlaylist.cs index 2a35419..ac5e880 100644 --- a/TomatenMusicCore/Music/Entitites/YoutubePlaylist.cs +++ b/TomatenMusicCore/Music/Entitites/YoutubePlaylist.cs @@ -4,6 +4,8 @@ using System.Text; using System.Linq; using Google.Apis.YouTube.v3.Data; using Lavalink4NET.Player; +using Microsoft.Extensions.DependencyInjection; +using TomatenMusic.Services; namespace TomatenMusic.Music.Entitites { @@ -28,11 +30,12 @@ namespace TomatenMusic.Music.Entitites public YoutubePlaylist(string name, IEnumerable tracks, Uri uri) { - Identifier = uri.ToString().Replace("https://www.youtube.com/playlist?list=", ""); + Identifier = uri.ToString().Replace("https://www.youtube.com/playlist?list=", "").Replace("https://youtube.com/playlist?list=", ""); Name = name; Tracks = tracks; Url = uri; TrackCount = tracks.Count(); + } } } diff --git a/TomatenMusicCore/Services/TrackProvider.cs b/TomatenMusicCore/Services/TrackProvider.cs index 3c5f389..1c47d38 100644 --- a/TomatenMusicCore/Services/TrackProvider.cs +++ b/TomatenMusicCore/Services/TrackProvider.cs @@ -14,11 +14,13 @@ namespace TomatenMusic.Music { public ISpotifyService _spotifyService { get; set; } public IAudioService _audioService { get; set; } + public YoutubeService _youtubeService { get; set; } - public TrackProvider(ISpotifyService spotify, IAudioService audioService) + public TrackProvider(ISpotifyService spotify, IAudioService audioService, YoutubeService youtubeService) { _audioService = audioService; _spotifyService = spotify; + _youtubeService = youtubeService; } public async Task SearchAsync(string query, bool withSearchResults = false) @@ -55,7 +57,7 @@ namespace TomatenMusic.Music if (loadResult.LoadType == TrackLoadType.PlaylistLoaded && !isSearch) return new MusicActionResponse( - playlist: new YoutubePlaylist(loadResult.PlaylistInfo.Name, await FullTrackContext.PopulateTracksAsync(loadResult.Tracks), uri)); + playlist: await _youtubeService.PopulatePlaylistAsync(new YoutubePlaylist(loadResult.PlaylistInfo.Name, await FullTrackContext.PopulateTracksAsync(loadResult.Tracks), uri))); else return new MusicActionResponse(await FullTrackContext.PopulateAsync(loadResult.Tracks.First())); diff --git a/TomatenMusicCore/Services/YoutubeService.cs b/TomatenMusicCore/Services/YoutubeService.cs index 1adfd6a..26fbd28 100644 --- a/TomatenMusicCore/Services/YoutubeService.cs +++ b/TomatenMusicCore/Services/YoutubeService.cs @@ -53,7 +53,7 @@ namespace TomatenMusic.Services return track; } - public async Task> PopulateMultiTrackListAsync(IEnumerable tracks) + public async Task> PopulateTrackListAsync(IEnumerable tracks) { List newTracks = new List(); foreach (var track in tracks) @@ -69,14 +69,14 @@ namespace TomatenMusic.Services string desc = list.Snippet.Description; playlist.Description = desc.Substring(0, Math.Min(desc.Length, 1024)) + (desc.Length > 1020 ? "..." : " "); - if (playlist.Description == "") + if (playlist.Description.Length < 2) playlist.Description = "None"; playlist.Thumbnail = new Uri(list.Snippet.Thumbnails.High.Url); playlist.CreationTime = (DateTime)list.Snippet.PublishedAt; playlist.YoutubeItem = list; playlist.AuthorThumbnail = new Uri(channel.Snippet.Thumbnails.High.Url); - playlist.AuthorUri = new Uri($"https://www.youtube.com/playlist?list={playlist.Identifier}"); + 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 8fbcdd3..2258a7e 100644 --- a/TomatenMusicCore/Util/Common.cs +++ b/TomatenMusicCore/Util/Common.cs @@ -100,28 +100,28 @@ namespace TomatenMusic.Util if (playlist is YoutubePlaylist) { YoutubePlaylist youtubePlaylist = (YoutubePlaylist)playlist; - builder - .WithAuthor(playlist.AuthorName, playlist.AuthorUri.ToString(), youtubePlaylist.AuthorThumbnail.ToString()) - .WithTitle(playlist.Name) - .WithUrl(playlist.Url) - .WithDescription(TrackListString(playlist.Tracks)) - .WithImageUrl(youtubePlaylist.Thumbnail) - .AddField("Description", playlist.Description, false) - .AddField("Track Count", $"{playlist.Tracks.Count()} Tracks", true) - .AddField("Length", $"{Common.GetTimestamp(playlist.GetLength())}", true) - .AddField("Create Date", $"{youtubePlaylist.CreationTime:dd. MMMM, yyyy}", true); + + builder.WithAuthor(playlist.AuthorName, playlist.AuthorUri.ToString(), youtubePlaylist.AuthorThumbnail.ToString()); + builder.WithTitle(playlist.Name); + builder.WithUrl(playlist.Url); + builder.WithDescription(TrackListString(playlist.Tracks)); + builder.WithImageUrl(youtubePlaylist.Thumbnail); + builder.AddField("Description", playlist.Description, false); + builder.AddField("Track Count", $"{playlist.Tracks.Count()} Tracks", true); + builder.AddField("Length", $"{Common.GetTimestamp(playlist.GetLength())}", true); + builder.AddField("Create Date", $"{youtubePlaylist.CreationTime:dd. MMMM, yyyy}", true); }else if (playlist is SpotifyPlaylist) { SpotifyPlaylist spotifyPlaylist = (SpotifyPlaylist)playlist; - builder - .WithTitle(playlist.Name) - .WithUrl(playlist.Url) - .WithDescription(TrackListString(playlist.Tracks)) - .AddField("Description", playlist.Description, false) - .AddField("Track Count", $"{playlist.Tracks.Count()} Tracks", true) - .AddField("Length", $"{Common.GetTimestamp(playlist.GetLength())}", true) - .AddField("Spotify Followers", $"{spotifyPlaylist.Followers:N0}", true); + + builder.WithTitle(playlist.Name); + builder.WithUrl(playlist.Url); + builder.WithDescription(TrackListString(playlist.Tracks)); + builder.AddField("Description", playlist.Description, false); + builder.AddField("Track Count", $"{playlist.Tracks.Count()} Tracks", true); + builder.AddField("Length", $"{Common.GetTimestamp(playlist.GetLength())}", true); + builder.AddField("Spotify Followers", $"{spotifyPlaylist.Followers:N0}", true); if (spotifyPlaylist.AuthorThumbnail != null) { builder.WithAuthor(playlist.AuthorName, playlist.AuthorUri.ToString(), spotifyPlaylist.AuthorThumbnail.ToString()); @@ -150,11 +150,12 @@ namespace TomatenMusic.Util builder.AddField("Length", GetTimestamp(timeSpan), true); builder.AddField("Loop Type", player.PlayerQueue.LoopType.ToString(), true); builder.AddField("Autoplay", player.Autoplay ? "✅" : "❌", true); - if (player.PlayerQueue.PlayedTracks.Any()) - builder.AddField("History", TrackListString(player.PlayerQueue.PlayedTracks), true); if (player.PlayerQueue.CurrentPlaylist != null) builder.AddField("Current Playlist", $"[{player.PlayerQueue.CurrentPlaylist.Name}]({player.PlayerQueue.CurrentPlaylist.Url})", true); + if (player.PlayerQueue.PlayedTracks.Any()) + builder.AddField("History", TrackListString(player.PlayerQueue.PlayedTracks), true); + return builder; }