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 MusixClient(string SpotifyClientID, string SpotifyClientToken, string ImageCachePath = "", string AudioCachePath = "", IConversionProvider ConversionProvider = null) { if (ConversionProvider != null) { this.ConversionsProvider = ConversionProvider; } else { this.ConversionsProvider = new XabeFFMPEGProvider(); } Spotify = new SpotifyWebAPI(); AudioCache = AudioCachePath; this.ImageCachePath = ImageCachePath; this.SpotifyClientID = SpotifyClientID; this.SpotifyClientToken = SpotifyClientToken; DetailsExtrapolator = new DirectTrackExtrapolator(); }
//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); }