Using native videolib api. added .mute and .deafen
This commit is contained in:
@@ -12,7 +12,7 @@ using System.Diagnostics;
|
||||
using NadekoBot.Extensions;
|
||||
using System.Threading;
|
||||
using Timer = System.Timers.Timer;
|
||||
using YoutubeExtractor;
|
||||
using VideoLibrary;
|
||||
|
||||
namespace NadekoBot.Classes.Music {
|
||||
public enum StreamState {
|
||||
@@ -51,18 +51,20 @@ namespace NadekoBot.Classes.Music {
|
||||
this.VoiceClient = mc.VoiceClient;
|
||||
this.Server = e.Server;
|
||||
this.Query = query;
|
||||
Task.Run(() => ResolveStreamLink());
|
||||
Task.Run(async () => await ResolveStreamLink());
|
||||
}
|
||||
|
||||
private void ResolveStreamLink() {
|
||||
VideoInfo video = null;
|
||||
private async Task ResolveStreamLink() {
|
||||
VideoLibrary.YouTubeVideo video = null;
|
||||
try {
|
||||
if (OnResolving != null)
|
||||
OnResolving();
|
||||
Console.WriteLine("Resolving video link");
|
||||
video = DownloadUrlResolver.GetDownloadUrls(Searches.FindYoutubeUrlByKeywords(Query))
|
||||
.Where(v => v.AdaptiveType == AdaptiveType.Audio)
|
||||
.OrderByDescending(v => v.AudioBitrate).FirstOrDefault();
|
||||
|
||||
video = (await YouTube.Default.GetAllVideosAsync(Searches.FindYoutubeUrlByKeywords(Query)))
|
||||
.Where(v => v.AdaptiveKind == AdaptiveKind.Audio)
|
||||
.OrderByDescending(v => v.AudioBitrate)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (video == null) // do something with this error
|
||||
throw new Exception("Could not load any video elements based on the query.");
|
||||
@@ -76,9 +78,10 @@ namespace NadekoBot.Classes.Music {
|
||||
return;
|
||||
}
|
||||
|
||||
musicStreamer = new MusicStreamer(this, video.DownloadUrl, Channel);
|
||||
musicStreamer = new MusicStreamer(this, video.Uri, Channel);
|
||||
if (OnQueued != null)
|
||||
OnQueued();
|
||||
return;
|
||||
}
|
||||
|
||||
internal string PrintStats() => musicStreamer?.Stats();
|
||||
|
@@ -11,16 +11,17 @@ using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using NadekoBot.Extensions;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
//github.com/micmorris contributed quite a bit to making trivia better!
|
||||
namespace NadekoBot {
|
||||
public class Trivia : DiscordCommand {
|
||||
public static float HINT_TIME_SECONDS = 6;
|
||||
|
||||
public static Dictionary<ulong, TriviaGame> runningTrivias;
|
||||
public static ConcurrentDictionary<ulong, TriviaGame> runningTrivias;
|
||||
|
||||
public Trivia() : base() {
|
||||
runningTrivias = new Dictionary<ulong, TriviaGame>();
|
||||
runningTrivias = new ConcurrentDictionary<ulong, TriviaGame>();
|
||||
}
|
||||
|
||||
public static TriviaGame StartNewGame(CommandEventArgs e) {
|
||||
@@ -28,7 +29,7 @@ namespace NadekoBot {
|
||||
return null;
|
||||
|
||||
var tg = new TriviaGame(e, NadekoBot.client);
|
||||
runningTrivias.Add(e.Server.Id, tg);
|
||||
runningTrivias.TryAdd(e.Server.Id, tg);
|
||||
|
||||
return tg;
|
||||
}
|
||||
@@ -86,7 +87,8 @@ namespace NadekoBot {
|
||||
};
|
||||
|
||||
internal static void FinishGame(TriviaGame triviaGame) {
|
||||
runningTrivias.Remove(runningTrivias.Where(kvp => kvp.Value == triviaGame).First().Key);
|
||||
TriviaGame throwaway;
|
||||
runningTrivias.TryRemove(runningTrivias.Where(kvp => kvp.Value == triviaGame).First().Key,out throwaway);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user