static string VideoDownload(string url) { var youtubeDl = new YoutubeDL(); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { youtubeDl.YoutubeDlPath = "./tools/youtube-dl.exe"; } else { youtubeDl.YoutubeDlPath = "./tools/youtube-dl"; } string filename = url.Split("/")[url.Split("/").Length - 2] + ".mp4"; youtubeDl.Options.FilesystemOptions.Output = filename; youtubeDl.VideoUrl = "https://reddit.com" + url; Console.WriteLine("https://reddit.com" + url); youtubeDl.StandardOutputEvent += (sender, output) => Console.WriteLine(output); youtubeDl.StandardErrorEvent += (sender, errorOutput) => Console.WriteLine(errorOutput); string commandToRun = youtubeDl.PrepareDownload(); youtubeDl.Download(); youtubeDl = null; return(filename); }
private async Task <VideoQualityFormat> getVideoFormatsAsync(string url) { VideoQualityFormat data = null; var updateGUIThread = new Progress <string>((value) => { }); var updateMainForm = updateGUIThread as IProgress <string>; await Task.Run(() => { string x = ""; var youtubeDL1 = new YoutubeDL(); youtubeDL1.StandardOutputEvent += (sender, output) => { Console.WriteLine(output); x = output; }; youtubeDL1.StandardErrorEvent += (sender, errorOutput) => Console.WriteLine(errorOutput); youtubeDL1.VideoUrl = _VODObject.url; youtubeDL1.Options.VerbositySimulationOptions.DumpJson = true; //Only can do one json even at a time youtubeDL1.Download(); data = JsonConvert.DeserializeObject <VideoQualityFormat>(x); }); return(data); }
/// <summary> /// Downloads a file from youtube using ytdl by its id /// </summary> /// <param name="id">The id of the file to download</param> /// <param name="channel">The channel that requested the download</param> public void ById(string id, Channel channel) { // If the file doesn't already exist, download if (!File.Exists($"./audio_files/{id}.mp3")) { // Download audio only ytdl.Options.PostProcessingOptions.ExtractAudio = true; ytdl.Options.FilesystemOptions.Output = $"./audio_files/{id}.mp3"; ytdl.Options.PostProcessingOptions.AudioFormat = NYoutubeDL.Helpers.Enums.AudioFormat.mp3; ytdl.VideoUrl = $"https://www.youtube.com/watch?v={id}"; // Subscribe to console output ytdl.StandardOutputEvent += (sender, output) => { if (output.Contains("[download]")) { Console.WriteLine("YTDL: " + output); } }; ytdl.StandardErrorEvent += (sender, errorOutput) => { throw new Exception(errorOutput); }; // Execute download ytdl.Download(); ConvertMp3ToOpusOgg(id); } channel.audioServerQueue.Add(id); }
private async Task PlayYoutubeSongByIdAsync(string id) { var output = $"{Config.DataDirectory}/youtubeDownloads/{id}.mp4"; if (!File.Exists(output)) { _youtubeDl.Options.FilesystemOptions.Output = output; _youtubeDl.Options.PostProcessingOptions.ExtractAudio = true; var process = _youtubeDl.Download($"https://www.youtube.com/watch?v={id}"); while (true) { await Task.Delay(100).ConfigureAwait(false); if (process.HasExited) { break; } } } if (Context.User is IVoiceState state && state.VoiceChannel != null) { await _audioService.QueueFileAsync( Context.Channel as ITextChannel, state.VoiceChannel, output).ConfigureAwait(false); } }
public IActionResult DownloadVideo(string url) { youtubeDl.CancelDownload(); var process = new Process(); process.StartInfo.FileName = "./del.bat"; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.Start(); process.WaitForExit(); youtubeDl.Options.FilesystemOptions.Output = "/video.mp4"; youtubeDl.Options.VideoFormatOptions.Format = NYoutubeDL.Helpers.Enums.VideoFormat.mp4; youtubeDl.Options.PostProcessingOptions.ExtractAudio = false; youtubeDl.VideoUrl = url; System.Diagnostics.Debug.WriteLine("ok"); youtubeDl.Download(); youtubeDl.CancelDownload(); return(Ok(url)); }
public async Task PlayLocal(params string[] search) { int querypages = 1; var items = new VideoSearch(); var message = await Context.Channel.SendMessageAsync("Searching..."); var urls = items.SearchQuery(string.Join(" ", search), querypages); var duration = urls.First().Duration; var thumbnail = urls.First().Thumbnail; await message.ModifyAsync(msg => msg.Content = "Downloading " + urls.First().Title + "..."); var urlToDownload = urls.First().Url; var newFilename = Guid.NewGuid().ToString(); var mp3OutputFolder = Environment.CurrentDirectory + "/songs/"; var downloader = new YoutubeDL(); downloader.VideoUrl = urlToDownload; downloader.YoutubeDlPath = @"C:\Users\thoma\source\repos\CoolDiscordBot\CoolDiscordBot\bin\Debug\youtube-dl.exe"; downloader.Options.FilesystemOptions.Output = Environment.CurrentDirectory + "/songs/" + newFilename; downloader.PrepareDownload(); downloader.Download(); var info = downloader.GetDownloadInfo(); while (downloader.ProcessRunning == true) { await Task.Delay(50); } EmbedBuilder builder = new EmbedBuilder(); builder.Title = Context.User.Username + "#" + Context.User.Discriminator; builder.AddField("Name", info.Title); builder.ThumbnailUrl = thumbnail; builder.AddField("Duration", duration); builder.AddField("Url", urlToDownload); await ReplyAsync("t", false, builder.Build()); audioModule = new audiomodule(); var voiceChannel = ((IVoiceState)Context.User).VoiceChannel; if (voiceChannel is null) { await ReplyAsync($"{Context.User.Mention} you are not in a voice channel!"); return; } var audioClient = await voiceChannel.ConnectAsync().ConfigureAwait(false); Console.WriteLine(newFilename); string path = "\"" + Environment.CurrentDirectory + "/songs/" + newFilename + ".mkv" + "\""; await audioModule.PlayLocalMusic(path, audioClient); }
private void Download(string yt) { YoutubeDL youtubeDL = new YoutubeDL(); youtubeDL.Options.FilesystemOptions.Output = String.Format(format, yt); youtubeDL.VideoUrl = "https://youtu.be/" + yt; youtubeDL.Download(); }
private static void DownloadVideo(string aVideoId) { fYoutubeDL.VideoUrl = "https://www.youtube.com/watch?v=7WFk23_6yos"; //string commandToRun = fYoutubeDL.PrepareDownload(); //Console.WriteLine(commandToRun); //https://gitlab.com/BrianAllred/NYoutubeDL //.\youtube-dl.exe -v -x -i --proxy "http://localhost:3128" --audio-format mp3 --prefer-ffmpeg --ffmpeg-location "C:\DjQbox\youtube-dl\ffmpeg-20170425-b4330a0-win64-static\bin" https://www.youtube.com/watch?v=7WFk23_6yos fYoutubeDL.Download(); }
protected override void ProcessRecord() { if (!Url.IsValidUrl()) { WriteVerbose($"The given url: \"{Url}\" is not valid."); return; } var client = new YoutubeDL { VideoUrl = Url }; if (!string.IsNullOrWhiteSpace(ConfigurationFile)) { var resolvedPath = this.ResolvePaths(false, ConfigurationFile).SingleOrDefault() ?? throw new ArgumentException( "Cannot find the configuration file at the given path.", nameof(ConfigurationFile)); WriteVerbose($"Using \"{resolvedPath}\""); client.Options = Options.Deserialize(File.ReadAllText(resolvedPath)); } else if (!string.IsNullOrWhiteSpace(ConfigurationJson)) { WriteVerbose("Using json configuration"); client.Options = Options.Deserialize(ConfigurationJson); } else { WriteVerbose("Using default media options"); var includeThumbnail = !(NoThumbnail.IsPresent && NoThumbnail.ToBool()); client.ApplyDefaultMediaOptions(includeThumbnail); } WriteVerbose("Executing Youtubedl using the following parameters:"); WriteVerbose(client.Options.ToCliParameters()); if (MyInvocation.BoundParameters.ContainsKey("Verbose")) { client.StandardOutputEvent += (sender, output) => WriteLineExternal(output, ConsoleColor.Yellow); } client.StandardErrorEvent += (sender, errorOutput) => WriteLineExternal(errorOutput, ConsoleColor.Red); client.Download(); }
private async Task DownloadVideoAsync(string youtubeUrl) { try { var youtubeDl = new YoutubeDL(); WriteToStatusBar("Started downloading"); DirectoryInfo dir = new DirectoryInfo("Videos"); if (!dir.Exists) { dir.Create(); } var exportDir = dir.CreateSubdirectory(DateTime.Now.ToString("yyyy-MM-dd")); var exportFilePath = Path.Combine(exportDir.FullName, "video" + DateTime.Now.ToString("hh-mm-ss") + ".mkv"); //set format output and library locations youtubeDl.Options.FilesystemOptions.Output = exportFilePath; youtubeDl.Options.PostProcessingOptions.ExtractAudio = true; youtubeDl.Options.SubtitleOptions.AllSubs = true; youtubeDl.Options.PostProcessingOptions.KeepVideo = true; youtubeDl.Options.PostProcessingOptions.ConvertSubs = NYoutubeDL.Helpers.Enums.SubtitleFormat.srt; youtubeDl.Options.PostProcessingOptions.FfmpegLocation = @"ffmpeg-static\bin\ffmpeg.exe"; youtubeDl.VideoUrl = youtubeUrl; // Optional, required if binary is not in $PATH youtubeDl.YoutubeDlPath = @"youtube-dl\youtube-dl.exe"; youtubeDl.StandardOutputEvent += (sender, output) => WriteToStatusBar(output); youtubeDl.StandardErrorEvent += (sender, errorOutput) => WriteToStatusBar(errorOutput); // youtubeDl.Info.PropertyChanged += delegate { < your code here> }; // Prepare the download (in case you need to validate the command before starting the download) string commandToRun = await youtubeDl.PrepareDownloadAsync(); // Just let it run youtubeDl.Download(); // Wait for it WriteToStatusBar("Done! " + exportFilePath); } catch (Exception e) { WriteToStatusBar(e.Message.ToString()); } }
public static void Main(string[] args) { YoutubeDL ydlClient = new YoutubeDL(); ydlClient.Options.DownloadOptions.FragmentRetries = -1; ydlClient.Options.DownloadOptions.Retries = -1; ydlClient.Options.VideoFormatOptions.Format = Enums.VideoFormat.best; ydlClient.Options.PostProcessingOptions.AudioFormat = Enums.AudioFormat.best; ydlClient.Options.PostProcessingOptions.AudioQuality = "0"; string options = ydlClient.Options.Serialize(); ydlClient.Options = Options.Deserialize(options); ydlClient.StandardErrorEvent += (sender, error) => Console.WriteLine(error); ydlClient.StandardOutputEvent += (sender, output) => Console.WriteLine(output); ydlClient.Download("https://www.youtube.com/watch?v=dQw4w9WgXcQ"); }
public Task download(String url, IGuild guild) { var youtubeDl = new YoutubeDL(); Console.WriteLine("Writing download location"); youtubeDl.Options.FilesystemOptions.Output = @"C:\Users\david\source\repos\ConsoleApp2\ConsoleApp2\bin\Release\netcoreapp2.0\songs\" + guild.Id.ToString() + ".mp4"; youtubeDl.Options.PostProcessingOptions.ExtractAudio = true; youtubeDl.VideoUrl = url; youtubeDl.StandardOutputEvent += (sender, output) => Console.WriteLine(output); youtubeDl.StandardErrorEvent += (sender, errorOutput) => Console.WriteLine(errorOutput); Console.WriteLine("Begining download..."); youtubeDl.Download(); return(Task.CompletedTask); }
public static void Main(string[] args) { YoutubeDL ydlClient = new YoutubeDL(); ydlClient.Options.DownloadOptions.FragmentRetries = -1; ydlClient.Options.DownloadOptions.Retries = -1; ydlClient.Options.VideoFormatOptions.Format = Enums.VideoFormat.best; ydlClient.Options.PostProcessingOptions.AudioFormat = Enums.AudioFormat.best; ydlClient.Options.PostProcessingOptions.AudioQuality = "0"; string options = ydlClient.Options.Serialize(); ydlClient.Options = Options.Deserialize(options); ydlClient.StandardErrorEvent += (sender, error) => Console.WriteLine(error); ydlClient.StandardOutputEvent += (sender, output) => Console.WriteLine(output); ydlClient.Info.PropertyChanged += (sender, e) => { DownloadInfo info = (DownloadInfo)sender; var propertyValue = info.GetType().GetProperty(e.PropertyName).GetValue(info); switch (e.PropertyName) { case "VideoProgress": Console.WriteLine($" > Video Progress: {propertyValue}%"); break; case "Status": Console.WriteLine($" > Status: {propertyValue}"); break; case "DownloadRate": Console.WriteLine($" > Download Rate: {propertyValue}"); break; default: break; } }; ydlClient.Download("https://www.youtube.com/watch?v=dQw4w9WgXcQ"); }
private void DownloadURLAudioFile(string s) { var youtubeDl = new YoutubeDL(); youtubeDl.Options.FilesystemOptions.Output = s + ".m4a"; youtubeDl.Options.VideoFormatOptions.Format = NYoutubeDL.Helpers.Enums.VideoFormat.webm; youtubeDl.Options.PostProcessingOptions.ExtractAudio = true; youtubeDl.VideoUrl = s; //youtubeDl.Options.VerbositySimulationOptions.GetUrl = true; //System.Diagnostics.Debug.WriteLine(((NYoutubeDL.Models.VideoDownloadInfo)youtubeDl.GetDownloadInfo()).Url); youtubeDl.Download(); //((NYoutubeDL.Models.VideoDownloadInfo)youtubeDl.GetDownloadInfo()).Url //System.Diagnostics.Debug.WriteLine("test"); //////youtubeDl.GetDownloadInfo(). //SoundPlayer simpleSound = new SoundPlayer(s + ".m4a"); //simpleSound. //simpleSound.Play(); }
static void VideoDownload(string url) { var youtubeDl = new YoutubeDL(); if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { youtubeDl.YoutubeDlPath = "./tools/youtube-dl.exe"; } else { youtubeDl.YoutubeDlPath = "./tools/youtube-dl"; } youtubeDl.Options.FilesystemOptions.Output = "./video.mp4"; youtubeDl.VideoUrl = "https://reddit.com" + url; Console.WriteLine("https://reddit.com" + url); youtubeDl.StandardOutputEvent += (sender, output) => Console.WriteLine(output); youtubeDl.StandardErrorEvent += (sender, errorOutput) => Console.WriteLine(errorOutput); string commandToRun = youtubeDl.PrepareDownload(); youtubeDl.Download(); youtubeDl = null; }
//private void DownloadStreamForm_Load(object sender, EventArgs e) //{ //} private void testTwitchDownload() { if (_VODObject != null) { if (comboBox2.Text != string.Empty) { VideoQuality downloadQuality = _videoQualityFormats.VideoQualityList.Find(x => x.format == comboBox2.Text); NYoutubeDL.Helpers.FileSizeRate help = new NYoutubeDL.Helpers.FileSizeRate(1.0, NYoutubeDL.Helpers.Enums.ByteUnit.M); var youtubeDL = new YoutubeDL(); youtubeDL.VideoUrl = downloadQuality.url; youtubeDL.Options.DownloadOptions.LimitRate = help; string fileType = downloadQuality.extension; youtubeDL.Options.PostProcessingOptions.FfmpegLocation = "C:\\ffmpeg.exe"; youtubeDL.Options.FilesystemOptions.Output = String.Format(@"C:\Users\rgsch\Downloads\{0}_{1}.{2}", _VODObject.title, downloadQuality.format, fileType); Console.WriteLine(downloadQuality.size); int totalSeconds = 0; try { youtubeDL.StandardOutputEvent += (sender, output) => { Console.WriteLine(output); //sw.WriteLine(output); }; youtubeDL.StandardErrorEvent += (sender, errorOutput) => { Console.WriteLine(errorOutput); int timeIndex = errorOutput.IndexOf("time="); TimeSpan downloadedDuration = TimeSpan.Zero; if (timeIndex != -1) { TimeSpan.TryParse(errorOutput.Substring(timeIndex + 5, 8), out downloadedDuration); } if (timeIndex > 0) { Console.WriteLine(errorOutput.Substring(timeIndex + 5, 8)); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine((double)downloadedDuration.TotalSeconds / (double)totalSeconds); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); } }; totalSeconds = VODDuration(_VODObject.duration); youtubeDL.Download(); MessageBox.Show("Done"); } catch (Exception e) { Console.WriteLine(e.ToString()); } } } }
/// <summary> /// Downloads the VOD at the selected video quality using FFmpeg /// </summary> private void DownloadVOD() { string fileName = ""; var updateProgressBar = new Progress <int>(value => { progressBar1.Value = (value > 100) ? 100 : value; if (value >= 100) { Process.Start(System.IO.Directory.GetParent(fileName).FullName); } }); var updateLoadingMessage = new Progress <bool>(isPreparingToDownload => { if (isPreparingToDownload) { LoadingPictureBox.Image = Properties.Resources.loadingIcon; } else { LoadingPictureBox.Image = Properties.Resources.GreenCheck; } }); var updateGUIThreadDownload = updateProgressBar as IProgress <int>; var UpdateGUIThreadLoading = updateLoadingMessage as IProgress <bool>; if (_selectedVOD != null) { if (VideoQualityComboBox.Text != string.Empty) { PickVideoQualityLabel.Visible = false; //get selected video quailty VideoQuality downloadQuality = _videoQualityFormats.VideoQualityList.Find(x => x.format == VideoQualityComboBox.Text); fileName = (_selectedVOD.title + downloadQuality.format + "." + downloadQuality.extension); //replace all invalid filename chars with _ System.IO.Path.GetInvalidFileNameChars().ToList().ForEach(c => fileName = fileName.Replace(c, '_')); //get filename fileName = getSavedFileName(fileName); YoutubeDL youtubeDL = new YoutubeDL() { VideoUrl = downloadQuality.url, YoutubeDlPath = Properties.Settings.Default.YoutubeDLLocation }; youtubeDL.Options.PostProcessingOptions.FfmpegLocation = Properties.Settings.Default.MpegLocation; if (fileName != "") { youtubeDL.Options.FilesystemOptions.Output = fileName; } else { return; } try { int totalSeconds = 0; //download the VOD Task.Run(() => { youtubeDL.StandardOutputEvent += (sender, output) => { Console.WriteLine(output); }; youtubeDL.StandardErrorEvent += (sender, errorOutput) => { Console.WriteLine(errorOutput); int timeIndex = 0; TimeSpan downloadedDuration = TimeSpan.Zero; if (errorOutput.Contains("time=")) { timeIndex = errorOutput.IndexOf("time=") + 5; TimeSpan.TryParse(errorOutput.Substring(timeIndex, 8), out downloadedDuration); } if (timeIndex > 0) { updateGUIThreadDownload.Report((int)(((double)downloadedDuration.TotalSeconds / (double)totalSeconds) * 100)); } }; totalSeconds = VODDuration(_selectedVOD.duration); UpdateGUIThreadLoading.Report(true); youtubeDL.Download(); Thread.Sleep(1000); updateGUIThreadDownload?.Report(100); UpdateGUIThreadLoading.Report(false); }); } catch (Exception e) { Console.WriteLine(e.ToString()); } } else { PickVideoQualityLabel.Visible = true; } } }