Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
fbd8f3566d | ||
![]() |
64bbf0598e | ||
![]() |
370d018c92 | ||
![]() |
9eecccf0e0 | ||
![]() |
7604f7af88 | ||
![]() |
9c162ee934 | ||
![]() |
31ddb54e5a | ||
![]() |
22e2318843 | ||
![]() |
90514e8e62 | ||
![]() |
3bdb592671 | ||
![]() |
6e2f05c9b8 | ||
![]() |
f7f0c90570 |
@@ -4,7 +4,7 @@ branches:
|
||||
regex: ^master$|^main$
|
||||
mode: ContinuousDelivery
|
||||
tag: ''
|
||||
increment: None
|
||||
increment: Minor
|
||||
prevent-increment-of-merged-branch-version: true
|
||||
track-merge-target: false
|
||||
source-branches: [ 'develop', 'release' ]
|
||||
@@ -16,7 +16,7 @@ branches:
|
||||
regex: ^dev(elop)?(ment)?$
|
||||
mode: ContinuousDeployment
|
||||
tag: pre
|
||||
increment: None
|
||||
increment: Patch
|
||||
prevent-increment-of-merged-branch-version: false
|
||||
track-merge-target: true
|
||||
source-branches: []
|
||||
@@ -27,3 +27,7 @@ branches:
|
||||
ignore:
|
||||
sha: []
|
||||
merge-message-formats: {}
|
||||
major-version-bump-message: '\+semver:\s?(breaking|major)'
|
||||
minor-version-bump-message: '\+semver:\s?(feature|minor)'
|
||||
patch-version-bump-message: '\+semver:\s?(fix|patch)'
|
||||
commit-message-incrementing: Enabled
|
||||
|
@@ -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();
|
||||
|
||||
|
@@ -4,8 +4,8 @@
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Information"
|
||||
"Default": "Debug",
|
||||
"Microsoft.AspNetCore": "Debug"
|
||||
}
|
||||
}
|
||||
}
|
@@ -5,6 +5,7 @@ using Lavalink4NET.Player;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TomatenMusic.Commands.Checks;
|
||||
@@ -35,6 +36,8 @@ namespace TomatenMusic.Commands
|
||||
[OnlyGuildCheck]
|
||||
public async Task PlayQueryCommand(InteractionContext ctx, [Option("query", "The song search query.")] string query)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
await ctx.DeferAsync(true);
|
||||
|
||||
GuildPlayer player = (GuildPlayer)_audioService.GetPlayer(ctx.Guild.Id);
|
||||
@@ -50,6 +53,8 @@ namespace TomatenMusic.Commands
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while resolving your query: ``{ex.Message}``, ```{ex.StackTrace}```")
|
||||
);
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -66,6 +71,8 @@ namespace TomatenMusic.Commands
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while connecting to your Channel: ``{ex.Message}``")
|
||||
);
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -97,8 +104,12 @@ namespace TomatenMusic.Commands
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while playing your Query: ``{ex.Message}``")
|
||||
);
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute.");
|
||||
return;
|
||||
}
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute.");
|
||||
}
|
||||
|
||||
[SlashCommand("file", "Play a song file. (mp3/mp4)")]
|
||||
@@ -107,6 +118,7 @@ namespace TomatenMusic.Commands
|
||||
[OnlyGuildCheck]
|
||||
public async Task PlayFileCommand(InteractionContext ctx, [Option("File", "The File that should be played.")] DiscordAttachment file)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
await ctx.DeferAsync(true);
|
||||
|
||||
@@ -123,6 +135,8 @@ namespace TomatenMusic.Commands
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while resolving your file: ``{ex.Message}``")
|
||||
);
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -138,6 +152,8 @@ namespace TomatenMusic.Commands
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while connecting to your Channel: ``{ex.Message}``")
|
||||
);
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -148,6 +164,8 @@ namespace TomatenMusic.Commands
|
||||
.AddEmbed(Common.AsEmbed(track, player.PlayerQueue.LoopType, 0)));
|
||||
|
||||
await player.PlayNowAsync(response.Track);
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,6 +190,8 @@ namespace TomatenMusic.Commands
|
||||
[OnlyGuildCheck]
|
||||
public async Task PlayQueryCommand(InteractionContext ctx, [Option("query", "The song search query.")] string query)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
await ctx.DeferAsync(true);
|
||||
|
||||
GuildPlayer player = (GuildPlayer)_audioService.GetPlayer(ctx.Guild.Id);
|
||||
@@ -187,6 +207,8 @@ namespace TomatenMusic.Commands
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while resolving your query: ``{ex.Message}``, ```{ex.StackTrace}```")
|
||||
);
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -202,6 +224,8 @@ namespace TomatenMusic.Commands
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while connecting to your Channel: ``{ex.Message}``")
|
||||
);
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -233,8 +257,12 @@ namespace TomatenMusic.Commands
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while playing your Track: ``{ex.Message}``, ```{ex.StackTrace}```")
|
||||
);
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute.");
|
||||
return;
|
||||
}
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute.");
|
||||
}
|
||||
|
||||
[SlashCommand("file", "Play a song file. (mp3/mp4)")]
|
||||
@@ -243,6 +271,7 @@ namespace TomatenMusic.Commands
|
||||
[OnlyGuildCheck]
|
||||
public async Task PlayFileCommand(InteractionContext ctx, [Option("File", "The File that should be played.")] DiscordAttachment file)
|
||||
{
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
await ctx.DeferAsync(true);
|
||||
|
||||
@@ -259,6 +288,8 @@ namespace TomatenMusic.Commands
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while resolving your file: ``{ex.Message}``")
|
||||
);
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -274,6 +305,8 @@ namespace TomatenMusic.Commands
|
||||
await ctx.EditResponseAsync(new DiscordWebhookBuilder()
|
||||
.WithContent($"❌ An error occured while connecting to your Channel: ``{ex.Message}``")
|
||||
);
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -284,6 +317,9 @@ namespace TomatenMusic.Commands
|
||||
.AddEmbed(Common.AsEmbed(track, player.PlayerQueue.LoopType, player.State == PlayerState.NotPlaying ? 0 : player.PlayerQueue.Queue.Count + 1)));
|
||||
|
||||
await player.PlayAsync(response.Track);
|
||||
|
||||
sw.Stop();
|
||||
_logger.LogDebug($"Command {ctx.CommandName} took {sw.ElapsedMilliseconds}ms to execute.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -34,7 +34,7 @@ namespace TomatenMusic.Music.Entitites
|
||||
public int SpotifyPopularity { get; set; }
|
||||
public Uri SpotifyUri { get; set; }
|
||||
|
||||
public static async Task<LavalinkTrack> PopulateAsync(LavalinkTrack track, string spotifyIdentifier = null)
|
||||
public static async Task<LavalinkTrack> PopulateAsync(LavalinkTrack track, FullTrack spotifyTrack = null, string spotifyId = null)
|
||||
{
|
||||
FullTrackContext context = (FullTrackContext)track.Context;
|
||||
|
||||
@@ -43,12 +43,15 @@ namespace TomatenMusic.Music.Entitites
|
||||
|
||||
var spotifyService = TomatenMusicBot.ServiceProvider.GetRequiredService<ISpotifyService>();
|
||||
var youtubeService = TomatenMusicBot.ServiceProvider.GetRequiredService<YoutubeService>();
|
||||
context.SpotifyIdentifier = spotifyIdentifier;
|
||||
context.YoutubeUri = new Uri($"https://youtu.be/{track.TrackIdentifier}");
|
||||
if (spotifyId != null)
|
||||
context.SpotifyIdentifier = spotifyId;
|
||||
else if (spotifyTrack != null)
|
||||
context.SpotifyIdentifier = spotifyTrack.Id;
|
||||
|
||||
context.YoutubeUri = new Uri(track.Source);
|
||||
track.Context = context;
|
||||
Console.WriteLine(context);
|
||||
await youtubeService.PopulateTrackInfoAsync(track);
|
||||
await spotifyService.PopulateTrackAsync(track);
|
||||
await spotifyService.PopulateTrackAsync(track, spotifyTrack);
|
||||
|
||||
return track;
|
||||
}
|
||||
|
@@ -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<LavalinkTrack> 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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -134,7 +134,6 @@ namespace TomatenMusic.Music
|
||||
|
||||
public async Task PlayPlaylistNowAsync(LavalinkPlaylist playlist)
|
||||
{
|
||||
|
||||
EnsureConnected();
|
||||
EnsureNotDestroyed();
|
||||
if (!PlayerQueue.Queue.Any())
|
||||
@@ -159,6 +158,14 @@ namespace TomatenMusic.Music
|
||||
|
||||
public async Task RewindAsync()
|
||||
{
|
||||
EnsureNotDestroyed();
|
||||
EnsureConnected();
|
||||
if (Position.Position.Seconds < 4)
|
||||
{
|
||||
await ReplayAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
MusicActionResponse response = PlayerQueue.Rewind();
|
||||
|
||||
_logger.LogInformation($"Rewinded Track {CurrentTrack.Title} for Track {response.Track.Title}");
|
||||
@@ -168,6 +175,8 @@ namespace TomatenMusic.Music
|
||||
|
||||
public async Task SkipAsync()
|
||||
{
|
||||
EnsureNotDestroyed();
|
||||
EnsureConnected();
|
||||
MusicActionResponse response = PlayerQueue.NextTrack(true);
|
||||
|
||||
_logger.LogInformation($"Skipped Track {CurrentTrack.Title} for Track {response.Track.Title}");
|
||||
|
@@ -269,7 +269,10 @@ namespace TomatenMusic.Prompt.Implementation
|
||||
|
||||
protected async override Task<DiscordMessageBuilder> GetMessageAsync()
|
||||
{
|
||||
return new DiscordMessageBuilder().AddEmbed(Common.GetQueueEmbed(Player)).AddEmbed(await Common.CurrentSongEmbedAsync(Player)).AddEmbeds(Embeds);
|
||||
return new DiscordMessageBuilder()
|
||||
.AddEmbed(Common.GetQueueEmbed(Player))
|
||||
.AddEmbed(await Common.CurrentSongEmbedAsync(Player))
|
||||
.AddEmbeds(Embeds);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@ using TomatenMusic.Services;
|
||||
using TomatenMusic.Music;
|
||||
using Lavalink4NET;
|
||||
using Lavalink4NET.Player;
|
||||
using System.Runtime.Caching;
|
||||
|
||||
namespace TomatenMusic.Services
|
||||
{
|
||||
@@ -18,9 +19,9 @@ namespace TomatenMusic.Services
|
||||
public interface ISpotifyService
|
||||
{
|
||||
public Task<MusicActionResponse> ConvertURL(string url);
|
||||
public Task<SpotifyPlaylist> PopulateSpotifyPlaylistAsync(SpotifyPlaylist playlist);
|
||||
public Task<SpotifyPlaylist> PopulateSpotifyAlbumAsync(SpotifyPlaylist playlist);
|
||||
public Task<LavalinkTrack> PopulateTrackAsync(LavalinkTrack track);
|
||||
public Task<SpotifyPlaylist> PopulateSpotifyPlaylistAsync(SpotifyPlaylist playlist, FullPlaylist spotifyPlaylist = null);
|
||||
public Task<SpotifyPlaylist> PopulateSpotifyAlbumAsync(SpotifyPlaylist playlist, FullAlbum spotifyAlbum = null);
|
||||
public Task<LavalinkTrack> PopulateTrackAsync(LavalinkTrack track, FullTrack spotifyFullTrack = null);
|
||||
|
||||
}
|
||||
|
||||
@@ -29,10 +30,13 @@ namespace TomatenMusic.Services
|
||||
public ILogger _logger { get; set; }
|
||||
public IAudioService _audioService { get; set; }
|
||||
|
||||
public ObjectCache Cache { get; set; }
|
||||
|
||||
public SpotifyService(SpotifyClientConfig config, ILogger<SpotifyService> logger, IAudioService audioService) : base(config)
|
||||
{
|
||||
_logger = logger;
|
||||
_audioService = audioService;
|
||||
Cache = MemoryCache.Default;
|
||||
}
|
||||
|
||||
public async Task<MusicActionResponse> ConvertURL(string url)
|
||||
@@ -43,9 +47,11 @@ namespace TomatenMusic.Services
|
||||
.Replace("https://open.spotify.com/playlist/", "")
|
||||
.Substring(0, 22);
|
||||
|
||||
_logger.LogDebug($"Starting spotify conversion for: {url}");
|
||||
|
||||
if (url.StartsWith("https://open.spotify.com/track"))
|
||||
{
|
||||
FullTrack sTrack = await Tracks.Get(trackId);
|
||||
FullTrack sTrack = Cache.Contains(trackId) ? Cache.Get(trackId) as FullTrack : await Tracks.Get(trackId);
|
||||
|
||||
_logger.LogInformation($"Searching youtube from spotify with query: {sTrack.Name} {String.Join(" ", sTrack.Artists)}");
|
||||
|
||||
@@ -53,39 +59,43 @@ namespace TomatenMusic.Services
|
||||
|
||||
if (track == null) throw new ArgumentException("This Spotify Track was not found on Youtube");
|
||||
|
||||
return new MusicActionResponse(await FullTrackContext.PopulateAsync(track, trackId));
|
||||
Cache.Add(trackId, sTrack, DateTimeOffset.MaxValue);
|
||||
|
||||
return new MusicActionResponse(await FullTrackContext.PopulateAsync(track, sTrack));
|
||||
|
||||
}
|
||||
else if (url.StartsWith("https://open.spotify.com/album"))
|
||||
{
|
||||
List<LavalinkTrack> tracks = new List<LavalinkTrack>();
|
||||
|
||||
FullAlbum album = await Albums.Get(trackId);
|
||||
FullAlbum album = Cache.Contains(trackId) ? Cache.Get(trackId) as FullAlbum : await Albums.Get(trackId);
|
||||
|
||||
foreach (var sTrack in await PaginateAll(album.Tracks))
|
||||
{
|
||||
_logger.LogInformation($"Searching youtube from spotify with query: {sTrack.Name} {String.Join(" ", sTrack.Artists.ConvertAll(artist => artist.Name))}");
|
||||
|
||||
var track = await _audioService.GetTrackAsync($"{sTrack.Name} {String.Join(" ", sTrack.Artists.ConvertAll(artist => artist.Name))}", Lavalink4NET.Rest.SearchMode.YouTube);
|
||||
|
||||
if (track == null) throw new ArgumentException("This Spotify Track was not found on Youtube");
|
||||
|
||||
tracks.Add(await FullTrackContext.PopulateAsync(track, sTrack.Uri.Replace("spotify:track:", "")));
|
||||
tracks.Add(await FullTrackContext.PopulateAsync(track, spotifyId: sTrack.Uri.Replace("spotify:track:", "")));
|
||||
}
|
||||
Uri uri;
|
||||
Uri.TryCreate(url, UriKind.Absolute, out uri);
|
||||
|
||||
SpotifyPlaylist playlist = new SpotifyPlaylist(album.Name, album.Id, tracks, uri);
|
||||
await PopulateSpotifyAlbumAsync(playlist);
|
||||
await PopulateSpotifyAlbumAsync(playlist, album);
|
||||
|
||||
Cache.Add(trackId, album, DateTimeOffset.MaxValue);
|
||||
|
||||
return new MusicActionResponse(playlist: playlist);
|
||||
|
||||
}
|
||||
else if (url.StartsWith("https://open.spotify.com/playlist"))
|
||||
{
|
||||
|
||||
List<LavalinkTrack> tracks = new List<LavalinkTrack>();
|
||||
|
||||
FullPlaylist spotifyPlaylist = await Playlists.Get(trackId);
|
||||
FullPlaylist spotifyPlaylist = Cache.Contains(trackId) ? Cache.Get(trackId) as FullPlaylist : await Playlists.Get(trackId);
|
||||
|
||||
foreach (var sTrack in await PaginateAll(spotifyPlaylist.Tracks))
|
||||
{
|
||||
@@ -98,23 +108,28 @@ namespace TomatenMusic.Services
|
||||
|
||||
if (track == null) throw new ArgumentException("This Spotify Track was not found on Youtube");
|
||||
|
||||
tracks.Add(await FullTrackContext.PopulateAsync(track, fullTrack.Uri.Replace("spotify:track:", "")));
|
||||
tracks.Add(await FullTrackContext.PopulateAsync(track, fullTrack));
|
||||
}
|
||||
|
||||
}
|
||||
Uri uri;
|
||||
Uri.TryCreate(url, UriKind.Absolute, out uri);
|
||||
SpotifyPlaylist playlist = new SpotifyPlaylist(spotifyPlaylist.Name, spotifyPlaylist.Id, tracks, uri);
|
||||
await PopulateSpotifyPlaylistAsync(playlist);
|
||||
await PopulateSpotifyPlaylistAsync(playlist, spotifyPlaylist);
|
||||
|
||||
Cache.Add(trackId, spotifyPlaylist, DateTimeOffset.MaxValue);
|
||||
|
||||
return new MusicActionResponse(playlist: playlist);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<SpotifyPlaylist> PopulateSpotifyPlaylistAsync(SpotifyPlaylist playlist)
|
||||
public async Task<SpotifyPlaylist> PopulateSpotifyPlaylistAsync(SpotifyPlaylist playlist, FullPlaylist spotifyPlaylist = null)
|
||||
{
|
||||
var list = await this.Playlists.Get(playlist.Identifier);
|
||||
FullPlaylist list = spotifyPlaylist;
|
||||
if (list == null)
|
||||
list = await this.Playlists.Get(playlist.Identifier);
|
||||
|
||||
string desc = list.Description;
|
||||
|
||||
playlist.Description = desc.Substring(0, Math.Min(desc.Length, 1024)) + (desc.Length > 1020 ? "..." : " ");
|
||||
@@ -134,9 +149,12 @@ namespace TomatenMusic.Services
|
||||
return playlist;
|
||||
}
|
||||
|
||||
public async Task<SpotifyPlaylist> PopulateSpotifyAlbumAsync(SpotifyPlaylist playlist)
|
||||
public async Task<SpotifyPlaylist> PopulateSpotifyAlbumAsync(SpotifyPlaylist playlist, FullAlbum spotifyAlbum = null)
|
||||
{
|
||||
var list = await this.Albums.Get(playlist.Identifier);
|
||||
FullAlbum list = spotifyAlbum;
|
||||
if (list == null)
|
||||
list = await this.Albums.Get(playlist.Identifier);
|
||||
|
||||
string desc = list.Label;
|
||||
|
||||
playlist.Description = desc.Substring(0, Math.Min(desc.Length, 1024)) + (desc.Length > 1020 ? "..." : " ");
|
||||
@@ -148,13 +166,15 @@ namespace TomatenMusic.Services
|
||||
return playlist;
|
||||
}
|
||||
|
||||
public async Task<LavalinkTrack> PopulateTrackAsync(LavalinkTrack track)
|
||||
public async Task<LavalinkTrack> PopulateTrackAsync(LavalinkTrack track, FullTrack spotifyFullTrack)
|
||||
{
|
||||
FullTrackContext context = (FullTrackContext)track.Context;
|
||||
if (context.SpotifyIdentifier == null)
|
||||
return track;
|
||||
|
||||
var spotifyTrack = await this.Tracks.Get(context.SpotifyIdentifier);
|
||||
FullTrack spotifyTrack = spotifyFullTrack;
|
||||
if (spotifyTrack == null)
|
||||
spotifyTrack = await Tracks.Get(context.SpotifyIdentifier);
|
||||
|
||||
context.SpotifyAlbum = spotifyTrack.Album;
|
||||
context.SpotifyArtists = spotifyTrack.Artists;
|
||||
|
@@ -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<MusicActionResponse> 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()));
|
||||
|
||||
|
@@ -53,7 +53,7 @@ namespace TomatenMusic.Services
|
||||
return track;
|
||||
}
|
||||
|
||||
public async Task<List<LavalinkTrack>> PopulateMultiTrackListAsync(IEnumerable<LavalinkTrack> tracks)
|
||||
public async Task<List<LavalinkTrack>> PopulateTrackListAsync(IEnumerable<LavalinkTrack> tracks)
|
||||
{
|
||||
List<LavalinkTrack> newTracks = new List<LavalinkTrack>();
|
||||
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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user