Merge pull request #919 from samdivaio/dev

Music fixes
This commit is contained in:
Master Kwoth 2016-12-27 01:24:16 +01:00 committed by GitHub
commit d08abbafd0
4 changed files with 80 additions and 108 deletions

View File

@ -11,6 +11,7 @@ using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using VideoLibrary; using VideoLibrary;
using System.Net;
namespace NadekoBot.Modules.Music.Classes namespace NadekoBot.Modules.Music.Classes
{ {
@ -46,7 +47,25 @@ namespace NadekoBot.Modules.Music.Classes
public string PrettyFullTime => PrettyCurrentTime + " / " + PrettyTotalTime; public string PrettyFullTime => PrettyCurrentTime + " / " + PrettyTotalTime;
public string PrettyName => $"**[{SongInfo.Title.TrimTo(70)}]({SongInfo.Query})**"; //public string PrettyName => $"**[{SongInfo.Title.TrimTo(70)}]({SongInfo.Query})**";
public string PrettyName {
get {
switch (SongInfo.ProviderType)
{
case MusicType.Normal:
return $"**[{SongInfo.Title.TrimTo(70)}]({SongInfo.Query})**";
case MusicType.Soundcloud:
return $"**[{SongInfo.Title.TrimTo(70)}]({SongInfo.Query})**";
case MusicType.Local:
return $"**{SongInfo.Title.TrimTo(70)}**";
case MusicType.Radio:
return $"**{SongInfo.Title.TrimTo(70)}**";
default:
return "";
}
}
}
public string PrettyInfo => $"{PrettyTotalTime} | {PrettyProvider} | {QueuerName}"; public string PrettyInfo => $"{PrettyTotalTime} | {PrettyProvider} | {QueuerName}";
@ -67,16 +86,36 @@ namespace NadekoBot.Modules.Music.Classes
public string Thumbnail { public string Thumbnail {
get { get {
switch (SongInfo.ProviderType) switch (SongInfo.Provider)
{ {
case MusicType.Normal: case "YouTube":
//todo have videoid in songinfo from the start //todo have videoid in songinfo from the start
var videoId = Regex.Match(SongInfo.Query, "<=v=[a-zA-Z0-9-]+(?=&)|(?<=[0-9])[^&\n]+|(?<=v=)[^&\n]+"); var videoId = Regex.Match(SongInfo.Query, "<=v=[a-zA-Z0-9-]+(?=&)|(?<=[0-9])[^&\n]+|(?<=v=)[^&\n]+");
return $"https://img.youtube.com/vi/{ videoId }/0.jpg"; return $"https://img.youtube.com/vi/{ videoId }/0.jpg";
case "SoundCloud":
return SongInfo.AlbumArt;
case "Local File":
return $"https://cdn.discordapp.com/attachments/155726317222887425/261850914783100928/1482522077_music.png"; //test links
case "Radio Stream":
return $"https://cdn.discordapp.com/attachments/155726317222887425/261850925063340032/1482522097_radio.png"; //test links
default:
return "";
}
}
}
public string songURL {
get {
switch (SongInfo.ProviderType)
{
case MusicType.Normal:
return SongInfo.Query;
case MusicType.Soundcloud: case MusicType.Soundcloud:
return SongInfo.AlbumArt; return SongInfo.Query;
case MusicType.Local: case MusicType.Local:
return $"https://google.com/search?q={ WebUtility.UrlEncode(SongInfo.Title).Replace(' ', '+') }";
case MusicType.Radio: case MusicType.Radio:
return $"https://google.com/search?q={SongInfo.Title}";
default: default:
return ""; return "";
} }
@ -104,6 +143,7 @@ namespace NadekoBot.Modules.Music.Classes
{ {
var s = new Song(SongInfo); var s = new Song(SongInfo);
s.MusicPlayer = MusicPlayer; s.MusicPlayer = MusicPlayer;
s.QueuerName = QueuerName;
return s; return s;
} }

View File

@ -235,12 +235,12 @@ namespace NadekoBot.Modules.Music
var embed = new EmbedBuilder() var embed = new EmbedBuilder()
.WithAuthor(eab => eab.WithName("Now Playing") .WithAuthor(eab => eab.WithName("Now Playing")
.WithMusicIcon()) .WithMusicIcon())
.WithTitle($"{currentSong.SongInfo.Title}") .WithTitle(currentSong.SongInfo.Title)
.WithDescription(currentSong.PrettyFullTime) .WithDescription(currentSong.PrettyFullTime)
.WithFooter(ef => ef.WithText($"{currentSong.PrettyProvider} | {currentSong.QueuerName}")) .WithFooter(ef => ef.WithText($"{currentSong.PrettyProvider} | {currentSong.QueuerName}"))
.WithOkColor() .WithOkColor()
.WithThumbnail(tn => tn.Url = currentSong.Thumbnail) .WithThumbnail(tn => tn.Url = currentSong.Thumbnail)
.WithUrl(currentSong.SongInfo.Query); .WithUrl(currentSong.songURL);
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
} }
@ -327,28 +327,28 @@ namespace NadekoBot.Modules.Music
var count = ids.Count(); var count = ids.Count();
var msg = await channel.SendMessageAsync($"🎵 Attempting to queue **{count}** songs".SnPl(count) + "...").ConfigureAwait(false); var msg = await channel.SendMessageAsync($"🎵 Attempting to queue **{count}** songs".SnPl(count) + "...").ConfigureAwait(false);
var cancelSource = new CancellationTokenSource(); var cancelSource = new CancellationTokenSource();
var gusr = (IGuildUser)umsg.Author; var gusr = (IGuildUser)umsg.Author;
while (ids.Any() && !cancelSource.IsCancellationRequested) while (ids.Any() && !cancelSource.IsCancellationRequested)
{ {
var tasks = Task.WhenAll(ids.Take(5).Select(async id => var tasks = Task.WhenAll(ids.Take(5).Select(async id =>
{ {
if (cancelSource.Token.IsCancellationRequested) if (cancelSource.Token.IsCancellationRequested)
return; return;
try try
{ {
await QueueSong(gusr, channel, gusr.VoiceChannel, id, true).ConfigureAwait(false); await QueueSong(gusr, channel, gusr.VoiceChannel, id, true).ConfigureAwait(false);
} }
catch (SongNotFoundException) { } catch (SongNotFoundException) { }
catch { try { cancelSource.Cancel(); } catch { } } catch { try { cancelSource.Cancel(); } catch { } }
})); }));
await Task.WhenAny(tasks, Task.Delay(Timeout.Infinite, cancelSource.Token)); await Task.WhenAny(tasks, Task.Delay(Timeout.Infinite, cancelSource.Token));
ids = ids.Skip(5); ids = ids.Skip(5);
} }
await msg.ModifyAsync(m => m.Content = "✅ Playlist queue complete.").ConfigureAwait(false); await msg.ModifyAsync(m => m.Content = "✅ Playlist queue complete.").ConfigureAwait(false);
} }
@ -404,7 +404,7 @@ namespace NadekoBot.Modules.Music
var dir = new DirectoryInfo(arg); var dir = new DirectoryInfo(arg);
var fileEnum = dir.GetFiles("*", SearchOption.AllDirectories) var fileEnum = dir.GetFiles("*", SearchOption.AllDirectories)
.Where(x => !x.Attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System)); .Where(x => !x.Attributes.HasFlag(FileAttributes.Hidden | FileAttributes.System));
var gusr = (IGuildUser)umsg.Author; var gusr = (IGuildUser)umsg.Author;
foreach (var file in fileEnum) foreach (var file in fileEnum)
{ {
try try
@ -486,8 +486,9 @@ namespace NadekoBot.Modules.Music
var embed = new EmbedBuilder() var embed = new EmbedBuilder()
.WithAuthor(eab => eab.WithName("Song Removed!").WithMusicIcon()) .WithAuthor(eab => eab.WithName("Song Removed!").WithMusicIcon())
.AddField(fb => fb.WithName("**Song Position**").WithValue($"#{num}").WithIsInline(true)) .AddField(fb => fb.WithName("**Song Position**").WithValue($"#{num}").WithIsInline(true))
.AddField(fb => fb.WithName("**Song Name**").WithValue($"**[{song.SongInfo.Title.TrimTo(70)}]({song.SongInfo.Query})** `{song.PrettyProvider} | {song.QueuerName.TrimTo(15)}`").WithIsInline(true)) .AddField(fb => fb.WithName("**Song Name**").WithValue(song.PrettyName).WithIsInline(true))
.WithErrorColor(); .WithFooter(ef => ef.WithText($"{song.PrettyProvider} | {song.QueuerName}"))
.WithErrorColor();
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
} }
@ -540,11 +541,12 @@ namespace NadekoBot.Modules.Music
playlist.RemoveAt(nn1); playlist.RemoveAt(nn1);
var embed = new EmbedBuilder() var embed = new EmbedBuilder()
.WithTitle($"{s.SongInfo.Title.TrimTo(70)}") .WithTitle(s.SongInfo.Title.TrimTo(70))
.WithUrl($"{s.SongInfo.Query}") .WithUrl(s.SongInfo.Query)
.WithAuthor(eab => eab.WithName("Song Moved").WithMusicIcon()) .WithAuthor(eab => eab.WithName("Song Moved").WithMusicIcon())
.AddField(fb => fb.WithName("**From Position**").WithValue($"#{n1}").WithIsInline(true)) .AddField(fb => fb.WithName("**From Position**").WithValue($"#{n1}").WithIsInline(true))
.AddField(fb => fb.WithName("**To Position**").WithValue($"#{n2}").WithIsInline(true)) .AddField(fb => fb.WithName("**To Position**").WithValue($"#{n2}").WithIsInline(true))
.WithFooter(ef => ef.WithText($"{s.PrettyProvider} | {s.QueuerName}"))
.WithOkColor(); .WithOkColor();
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
} }
@ -580,7 +582,8 @@ namespace NadekoBot.Modules.Music
await channel.EmbedAsync(new EmbedBuilder() await channel.EmbedAsync(new EmbedBuilder()
.WithOkColor() .WithOkColor()
.WithAuthor(eab => eab.WithMusicIcon().WithName("🔂 Repeating track")) .WithAuthor(eab => eab.WithMusicIcon().WithName("🔂 Repeating track"))
.WithDescription(currentSong.PrettyFullName) .WithDescription(currentSong.PrettyName)
.WithFooter(ef => ef.WithText(currentSong.PrettyInfo))
.Build()).ConfigureAwait(false); .Build()).ConfigureAwait(false);
else else
await channel.SendConfirmAsync($"🔂 Current track repeat stopped.") await channel.SendConfirmAsync($"🔂 Current track repeat stopped.")
@ -655,9 +658,9 @@ namespace NadekoBot.Modules.Music
} }
IUserMessage msg = null; IUserMessage msg = null;
try { msg = await channel.SendMessageAsync($"🎶 Attempting to load **{mpl.Songs.Count}** songs...").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); } try { msg = await channel.SendMessageAsync($"🎶 Attempting to load **{mpl.Songs.Count}** songs...").ConfigureAwait(false); } catch (Exception ex) { _log.Warn(ex); }
var usr = (IGuildUser)umsg.Author; var usr = (IGuildUser)umsg.Author;
foreach (var item in mpl.Songs) foreach (var item in mpl.Songs)
{ {
try try
{ {
@ -688,7 +691,7 @@ namespace NadekoBot.Modules.Music
var embed = new EmbedBuilder() var embed = new EmbedBuilder()
.WithAuthor(eab => eab.WithName($"Page {num} of Saved Playlists").WithMusicIcon()) .WithAuthor(eab => eab.WithName($"Page {num} of Saved Playlists").WithMusicIcon())
.WithDescription(string.Join("\n", playlists.Select(r => $"`#{r.Id}` - **{r.Name}**\t by **`{r.Author}`**\t ({r.Songs.Count} songs)"))) .WithDescription(string.Join("\n", playlists.Select(r => $"`#{r.Id}` - **{r.Name}** by *{r.Author}* ({r.Songs.Count} songs)")))
.WithOkColor(); .WithOkColor();
await channel.EmbedAsync(embed.Build()).ConfigureAwait(false); await channel.EmbedAsync(embed.Build()).ConfigureAwait(false);
@ -770,41 +773,6 @@ namespace NadekoBot.Modules.Music
await channel.SendConfirmAsync($"Skipped to `{minutes}:{seconds}`").ConfigureAwait(false); await channel.SendConfirmAsync($"Skipped to `{minutes}:{seconds}`").ConfigureAwait(false);
} }
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task GetLink(IUserMessage umsg, int index = 0)
{
var channel = (ITextChannel)umsg.Channel;
MusicPlayer musicPlayer;
if (!MusicPlayers.TryGetValue(channel.Guild.Id, out musicPlayer))
return;
if (index < 0)
return;
if (index > 0)
{
var selSong = musicPlayer.Playlist.DefaultIfEmpty(null).ElementAtOrDefault(index - 1);
if (selSong == null)
{
await channel.SendErrorAsync("Could not select song, likely wrong index");
}
else
{
await channel.SendMessageAsync($"🎶 Selected song **{selSong.SongInfo.Title}**: <{selSong.SongInfo.Query}>").ConfigureAwait(false);
}
}
else
{
var curSong = musicPlayer.CurrentSong;
if (curSong == null)
return;
await channel.SendMessageAsync($"🎶 Current song **{curSong.SongInfo.Title}**: <{curSong.SongInfo.Query}>").ConfigureAwait(false);
}
}
[NadekoCommand, Usage, Description, Aliases] [NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Autoplay(IUserMessage umsg) public async Task Autoplay(IUserMessage umsg)
@ -877,8 +845,8 @@ namespace NadekoBot.Modules.Music
playingMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor() playingMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithAuthor(eab => eab.WithName("Playing Song").WithMusicIcon()) .WithAuthor(eab => eab.WithName("Playing Song").WithMusicIcon())
.WithDescription($"{song.PrettyName}") .WithDescription(song.PrettyName)
.WithFooter(ef => ef.WithText($"🔉 {(int)(sender.Volume * 100)}% | {song.PrettyInfo}")) .WithFooter(ef => ef.WithText($"🔉 {(int)(sender.Volume * 100)}% | {song.PrettyInfo}"))
.Build()) .Build())
.ConfigureAwait(false); .ConfigureAwait(false);
} }
@ -899,7 +867,7 @@ namespace NadekoBot.Modules.Music
pauseMessage = await textCh.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false); pauseMessage = await textCh.SendConfirmAsync("🎵 Music playback **resumed**.").ConfigureAwait(false);
} }
if (pauseMessage != null) if (pauseMessage != null)
pauseMessage.DeleteAfter(5); pauseMessage.DeleteAfter(15);
} }
catch { } catch { }
}; };
@ -928,9 +896,9 @@ namespace NadekoBot.Modules.Music
//var queuedMessage = await textCh.SendConfirmAsync($"🎵 Queued **{resolvedSong.SongInfo.Title}** at `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false); //var queuedMessage = await textCh.SendConfirmAsync($"🎵 Queued **{resolvedSong.SongInfo.Title}** at `#{musicPlayer.Playlist.Count + 1}`").ConfigureAwait(false);
var queuedMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor() var queuedMessage = await textCh.EmbedAsync(new EmbedBuilder().WithOkColor()
.WithAuthor(eab => eab.WithName("Queued Song").WithMusicIcon()) .WithAuthor(eab => eab.WithName("Queued Song").WithMusicIcon())
.WithTitle($"{resolvedSong.SongInfo.Title}") .WithDescription($"{resolvedSong.PrettyName}\nQueue #{musicPlayer.Playlist.Count + 1}")
.WithDescription($"Queue #{musicPlayer.Playlist.Count + 1}") .WithThumbnail(tn => tn.Url = resolvedSong.Thumbnail)
.WithFooter(ef => ef.WithText($"{resolvedSong.PrettyProvider}")) .WithFooter(ef => ef.WithText(resolvedSong.PrettyProvider))
.Build()) .Build())
.ConfigureAwait(false); .ConfigureAwait(false);
if (queuedMessage != null) if (queuedMessage != null)

