public virtual async Task <string?> DownloadYouTubeAsync(string url, MediaType.MediaCodec codec) { string unified = YouTuberHelpers.UnifyYouTubeUrl(url); if (string.IsNullOrWhiteSpace(unified)) { return(Config.InvalidYouTube); } if (IsDuplicate(unified)) { return(Config.DuplicateYouTube); } IEnumerable <YouTubeVideo> videos = await _client.GetAllAvailableFormatAsync(unified); var video = FilterOnlyVideoFormats(videos).MaxBy(e => e.Resolution); string validationMessage = ValidateVideo(video); if (validationMessage != "OK") { return(validationMessage); } YouTuberHelpers.CreateFolder(Config.BaseFolder); string path = Path.Combine(Config.BaseFolder, video !.FullName); await File.WriteAllBytesAsync(path, await video.GetBytesAsync()); GetAudio(path, codec); return($"{video.Title} is ready under {Config.BaseFolder}"); }
public void IsDuplicateTest() { var service = new YouTubeService(); service .IsDuplicate(YouTuberHelpers.UnifyYouTubeUrl("https://www.youtube.com/watch?v=3rJfBFamlIw")) .ShouldBe(false); service .IsDuplicate(YouTuberHelpers.UnifyYouTubeUrl("https://www.youtube.com/watch?v=3rJfBFamlIw")) .ShouldBe(true); service .IsDuplicate(YouTuberHelpers.UnifyYouTubeUrl("https://www.youtube.com/watch?v=3rJfBFamlIw")) .ShouldBe(true); }
public void UnifyYouTubeUrlTest(int order, string input, string expected) { var youTubeUrl = YouTuberHelpers.UnifyYouTubeUrl(input); youTubeUrl.ShouldBe(expected); }