Soundcloud playlist support (!m scpl) - Better late than never. closes #123
This commit is contained in:
parent
ed59d11d71
commit
85ff050061
@ -174,6 +174,7 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
throw new ArgumentNullException(nameof(s));
|
throw new ArgumentNullException(nameof(s));
|
||||||
lock (playlistLock)
|
lock (playlistLock)
|
||||||
{
|
{
|
||||||
|
s.MusicPlayer = this;
|
||||||
playlist.Add(s);
|
playlist.Add(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Song(SongInfo songInfo)
|
public Song(SongInfo songInfo)
|
||||||
{
|
{
|
||||||
this.SongInfo = songInfo;
|
this.SongInfo = songInfo;
|
||||||
}
|
}
|
||||||
@ -67,6 +67,12 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Song SetMusicPlayer(MusicPlayer mp)
|
||||||
|
{
|
||||||
|
this.MusicPlayer = mp;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
private Task BufferSong(CancellationToken cancelToken) =>
|
private Task BufferSong(CancellationToken cancelToken) =>
|
||||||
Task.Factory.StartNew(async () =>
|
Task.Factory.StartNew(async () =>
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -34,18 +35,22 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
|
|
||||||
public class SoundCloudVideo
|
public class SoundCloudVideo
|
||||||
{
|
{
|
||||||
public string Kind = "";
|
public string Kind { get; set; } = "";
|
||||||
public long Id = 0;
|
public long Id { get; set; } = 0;
|
||||||
public SoundCloudUser User = new SoundCloudUser();
|
public SoundCloudUser User { get; set; } = new SoundCloudUser();
|
||||||
public string Title = "";
|
public string Title { get; set; } = "";
|
||||||
|
[JsonIgnore]
|
||||||
public string FullName => User.Name + " - " + Title;
|
public string FullName => User.Name + " - " + Title;
|
||||||
public bool Streamable = false;
|
public bool Streamable { get; set; } = false;
|
||||||
|
[JsonProperty("permalink_url")]
|
||||||
|
public string TrackLink { get; set; } = "";
|
||||||
|
[JsonIgnore]
|
||||||
public string StreamLink => $"https://api.soundcloud.com/tracks/{Id}/stream?client_id={NadekoBot.Creds.SoundCloudClientID}";
|
public string StreamLink => $"https://api.soundcloud.com/tracks/{Id}/stream?client_id={NadekoBot.Creds.SoundCloudClientID}";
|
||||||
}
|
}
|
||||||
public class SoundCloudUser
|
public class SoundCloudUser
|
||||||
{
|
{
|
||||||
[Newtonsoft.Json.JsonProperty("username")]
|
[Newtonsoft.Json.JsonProperty("username")]
|
||||||
public string Name;
|
public string Name { get; set; }
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
{"kind":"track",
|
{"kind":"track",
|
||||||
|
@ -6,6 +6,7 @@ using NadekoBot.DataModels;
|
|||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using NadekoBot.Modules.Music.Classes;
|
using NadekoBot.Modules.Music.Classes;
|
||||||
using NadekoBot.Modules.Permissions.Classes;
|
using NadekoBot.Modules.Permissions.Classes;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -302,6 +303,37 @@ namespace NadekoBot.Modules.Music
|
|||||||
await msg.Edit("🎵 `Playlist queue complete.`").ConfigureAwait(false);
|
await msg.Edit("🎵 `Playlist queue complete.`").ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
cgb.CreateCommand("soundcloudpl")
|
||||||
|
.Alias("scpl")
|
||||||
|
.Description("Queue a soundcloud playlist using a link. | `!m scpl https://soundcloud.com/saratology/sets/symphony`")
|
||||||
|
.Parameter("pl", ParameterType.Unparsed)
|
||||||
|
.Do(async e =>
|
||||||
|
{
|
||||||
|
var pl = e.GetArg("pl")?.Trim();
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(pl))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var scvids = JObject.Parse(await SearchHelper.GetResponseStringAsync($"http://api.soundcloud.com/resolve?url={pl}&client_id={NadekoBot.Creds.SoundCloudClientID}"))["tracks"].ToObject<SoundCloudVideo[]>();
|
||||||
|
await QueueSong(e.Channel, e.User.VoiceChannel, scvids[0].TrackLink);
|
||||||
|
|
||||||
|
MusicPlayer mp;
|
||||||
|
if (!MusicPlayers.TryGetValue(e.Server, out mp))
|
||||||
|
return;
|
||||||
|
|
||||||
|
foreach (var svideo in scvids.Skip(1))
|
||||||
|
{
|
||||||
|
mp.AddSong(new Song(new Classes.SongInfo
|
||||||
|
{
|
||||||
|
Title = svideo.FullName,
|
||||||
|
Provider = "SoundCloud",
|
||||||
|
Uri = svideo.StreamLink,
|
||||||
|
ProviderType = MusicType.Normal,
|
||||||
|
Query = svideo.TrackLink,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
cgb.CreateCommand("localplaylst")
|
cgb.CreateCommand("localplaylst")
|
||||||
.Alias("lopl")
|
.Alias("lopl")
|
||||||
.Description("Queues all songs from a directory. **Bot Owner Only!**\n**Usage**: `!m lopl C:/music/classical`")
|
.Description("Queues all songs from a directory. **Bot Owner Only!**\n**Usage**: `!m lopl C:/music/classical`")
|
||||||
@ -757,8 +789,6 @@ namespace NadekoBot.Modules.Music
|
|||||||
return mp;
|
return mp;
|
||||||
});
|
});
|
||||||
var resolvedSong = await Song.ResolveSong(query, musicType).ConfigureAwait(false);
|
var resolvedSong = await Song.ResolveSong(query, musicType).ConfigureAwait(false);
|
||||||
resolvedSong.MusicPlayer = musicPlayer;
|
|
||||||
|
|
||||||
musicPlayer.AddSong(resolvedSong);
|
musicPlayer.AddSong(resolvedSong);
|
||||||
if (!silent)
|
if (!silent)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user