!m sq
added (soundcloudqueue), allows search queries for soundcloud.
This commit is contained in:
parent
a771e519b4
commit
7bd8163fea
@ -12,7 +12,8 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
{
|
{
|
||||||
Radio,
|
Radio,
|
||||||
Normal,
|
Normal,
|
||||||
Local
|
Local,
|
||||||
|
Soundcloud
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum StreamState
|
public enum StreamState
|
||||||
|
@ -245,16 +245,30 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
}
|
}
|
||||||
if (SoundCloud.Default.IsSoundCloudLink(query))
|
if (SoundCloud.Default.IsSoundCloudLink(query))
|
||||||
{
|
{
|
||||||
var svideo = await SoundCloud.Default.GetVideoAsync(query).ConfigureAwait(false);
|
var svideo = await SoundCloud.Default.ResolveVideoAsync(query).ConfigureAwait(false);
|
||||||
return new Song(new SongInfo
|
return new Song(new SongInfo
|
||||||
{
|
{
|
||||||
Title = svideo.FullName,
|
Title = svideo.FullName,
|
||||||
Provider = "SoundCloud",
|
Provider = "SoundCloud",
|
||||||
Uri = svideo.StreamLink,
|
Uri = svideo.StreamLink,
|
||||||
ProviderType = musicType,
|
ProviderType = musicType,
|
||||||
Query = query,
|
Query = svideo.TrackLink,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (musicType == MusicType.Soundcloud)
|
||||||
|
{
|
||||||
|
var svideo = await SoundCloud.Default.GetVideoByQueryAsync(query).ConfigureAwait(false);
|
||||||
|
return new Song(new SongInfo
|
||||||
|
{
|
||||||
|
Title = svideo.FullName,
|
||||||
|
Provider = "SoundCloud",
|
||||||
|
Uri = svideo.StreamLink,
|
||||||
|
ProviderType = MusicType.Normal,
|
||||||
|
Query = svideo.TrackLink,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
var link = await SearchHelper.FindYoutubeUrlByKeywords(query).ConfigureAwait(false);
|
var link = await SearchHelper.FindYoutubeUrlByKeywords(query).ConfigureAwait(false);
|
||||||
if (string.IsNullOrWhiteSpace(link))
|
if (string.IsNullOrWhiteSpace(link))
|
||||||
throw new OperationCanceledException("Not a valid youtube query.");
|
throw new OperationCanceledException("Not a valid youtube query.");
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
using NadekoBot.Classes;
|
using NadekoBot.Classes;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Music.Classes
|
namespace NadekoBot.Modules.Music.Classes
|
||||||
@ -13,7 +14,7 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
static SoundCloud() { }
|
static SoundCloud() { }
|
||||||
public SoundCloud() { }
|
public SoundCloud() { }
|
||||||
|
|
||||||
public async Task<SoundCloudVideo> GetVideoAsync(string url)
|
public async Task<SoundCloudVideo> ResolveVideoAsync(string url)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(url))
|
if (string.IsNullOrWhiteSpace(url))
|
||||||
throw new ArgumentNullException(nameof(url));
|
throw new ArgumentNullException(nameof(url));
|
||||||
@ -31,6 +32,22 @@ namespace NadekoBot.Modules.Music.Classes
|
|||||||
|
|
||||||
public bool IsSoundCloudLink(string url) =>
|
public bool IsSoundCloudLink(string url) =>
|
||||||
System.Text.RegularExpressions.Regex.IsMatch(url, "(.*)(soundcloud.com|snd.sc)(.*)");
|
System.Text.RegularExpressions.Regex.IsMatch(url, "(.*)(soundcloud.com|snd.sc)(.*)");
|
||||||
|
|
||||||
|
internal async Task<SoundCloudVideo> GetVideoByQueryAsync(string query)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(query))
|
||||||
|
throw new ArgumentNullException(nameof(query));
|
||||||
|
if (string.IsNullOrWhiteSpace(NadekoBot.Creds.SoundCloudClientID))
|
||||||
|
throw new ArgumentNullException(nameof(NadekoBot.Creds.SoundCloudClientID));
|
||||||
|
|
||||||
|
var response = await SearchHelper.GetResponseStringAsync($"http://api.soundcloud.com/tracks?q={Uri.EscapeDataString(query)}&client_id={NadekoBot.Creds.SoundCloudClientID}").ConfigureAwait(false);
|
||||||
|
|
||||||
|
var responseObj = JsonConvert.DeserializeObject<SoundCloudVideo[]>(response).Where(s => s.Streamable).FirstOrDefault();
|
||||||
|
if (responseObj?.Kind != "track")
|
||||||
|
throw new InvalidOperationException("Query yielded no results.");
|
||||||
|
|
||||||
|
return responseObj;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SoundCloudVideo
|
public class SoundCloudVideo
|
||||||
|
@ -108,20 +108,20 @@ namespace NadekoBot.Modules.Music
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//cgb.CreateCommand("soundcloudqueue")
|
cgb.CreateCommand("soundcloudqueue")
|
||||||
// .Alias("sq")
|
.Alias("sq")
|
||||||
// .Description("Queue a soundcloud song using keywords. Bot will join your voice channel." +
|
.Description("Queue a soundcloud song using keywords. Bot will join your voice channel." +
|
||||||
// "**You must be in a voice channel**.\n**Usage**: `!m sq Dream Of Venice`")
|
"**You must be in a voice channel**.\n**Usage**: `!m sq Dream Of Venice`")
|
||||||
// .Parameter("query", ParameterType.Unparsed)
|
.Parameter("query", ParameterType.Unparsed)
|
||||||
// .Do(async e =>
|
.Do(async e =>
|
||||||
// {
|
{
|
||||||
// await QueueSong(e.Channel, e.User.VoiceChannel, e.GetArg("query")).ConfigureAwait(false);
|
await QueueSong(e.User, e.Channel, e.User.VoiceChannel, e.GetArg("query"), musicType: MusicType.Soundcloud).ConfigureAwait(false);
|
||||||
// if (e.Server.CurrentUser.GetPermissions(e.Channel).ManageMessages)
|
if (e.Server.CurrentUser.GetPermissions(e.Channel).ManageMessages)
|
||||||
// {
|
{
|
||||||
// await Task.Delay(10000).ConfigureAwait(false);
|
await Task.Delay(10000).ConfigureAwait(false);
|
||||||
// await e.Message.Delete().ConfigureAwait(false);
|
await e.Message.Delete().ConfigureAwait(false);
|
||||||
// }
|
}
|
||||||
// });
|
});
|
||||||
|
|
||||||
cgb.CreateCommand("listqueue")
|
cgb.CreateCommand("listqueue")
|
||||||
.Alias("lq")
|
.Alias("lq")
|
||||||
@ -297,7 +297,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
var ids = await SearchHelper.GetVideoIDs(plId, 500).ConfigureAwait(false);
|
var ids = await SearchHelper.GetVideoIDs(plId, 500).ConfigureAwait(false);
|
||||||
if (ids == null || ids.Count == 0)
|
if (ids == null || ids.Count == 0)
|
||||||
{
|
{
|
||||||
await e.Channel.SendMessage($"🎵 `Failed to find any songs.`");
|
await e.Channel.SendMessage($"🎵 `Failed to find any songs.`").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//todo TEMPORARY SOLUTION, USE RESOLVE QUEUE IN THE FUTURE
|
//todo TEMPORARY SOLUTION, USE RESOLVE QUEUE IN THE FUTURE
|
||||||
@ -329,8 +329,8 @@ namespace NadekoBot.Modules.Music
|
|||||||
if (string.IsNullOrWhiteSpace(pl))
|
if (string.IsNullOrWhiteSpace(pl))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var scvids = JObject.Parse(await SearchHelper.GetResponseStringAsync($"http://api.soundcloud.com/resolve?url={pl}&client_id={NadekoBot.Creds.SoundCloudClientID}"))["tracks"].ToObject<SoundCloudVideo[]>();
|
var scvids = JObject.Parse(await SearchHelper.GetResponseStringAsync($"http://api.soundcloud.com/resolve?url={pl}&client_id={NadekoBot.Creds.SoundCloudClientID}").ConfigureAwait(false))["tracks"].ToObject<SoundCloudVideo[]>();
|
||||||
await QueueSong(e.User, e.Channel, e.User.VoiceChannel, scvids[0].TrackLink);
|
await QueueSong(e.User, e.Channel, e.User.VoiceChannel, scvids[0].TrackLink).ConfigureAwait(false);
|
||||||
|
|
||||||
MusicPlayer mp;
|
MusicPlayer mp;
|
||||||
if (!MusicPlayers.TryGetValue(e.Server, out mp))
|
if (!MusicPlayers.TryGetValue(e.Server, out mp))
|
||||||
@ -483,7 +483,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
!int.TryParse(fromtoArr[1], out n2) || n1 < 1 || n2 < 1 || n1 == n2 ||
|
!int.TryParse(fromtoArr[1], out n2) || n1 < 1 || n2 < 1 || n1 == n2 ||
|
||||||
n1 > playlist.Count || n2 > playlist.Count)
|
n1 > playlist.Count || n2 > playlist.Count)
|
||||||
{
|
{
|
||||||
await e.Channel.SendMessage("`Invalid input.`");
|
await e.Channel.SendMessage("`Invalid input.`").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -492,7 +492,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
var nn1 = n2 < n1 ? n1 : n1 - 1;
|
var nn1 = n2 < n1 ? n1 : n1 - 1;
|
||||||
playlist.RemoveAt(nn1);
|
playlist.RemoveAt(nn1);
|
||||||
|
|
||||||
await e.Channel.SendMessage($"🎵`Moved` {s.PrettyName} `from #{n1} to #{n2}`");
|
await e.Channel.SendMessage($"🎵`Moved` {s.PrettyName} `from #{n1} to #{n2}`").ConfigureAwait(false);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -691,9 +691,9 @@ namespace NadekoBot.Modules.Music
|
|||||||
return;
|
return;
|
||||||
var result = DbHandler.Instance.GetPlaylistData(num);
|
var result = DbHandler.Instance.GetPlaylistData(num);
|
||||||
if (result.Count == 0)
|
if (result.Count == 0)
|
||||||
e.Channel.SendMessage($"`No saved playlists found on page {num}`");
|
e.Channel.SendMessage($"`No saved playlists found on page {num}`").ConfigureAwait(false);
|
||||||
else
|
else
|
||||||
e.Channel.SendMessage($"```js\n--- List of saved playlists ---\n\n" + string.Join("\n", result.Select(r => $"'{r.Name}-{r.Id}' by {r.Creator} ({r.SongCnt} songs)")) + $"\n\n --- Page {num} ---```");
|
e.Channel.SendMessage($"```js\n--- List of saved playlists ---\n\n" + string.Join("\n", result.Select(r => $"'{r.Name}-{r.Id}' by {r.Creator} ({r.SongCnt} songs)")) + $"\n\n --- Page {num} ---```").ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
cgb.CreateCommand("deleteplaylist")
|
cgb.CreateCommand("deleteplaylist")
|
||||||
@ -710,7 +710,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
DbHandler.Instance.Delete<MusicPlaylist>(plnum);
|
DbHandler.Instance.Delete<MusicPlaylist>(plnum);
|
||||||
else
|
else
|
||||||
DbHandler.Instance.DeleteWhere<MusicPlaylist>(mp => mp.Id == plnum && (long)e.User.Id == mp.CreatorId);
|
DbHandler.Instance.DeleteWhere<MusicPlaylist>(mp => mp.Id == plnum && (long)e.User.Id == mp.CreatorId);
|
||||||
await e.Channel.SendMessage("`Ok.` :ok:");
|
await e.Channel.SendMessage("`Ok.` :ok:").ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
cgb.CreateCommand("goto")
|
cgb.CreateCommand("goto")
|
||||||
@ -761,7 +761,7 @@ namespace NadekoBot.Modules.Music
|
|||||||
var curSong = musicPlayer.CurrentSong;
|
var curSong = musicPlayer.CurrentSong;
|
||||||
if (curSong == null)
|
if (curSong == null)
|
||||||
return;
|
return;
|
||||||
await e.Channel.SendMessage($"🎶`Current song:` <{curSong.SongInfo.Query}>");
|
await e.Channel.SendMessage($"🎶`Current song:` <{curSong.SongInfo.Query}>").ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
cgb.CreateCommand("autoplay")
|
cgb.CreateCommand("autoplay")
|
||||||
@ -775,9 +775,9 @@ namespace NadekoBot.Modules.Music
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (!musicPlayer.ToggleAutoplay())
|
if (!musicPlayer.ToggleAutoplay())
|
||||||
await e.Channel.SendMessage("🎶`Autoplay disabled.`");
|
await e.Channel.SendMessage("🎶`Autoplay disabled.`").ConfigureAwait(false);
|
||||||
else
|
else
|
||||||
await e.Channel.SendMessage("🎶`Autoplay enabled.`");
|
await e.Channel.SendMessage("🎶`Autoplay enabled.`").ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
.Description("Shows some basic stats for Nadeko.")
|
.Description("Shows some basic stats for Nadeko.")
|
||||||
.Do(async e =>
|
.Do(async e =>
|
||||||
{
|
{
|
||||||
await e.Channel.SendMessage(await NadekoStats.Instance.GetStats());
|
await e.Channel.SendMessage(await NadekoStats.Instance.GetStats()).ConfigureAwait(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
cgb.CreateCommand(Prefix + "dysyd")
|
cgb.CreateCommand(Prefix + "dysyd")
|
||||||
|
Loading…
Reference in New Issue
Block a user