예제 #1
0
        static void Main(string[] args)
        {
            int times = 5; // prevent exceptions from resetting the entire test
            if (args.Length != 0)
                times = Int32.Parse(args[0]);
            int iterations = 5;
            if (args.Length > 1)
                iterations = Int32.Parse(args[1]);

            Console.WriteLine("Starting...");
            Console.WriteLine($"Times: {times}.");
            Console.WriteLine($"Iterations: {iterations}.");
            Console.WriteLine();

            Console.WriteLine("Getting results for YoutubeExtractor...");

            var elapsed = TimeSpan.Zero;

            for (int i = 0; i < times; i++)
            {
                RunChecked(() =>
                {
                    var watch = Stopwatch.StartNew();

                    for (int j = 0; j < iterations; j++)
                        DownloadUrlResolver.GetDownloadUrls(Uri);

                    watch.Stop();
                    elapsed += watch.Elapsed;
                });
            }

            Console.WriteLine($"YoutubeExtractor: took {elapsed}.");
            Console.WriteLine();

            Console.WriteLine("Getting results for Livid...");

            elapsed = TimeSpan.Zero;

            using (var service =
                new SingleClientService(new YouTubeService()))
            {
                for (int i = 0; i < times; i++)
                {
                    RunChecked(() =>
                    {
                        var watch = Stopwatch.StartNew();

                        for (int j = 0; j < iterations; j++)
                            service.GetAllUris(Uri);

                        watch.Stop();
                        elapsed += watch.Elapsed;
                    });
                }
            }

            Console.WriteLine($"Livid: took {elapsed}.");
        }
예제 #2
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Valks!");
            Console.WriteLine("Easily save your favorite videos from YouTube.");

            using (var service =
                   new SingleClientService(new YouTubeService()))
            {
                while (true)
                {
                    Console.WriteLine();
                    Console.Write("Enter your video's ID: ");

                    string id = Console.ReadLine();

                    Console.WriteLine("Awesome! Downloading...");

                    var video = service.GetVideo("https://youtube.com/watch?v=" + id);

                    Console.Write("Finished! Would you like to save the video to Downloads? [y/n] ");

                    char opt = Console.ReadKey().KeyChar;

                    Console.WriteLine();

                    string folder;

                    if (Char.ToUpper(opt) == 'Y')
                        folder = GetDefaultFolder();
                    else
                    {
                        Console.Write("Please tell us where you'd like to save it: ");
                        folder = Console.ReadLine();
                    }

                    string path = Path.Combine(folder, GetFileName(video));

                    Console.WriteLine("Saving...");

                    File.WriteAllBytes(path, video.GetBytes());

                    Console.WriteLine("Done.");
                }
            }
        }