add /api/player/play endpoint
fix not being able to play track with a playlist reference ``&list=`` attached
This commit is contained in:
@@ -79,7 +79,7 @@ namespace TomatenMusic.Commands
|
||||
|
||||
try
|
||||
{
|
||||
if (response.isPlaylist)
|
||||
if (response.IsPlaylist)
|
||||
{
|
||||
ILavalinkPlaylist playlist = response.Playlist;
|
||||
await player.PlayPlaylistNowAsync(playlist);
|
||||
@@ -232,7 +232,7 @@ namespace TomatenMusic.Commands
|
||||
|
||||
try
|
||||
{
|
||||
if (response.isPlaylist)
|
||||
if (response.IsPlaylist)
|
||||
{
|
||||
ILavalinkPlaylist playlist = response.Playlist;
|
||||
await player.PlayPlaylistAsync(playlist);
|
||||
|
@@ -28,12 +28,12 @@ namespace TomatenMusic.Music.Entitites
|
||||
public Playlist YoutubeItem { get; set; }
|
||||
public Uri AuthorThumbnail { get; set; }
|
||||
|
||||
public YoutubePlaylist(string name, IEnumerable<LavalinkTrack> tracks, Uri uri)
|
||||
public YoutubePlaylist(string name, IEnumerable<LavalinkTrack> tracks, string id)
|
||||
{
|
||||
Identifier = uri.ToString().Replace("https://www.youtube.com/playlist?list=", "").Replace("https://youtube.com/playlist?list=", "");
|
||||
Identifier = id;
|
||||
Name = name;
|
||||
Tracks = tracks;
|
||||
Url = uri;
|
||||
Url = new Uri($"https://youtube.com/playlist?list={id}");
|
||||
TrackCount = tracks.Count();
|
||||
|
||||
}
|
||||
|
@@ -73,7 +73,7 @@ namespace TomatenMusic.Music
|
||||
QueuePrompt.UpdateFor(GuildId);
|
||||
}
|
||||
|
||||
public async Task PlayTracksAsync(List<LavalinkTrack> tracks)
|
||||
public async Task PlayTracksAsync(IEnumerable<LavalinkTrack> tracks)
|
||||
{
|
||||
EnsureNotDestroyed();
|
||||
EnsureConnected();
|
||||
|
@@ -11,12 +11,12 @@ namespace TomatenMusic.Music
|
||||
public ILavalinkPlaylist Playlist { get; }
|
||||
public LavalinkTrack Track { get; }
|
||||
public IEnumerable<LavalinkTrack> Tracks { get; }
|
||||
public bool isPlaylist { get; }
|
||||
public bool IsPlaylist { get; }
|
||||
public MusicActionResponse(LavalinkTrack track = null, ILavalinkPlaylist playlist = null, IEnumerable<LavalinkTrack> tracks = null)
|
||||
{
|
||||
Playlist = playlist;
|
||||
Track = track;
|
||||
isPlaylist = playlist != null;
|
||||
IsPlaylist = playlist != null;
|
||||
Tracks = tracks;
|
||||
}
|
||||
}
|
||||
|
@@ -59,7 +59,7 @@ namespace TomatenMusic.Music
|
||||
|
||||
}
|
||||
|
||||
public Task QueueTracksAsync(List<LavalinkTrack> tracks)
|
||||
public Task QueueTracksAsync(IEnumerable<LavalinkTrack> tracks)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
|
@@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using TomatenMusic.Music.Entitites;
|
||||
using TomatenMusic.Services;
|
||||
|
||||
@@ -57,7 +58,8 @@ namespace TomatenMusic.Music
|
||||
|
||||
if (loadResult.LoadType == TrackLoadType.PlaylistLoaded && !isSearch)
|
||||
return new MusicActionResponse(
|
||||
playlist: await _youtubeService.PopulatePlaylistAsync(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), ParseListId(query))));
|
||||
else
|
||||
return new MusicActionResponse(await FullTrackContext.PopulateAsync(loadResult.Tracks.First()));
|
||||
|
||||
@@ -79,5 +81,27 @@ namespace TomatenMusic.Music
|
||||
|
||||
}
|
||||
|
||||
public string ParseListId(string url)
|
||||
{
|
||||
var uri = new Uri(url, UriKind.Absolute);
|
||||
|
||||
// you can check host here => uri.Host <= "www.youtube.com"
|
||||
|
||||
var query = HttpUtility.ParseQueryString(uri.Query);
|
||||
|
||||
var videoId = string.Empty;
|
||||
|
||||
if (query.AllKeys.Contains("list"))
|
||||
{
|
||||
videoId = query["list"];
|
||||
}
|
||||
else
|
||||
{
|
||||
videoId = uri.Segments.Last();
|
||||
}
|
||||
|
||||
return videoId;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
@@ -11,17 +11,17 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DSharpPlus" Version="4.2.0-nightly-01088" />
|
||||
<PackageReference Include="DSharpPlus.Interactivity" Version="4.2.0-nightly-01084" />
|
||||
<PackageReference Include="DSharpPlus.SlashCommands" Version="4.2.0-nightly-01088" />
|
||||
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.56.0.2617" />
|
||||
<PackageReference Include="DSharpPlus" Version="4.2.0-nightly-01101" />
|
||||
<PackageReference Include="DSharpPlus.Interactivity" Version="4.2.0-nightly-01101" />
|
||||
<PackageReference Include="DSharpPlus.SlashCommands" Version="4.2.0-nightly-01101" />
|
||||
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.56.0.2630" />
|
||||
<PackageReference Include="HtmlAgilityPack" Version="1.11.42" />
|
||||
<PackageReference Include="Lavalink4NET" Version="2.1.1" />
|
||||
<PackageReference Include="Lavalink4NET.DSharpPlus" Version="2.1.1" />
|
||||
<PackageReference Include="Lavalink4NET.Logging.Microsoft" Version="2.1.1-preview.5" />
|
||||
<PackageReference Include="Lavalink4NET.Logging.Microsoft" Version="2.1.1-preview.6" />
|
||||
<PackageReference Include="Lavalink4NET.MemoryCache" Version="2.1.1" />
|
||||
<PackageReference Include="Microsoft.AspNet.WebApi.OwinSelfHost" Version="5.2.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0-preview.2.22152.2" />
|
||||
<PackageReference Include="SpotifyAPI.Web" Version="6.2.2" />
|
||||
<PackageReference Include="SpotifyAPI.Web.Auth" Version="6.2.2" />
|
||||
</ItemGroup>
|
||||
|
Reference in New Issue
Block a user