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 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 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); }
public async Task <MusixSongResult> Collect(string VideoURL) { Console.WriteLine("get id"); var video = await YouTube.Videos.GetAsync(YoutubeHeleprs.GetVideoID(VideoURL)); MusixSongResult Result = new MusixSongResult(); Console.WriteLine("run extrap"); ExtrapResult Extrap = DetailsExtrapolator.ExtrapolateDetails(video.Title); Result.Extrap = Extrap; FullTrack Track = FindTrack(Extrap, (video.Duration.HasValue ? video.Duration.Value : TimeSpan.Zero), 5000); Result.HasLyrics = false; Result.SpotifyTrack = Track; Result.YoutubeVideo = video; Console.WriteLine("ret."); return(Result); }
public static FullTrack FindTrack(SpotifyWebAPI Spotify, ExtrapResult Ext, TimeSpan BaseLength, double MaxDeviation) { PrintDebug($"searching tracks. Extrap; Name: {Ext.TrackName}, Artist: {Ext?.TrackArtist}. " + $" Source: {Ext.Source}"); SearchItem Results = Spotify.SearchItems(Ext.GetSearchTerm(), SpotifyAPI.Web.Enums.SearchType.Track, 20); FullTrack SelectedResult = null; foreach (var Result in Results.Tracks.Items) { PrintDebug(""); PrintDebug($"Spotify Track: {Result.Name}"); PrintDebug($"Spotify Artists: {string.Join(", ", Result.Artists.CastEnumerable(x => x.Name))}"); if (SelectedResult == null && ContainsMatch(Ext.TrackName, Ext.Source, Result.Name)) { PrintDebug("[Check] Name Passed"); if (BaseLength.TotalSeconds == 0 || !(Math.Abs(Result.DurationMs - BaseLength.TotalMilliseconds) > MaxDeviation)) { PrintDebug("[Check] Dur Passed"); if (!(string.IsNullOrEmpty(Ext.TrackArtist)) && ContainsMatch(Ext.TrackArtist, Ext.Source, Result.Artists[0].Name)) { PrintDebug("[Check] Len Passed"); SelectedResult = Result; } else { PrintDebug("[Check] len Failed"); } } else { PrintDebug("[Check] dur Failed"); } } else { PrintDebug("[Check] name Failed"); } } PrintDebug("Returned Tracks"); return(SelectedResult); }
public async Task <MusixSongResult> CollectAsync(string VideoURL) { string ID = YoutubeHeleprs.GetVideoID(VideoURL); Console.WriteLine($"VID: {ID}"); Video video = await YouTube.Videos.GetAsync(ID); MusixSongResult Result = new MusixSongResult(); Console.WriteLine("run extrap"); ExtrapResult Extrap = DetailsExtrapolator.ExtrapolateDetails(video.Title); Result.Extrap = Extrap; FullTrack Track = FindTrack(Extrap, video.Duration, 5000); Result.HasLyrics = false; Result.SpotifyTrack = Track; Result.YoutubeVideo = video; Console.WriteLine("ret."); return(Result); }
public MusixSongResult Collect(string VideoURL) { Console.WriteLine("get id"); var GetVid = YouTube.Videos.GetAsync(YoutubeHeleprs.GetVideoID(VideoURL)); Console.WriteLine("get wait"); GetVid.Wait(); Console.WriteLine("got vid"); Video video = GetVid.Result; MusixSongResult Result = new MusixSongResult(); Console.WriteLine("run extrap"); ExtrapResult Extrap = DetailsExtrapolator.ExtrapolateDetails(video.Title); Result.Extrap = Extrap; FullTrack Track = FindTrack(Extrap, video.Duration, 5000); Result.HasLyrics = false; Result.SpotifyTrack = Track; Result.YoutubeVideo = video; Console.WriteLine("ret."); return(Result); }
public FullTrack FindTrack(ExtrapResult Ext, TimeSpan BaseLength, double MaxDeviation) { return(SpotifyTrackFinder.FindTrack(Spotify, Ext, BaseLength, MaxDeviation)); }
public ExtrapResult ExtrapolateDetails(string Term) { int FPos = Term.IndexOf("ft.", 0, Term.Length, StringComparison.InvariantCultureIgnoreCase); if (FPos != -1) { Term = Term.Substring(0, FPos).Trim(' '); } bool InB = false; bool InSQB = false; string Ent = ""; string Remix = ""; string BracketContent = ""; string SQBracketContent = ""; foreach (char cha in Term) { if (!InB & !InSQB) { if (cha == '(') { InB = true; } else if (cha == '[') { InSQB = true; } else { Ent += cha; } } else { if (cha == ')') { if (InSQB) { SQBracketContent += cha; } InB = false; if (BracketContent.ToLower().Contains("remix")) { Remix = BracketContent; } BracketContent = ""; } else if (cha == ']') { if (InB) { BracketContent += cha; } InSQB = false; if (SQBracketContent.ToLower().Contains("remix")) { Remix = SQBracketContent; } SQBracketContent = ""; } else { if (InB) { BracketContent += cha; } if (InSQB) { SQBracketContent += cha; } } } } Term = Ent; ExtrapResult Result = new ExtrapResult() { Source = Term }; Term.Replace('|', '-'); if (Term.Contains("-")) { string artist = Term.Split('-')[0]; string Track = Term.Remove(0, artist.Length + 1); if (Track.Contains("-")) { Track = Track.Split('-')[0]; } if (artist.Contains("&")) { artist = artist.Split('&')[0]; } if (artist.Contains("-")) { artist = artist.Split('-')[0]; } if (!string.IsNullOrEmpty(artist)) { Result.TrackArtist = artist; } Result.TrackName = Track; } else { Result.TrackName = Term; Result.TrackArtist = ""; } Result.TrackArtist = Result.TrackArtist.Trim(' '); Result.TrackName = Result.TrackName.Trim(' '); if (Remix.Length != 0) { Result.TrackName += " " + Remix; } return(Result); }