private async Task <(bool, YoutubeVideo)> TryGetVideoAsync(ILavaTrack lavaTrack) { bool failed = false; YoutubeVideo video = null; if (lavaTrack.Uri.AbsoluteUri.Contains("youtu")) { Match match = YtRegex.Match(lavaTrack.Uri.AbsoluteUri); if (!match.Success) { failed = true; } video = await this.FetchYtRelatedVideoAsync(match.Value); if (video == null) { failed = true; } } else { failed = true; } return(failed, video); }
private async Task <string> GetNextTrackVideoUrlAsync(bool useDb, YoutubeVideo video) { if (!useDb) { return($"https://www.youtube.com/watch?v={video.Id.VideoID}"); } IDatabaseService dbService = this.ServiceManager.GetService <IDatabaseService>("Database"); using (IDatabaseContext ctx = await dbService.GetContextAsync()) { IYoutubeVideoID videoId = await ctx.Instance.GetRandomVideoIdAsync(); return(videoId == null ? string.Empty : $"https://www.youtube.com/watch?v={videoId.VideoID.Trim()}"); } }