public MusixSongResult Collect(Video video) { MusixSongResult Result = new MusixSongResult(); ExtrapResult Extrap = DetailsExtrapolator.ExtrapolateDetails(video.Title); FullTrack Track = FindTrack(Extrap, (video.Duration.HasValue ? video.Duration.Value : TimeSpan.FromSeconds(0)), 8000); Result.Extrap = Extrap; Result.HasLyrics = false; Result.SpotifyTrack = Track; Result.YoutubeVideo = video; return(Result); }
public static Video FindYoutubeVideo(FullTrack Track, double MaxDeviation, IDetailsExtrapolator Extrapolator) { YoutubeClient Client = new YoutubeClient(); Console.WriteLine("StartCheck"); var task = Task.Run(async() => await Client.Search.GetVideosAsync($"{Track.Artists[0].Name} - {Track.Name}")); Console.WriteLine("Wait"); task.Wait(); Console.WriteLine("Res "); var results = task.Result; foreach (Video video in results) { ExtrapResult Extrap = Extrapolator.ExtrapolateDetails(video.Title); if (Extrap.TrackName.ToLower().Contains(Track.Name.ToLower()) && (Extrap.TrackArtist == null || Extrap.TrackArtist.ToLower().Contains(Track.Artists[0].Name.ToLower()))) { if (Math.Abs(Track.DurationMs - video.Duration.TotalMilliseconds) <= MaxDeviation) { return(video); } } } return(null); }
//public static async Task<Video> FindYoutubeVideo(FullTrack Track, double MaxDeviation, IDetailsExtrapolator Extrapolator) //{ // YoutubeClient Client = new YoutubeClient(); // var results = await Client.Search.GetVideosAsync($"{Track.Artists[0].Name} - {Track.Name}").CollectAsync(); // foreach (var video in results) // { // ExtrapResult Extrap = Extrapolator.ExtrapolateDetails(video.Title); // if (Extrap.TrackName.ToLower().Contains(Track.Name.ToLower()) && (Extrap.TrackArtist == null || Extrap.TrackArtist.ToLower().Contains(Track.Artists[0].Name.ToLower()))) // { // if (Math.Abs(Track.DurationMs - video.Duration.Value.TotalMilliseconds) <= MaxDeviation) // { // return await Client.Videos.GetAsync(video.Id); // } // } // } // return null; //} public static async Task <Video> FindYoutubeVideoAsync(FullTrack Track, double MaxDeviation, IDetailsExtrapolator Extrapolator) { YoutubeClient Client = new YoutubeClient(); var results = await Client.Search.GetVideosAsync($"{Track.Artists[0].Name} - {Track.Name}").CollectAsync(); foreach (var video in results) { ExtrapResult Extrap = Extrapolator.ExtrapolateDetails(video.Title); if (Extrap.TrackName.ToLower().Contains(Track.Name.ToLower()) && (Extrap.TrackArtist == null || Extrap.TrackArtist.ToLower().Contains(Track.Artists[0].Name.ToLower()))) { if (Math.Abs(Track.DurationMs - video.Duration.Value.TotalMilliseconds) <= MaxDeviation) { return(await Client.Videos.GetAsync(video.Id)); } } } return(null); }