Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: rigorvzla en 31 Enero 2018, 01:02 am



Título: Ayuda con Nuget Descarga Video
Publicado por: rigorvzla en 31 Enero 2018, 01:02 am
Hola nuevamente , estoy usando un codigo capaz de bajar videos de youtube y funciona de manera espectacular mi problema es que no se como direccionar el archivo descargado a una carpeta que yo le asigne.
Tyrrrz/YoutubeExplode

Es ese el codigo que uso, y tome de prueba el codigo que tiene de ejemplo llamado "ConsoleDemo"

este se utiliza pegando la direccion del video de youtube pero lo crea en el mismo directorio raiz, si alguien lo ha usado que me pueda ayudar le estare muy agradecido.

Aqui el codigo que plantea

Código
  1. using System;
  2. using System.IO;
  3. using System.Threading.Tasks;
  4. using Tyrrrz.Extensions;
  5. using YoutubeExplode;
  6. using YoutubeExplode.Models.MediaStreams;
  7.  
  8. namespace DemoConsole
  9. {
  10.    public static class Program
  11.    {
  12.        /// <summary>
  13.        /// If given a YouTube URL, parses video id from it.
  14.        /// Otherwise returns the same string.
  15.        /// </summary>
  16.        private static string NormalizeId(string input)
  17.        {
  18.            if (!YoutubeClient.TryParseVideoId(input, out var id))
  19.                id = input;
  20.            return id;
  21.        }
  22.  
  23.        /// <summary>
  24.        /// Turns file size in bytes into human-readable string
  25.        /// </summary>
  26.        private static string NormalizeFileSize(long fileSize)
  27.        {
  28.            string[] units = { "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB" };
  29.            double size = fileSize;
  30.            var unit = 0;
  31.  
  32.            while (size >= 1024)
  33.            {
  34.                size /= 1024;
  35.                ++unit;
  36.            }
  37.  
  38.            return $"{size:0.#} {units[unit]}";
  39.        }
  40.  
  41.        private static async Task MainAsync()
  42.        {
  43.            // Client
  44.            var client = new YoutubeClient();
  45.  
  46.            // Get the video ID
  47.            Console.Write("YouTube URL: ");
  48.            var id = Console.ReadLine();
  49.            id = NormalizeId(id);
  50.  
  51.            // Get the video info
  52.            Console.WriteLine("Cargando...");
  53.            var video = await client.GetVideoAsync(id);
  54.            Console.WriteLine('-'.Repeat(100));
  55.  
  56.            // Print metadata
  57.            Console.WriteLine($"Id: {video.Id} | Title: {video.Title} | Author: {video.Author}");
  58.  
  59.            // Get media stream info set
  60.            var streamInfoSet = await client.GetVideoMediaStreamInfosAsync(id);
  61.  
  62.            // Get the most preferable stream
  63.            Console.WriteLine("Buscando la mejor calidad de video...");
  64.            var streamInfo = streamInfoSet.Muxed.WithHighestVideoQuality();
  65.            var normalizedFileSize = NormalizeFileSize(streamInfo.Size);
  66.            Console.WriteLine($"Quality: {streamInfo.VideoQualityLabel} | Container: {streamInfo.Container} | Size: {normalizedFileSize}");
  67.  
  68.            // Compose file name, based on metadata
  69.            var fileExtension = streamInfo.Container.GetFileExtension();
  70.            var fileName = $"{video.Title}.{fileExtension}";
  71.  
  72.            // Replace illegal characters in file name
  73.            fileName = fileName.Replace(Path.GetInvalidFileNameChars(), '_');
  74.  
  75.            // Download video
  76.            Console.WriteLine($"Descargando [{fileName}]...");
  77.            Console.WriteLine('-'.Repeat(100));
  78.  
  79.            var progress = new Progress<double>(p => Console.Title = $"Gestor de Descarga YouTube [{p:P0}]");
  80.            await client.DownloadMediaStreamAsync(streamInfo, fileName, progress);
  81.  
  82.            Console.WriteLine("Descarga completa!");
  83.            Console.ReadKey();
  84.        }
  85.  
  86.        public static void Main(string[] args)
  87.        {
  88.            // This demo prompts for video ID, gets video info and downloads one media stream
  89.            // It's intended to be very simple and straight to the point
  90.            // For a more complicated example - check out the WPF demo
  91.  
  92.            Console.Title = "Gestor de Descarga YouTube";
  93.  
  94.            // Main method in consoles cannot be asynchronous so we run everything synchronously
  95.            MainAsync().GetAwaiter().GetResult();
  96.        }
  97.    }
  98. }