add
This commit is contained in:
71
TomatenMusicCore/Music/Entitites/FullTrackContext.cs
Normal file
71
TomatenMusicCore/Music/Entitites/FullTrackContext.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using TomatenMusic.Services;
|
||||
using System.Linq;
|
||||
using SpotifyAPI.Web;
|
||||
using Lavalink4NET.Player;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Lavalink4NET;
|
||||
using TomatenMusicCore.Music;
|
||||
|
||||
namespace TomatenMusic.Music.Entitites
|
||||
{
|
||||
public class FullTrackContext
|
||||
{
|
||||
public bool IsFile { get; set; }
|
||||
public string YoutubeDescription { get; set; }
|
||||
public IEnumerable<string> YoutubeTags { get; set; }
|
||||
public ulong YoutubeViews { get; set; }
|
||||
public ulong YoutubeLikes { get; set; }
|
||||
public Uri YoutubeThumbnail { get; set; }
|
||||
public DateTime YoutubeUploadDate { get; set; }
|
||||
//
|
||||
// Summary:
|
||||
// Gets the author of the track.
|
||||
public Uri YoutubeAuthorThumbnail { get; set; }
|
||||
public ulong YoutubeAuthorSubs { get; set; }
|
||||
public Uri YoutubeAuthorUri { get; set; }
|
||||
public ulong? YoutubeCommentCount { get; set; }
|
||||
public string SpotifyIdentifier { get; set; }
|
||||
public SimpleAlbum SpotifyAlbum { get; set; }
|
||||
public List<SimpleArtist> SpotifyArtists { get; set; }
|
||||
public int SpotifyPopularity { get; set; }
|
||||
public Uri SpotifyUri { get; set; }
|
||||
|
||||
public static async Task<TomatenMusicTrack> PopulateAsync(TomatenMusicTrack track, FullTrack spotifyTrack = null, string spotifyId = null)
|
||||
{
|
||||
FullTrackContext context = (FullTrackContext)track.Context;
|
||||
|
||||
if (context == null)
|
||||
context = new FullTrackContext();
|
||||
|
||||
var spotifyService = TomatenMusicBot.ServiceProvider.GetRequiredService<ISpotifyService>();
|
||||
var youtubeService = TomatenMusicBot.ServiceProvider.GetRequiredService<YoutubeService>();
|
||||
if (spotifyId != null)
|
||||
context.SpotifyIdentifier = spotifyId;
|
||||
else if (spotifyTrack != null)
|
||||
context.SpotifyIdentifier = spotifyTrack.Id;
|
||||
|
||||
track.Context = context;
|
||||
await youtubeService.PopulateTrackInfoAsync(track);
|
||||
await spotifyService.PopulateTrackAsync(track, spotifyTrack);
|
||||
|
||||
return track;
|
||||
}
|
||||
|
||||
public static async Task<TrackList> PopulateTracksAsync(TrackList tracks)
|
||||
{
|
||||
foreach (var trackItem in tracks)
|
||||
{
|
||||
await PopulateAsync(trackItem);
|
||||
}
|
||||
|
||||
return tracks;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
35
TomatenMusicCore/Music/Entitites/ILavalinkPlaylist.cs
Normal file
35
TomatenMusicCore/Music/Entitites/ILavalinkPlaylist.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using TomatenMusic.Util;
|
||||
using DSharpPlus.Entities;
|
||||
using Lavalink4NET.Player;
|
||||
using TomatenMusicCore.Music;
|
||||
|
||||
namespace TomatenMusic.Music.Entitites
|
||||
{
|
||||
public interface ILavalinkPlaylist : IPlayableItem
|
||||
{
|
||||
public string Title { get; }
|
||||
public TrackList Tracks { get; }
|
||||
public Uri Url { get; }
|
||||
public string AuthorName { get; set; }
|
||||
public Uri AuthorUri { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string Identifier { get; }
|
||||
public Uri AuthorThumbnail { get; set; }
|
||||
|
||||
public TimeSpan GetLength()
|
||||
{
|
||||
TimeSpan timeSpan = TimeSpan.FromTicks(0);
|
||||
|
||||
foreach (var track in Tracks)
|
||||
{
|
||||
timeSpan = timeSpan.Add(track.Duration);
|
||||
}
|
||||
|
||||
return timeSpan;
|
||||
}
|
||||
}
|
||||
}
|
60
TomatenMusicCore/Music/Entitites/SpotifyPlaylist.cs
Normal file
60
TomatenMusicCore/Music/Entitites/SpotifyPlaylist.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
using Lavalink4NET.Player;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using TomatenMusicCore.Music;
|
||||
|
||||
namespace TomatenMusic.Music.Entitites
|
||||
{
|
||||
public class SpotifyPlaylist : ILavalinkPlaylist
|
||||
{
|
||||
public string Title { get; }
|
||||
public TrackList Tracks { get; }
|
||||
public Uri Url { get; set; }
|
||||
public string AuthorName { get; set; }
|
||||
public Uri AuthorUri { get; set; }
|
||||
public string Description { get; set; }
|
||||
public int Followers { get; set; }
|
||||
public string Identifier { get; }
|
||||
public Uri AuthorThumbnail { get; set; }
|
||||
|
||||
public SpotifyPlaylist(string name, string id, TrackList tracks, Uri uri)
|
||||
{
|
||||
Title = name;
|
||||
Identifier = id;
|
||||
Tracks = tracks;
|
||||
Url = uri;
|
||||
}
|
||||
|
||||
public async Task Play(GuildPlayer player, TimeSpan? startTime = null, TimeSpan? endTime = null, bool noReplace = true)
|
||||
{
|
||||
await player.PlayerQueue.QueuePlaylistAsync(this);
|
||||
|
||||
|
||||
if (player.State == PlayerState.NotPlaying)
|
||||
{
|
||||
LavalinkTrack nextTrack = player.PlayerQueue.NextTrack().Track;
|
||||
await player.PlayAsync(nextTrack);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task PlayNow(GuildPlayer player, TimeSpan? startTime = null, TimeSpan? endTime = null, bool withoutQueuePrepend = false)
|
||||
{
|
||||
if (!player.PlayerQueue.Queue.Any())
|
||||
player.PlayerQueue.CurrentPlaylist = this;
|
||||
|
||||
Queue<TomatenMusicTrack> reversedTracks = new Queue<TomatenMusicTrack>(Tracks);
|
||||
|
||||
TomatenMusicTrack track = reversedTracks.Dequeue();
|
||||
player.PlayerQueue.LastTrack = track;
|
||||
await player.PlayAsync(track);
|
||||
|
||||
reversedTracks.Reverse();
|
||||
|
||||
foreach (var item in reversedTracks)
|
||||
{
|
||||
player.PlayerQueue.Queue = new Queue<TomatenMusicTrack>(player.PlayerQueue.Queue.Prepend(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
73
TomatenMusicCore/Music/Entitites/YoutubePlaylist.cs
Normal file
73
TomatenMusicCore/Music/Entitites/YoutubePlaylist.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using Google.Apis.YouTube.v3.Data;
|
||||
using Lavalink4NET.Player;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using TomatenMusic.Services;
|
||||
using TomatenMusicCore.Music;
|
||||
|
||||
namespace TomatenMusic.Music.Entitites
|
||||
{
|
||||
public class YoutubePlaylist : ILavalinkPlaylist
|
||||
{
|
||||
public string Title { get; }
|
||||
|
||||
public TrackList Tracks { get; }
|
||||
|
||||
public int TrackCount { get; }
|
||||
|
||||
public Uri Url { get; }
|
||||
|
||||
public string AuthorName { get; set; }
|
||||
public Uri AuthorUri { get; set; }
|
||||
public string Description { get; set; }
|
||||
public Uri Thumbnail { get; set; }
|
||||
public DateTime CreationTime { get; set; }
|
||||
public string Identifier { get; }
|
||||
public Playlist YoutubeItem { get; set; }
|
||||
public Uri AuthorThumbnail { get; set; }
|
||||
|
||||
public YoutubePlaylist(string name, TrackList tracks, string id)
|
||||
{
|
||||
Identifier = id;
|
||||
Title = name;
|
||||
Tracks = tracks;
|
||||
Url = new Uri($"https://youtube.com/playlist?list={id}");
|
||||
TrackCount = tracks.Count();
|
||||
|
||||
}
|
||||
|
||||
public async Task Play(GuildPlayer player, TimeSpan? startTime = null, TimeSpan? endTime = null, bool noReplace = true)
|
||||
{
|
||||
await player.PlayerQueue.QueuePlaylistAsync(this);
|
||||
|
||||
|
||||
if (player.State == PlayerState.NotPlaying)
|
||||
{
|
||||
LavalinkTrack nextTrack = player.PlayerQueue.NextTrack().Track;
|
||||
await player.PlayAsync(nextTrack);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task PlayNow(GuildPlayer player, TimeSpan? startTime = null, TimeSpan? endTime = null, bool withoutQueuePrepend = false)
|
||||
{
|
||||
if (!player.PlayerQueue.Queue.Any())
|
||||
player.PlayerQueue.CurrentPlaylist = this;
|
||||
|
||||
Queue<TomatenMusicTrack> reversedTracks = new Queue<TomatenMusicTrack>(Tracks);
|
||||
|
||||
TomatenMusicTrack track = reversedTracks.Dequeue();
|
||||
player.PlayerQueue.LastTrack = track;
|
||||
await player.PlayAsync(track);
|
||||
|
||||
reversedTracks.Reverse();
|
||||
|
||||
foreach (var item in reversedTracks)
|
||||
{
|
||||
player.PlayerQueue.Queue = new Queue<TomatenMusicTrack>(player.PlayerQueue.Queue.Prepend(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user