View File

@ -2651,33 +2651,6 @@ namespace NadekoBot.Resources {
} }
} }
/// <summary>
/// Looks up a localized string similar to getlink gl.
/// </summary>
public static string getlink_cmd {
get {
return ResourceManager.GetString("getlink_cmd", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Shows a link to the song in the queue by index, or the currently playing song by default..
/// </summary>
public static string getlink_desc {
get {
return ResourceManager.GetString("getlink_desc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to `{0}gl`.
/// </summary>
public static string getlink_usage {
get {
return ResourceManager.GetString("getlink_usage", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to give. /// Looks up a localized string similar to give.
/// </summary> /// </summary>

View File

@ -1692,15 +1692,6 @@
<data name="goto_usage" xml:space="preserve"> <data name="goto_usage" xml:space="preserve">
<value>`{0}goto 30`</value> <value>`{0}goto 30`</value>
</data> </data>
<data name="getlink_cmd" xml:space="preserve">
<value>getlink gl</value>
</data>
<data name="getlink_desc" xml:space="preserve">
<value>Shows a link to the song in the queue by index, or the currently playing song by default.</value>
</data>
<data name="getlink_usage" xml:space="preserve">
<value>`{0}gl`</value>
</data>
<data name="autoplay_cmd" xml:space="preserve"> <data name="autoplay_cmd" xml:space="preserve">
<value>autoplay ap</value> <value>autoplay ap</value>
</data> </data>