Example #1
0
        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}");
        }
Example #2
0
        public void FileToListFileTest()
        {
            YouTuberHelpers.CreateSampleList();
            var fileToList = YouTuberHelpers.FileToList(Config.DownloadFile);

            fileToList.Count().ShouldBe(3);
            File.Delete(Config.DownloadFile);
        }
Example #3
0
        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);
        }
Example #4
0
        public void MapAudioTypeTest(int order, string input, MediaType.MediaCodec expected)
        {
            var codec = YouTuberHelpers.MapAudioType(input);

            codec.ShouldBe(expected);
        }
Example #5
0
        public void UnifyYouTubeUrlTest(int order, string input, string expected)
        {
            var youTubeUrl = YouTuberHelpers.UnifyYouTubeUrl(input);

            youTubeUrl.ShouldBe(expected);
        }