using System;
// 'youtube-dl' you can find here: (https://github.com/rg3/youtube-dl/releases/latest)
// For some additional options may need 'ffmpeg' and you can find it here: (https://ffmpeg.zeranoe.com/builds/)
// Copy ffmpeg from the bin directory to a dir where 'youtube-dl.exe' stored
public static class ClipboardFusionHelper
{
public static string ProcessText(string url)
{
// Check that url is a link to youtube
if(url.Contains("youtube.com") || url.Contains("youtu.be"))
{
// Set your path to youtube-dl. For example (@"C:\YouTube-Download\youtube-dl.exe")
var binPath = @"HERE'S_YOUR_PATH_TO_YOUTUBE-DL.EXE";
// Set your dir where the downloaded files will be saved. For example (@"C:\My YT Saved Video")
var pathToFiles = @"HERE'S_YOUR_PATH_TO_THE_SAVED_FILES";
// Set format to save files see (https://github.com/rg3/youtube-dl/blob/master/README.md) for more help
var fullPath = System.IO.Path.Combine(pathToFiles, "%(title)s.%(ext)s");
// Simple download 720p mp4 video does not require ffmpeg
var arg = string.Format(@"-o ""{0}"" --no-playlist -q -f best {1}", fullPath, url);
// If you want to use other parameters, a different quality video or audio, like a next line,
// look (https://github.com/rg3/youtube-dl/blob/master/README.md) to see what option you need.
// And make sure what you have 'ffmpeg' in 'youtube-dl' directory.
// var arg =
// string.Format(@"-o ""{0}"" --no-playlist --no-mtime -w -q -f bestvideo+bestaudio {1}",
// fullPath, url);
// Run youtube-dl
var appId = BFS.Application.Start(binPath, arg);
// Get youtube-dl window handle
var hWnd = BFS.Application.GetMainWindowByAppID(appId);
// Because youtube-dl is a console app, hide it's window
BFS.Window.SetWindowStyle(BFS.WindowEnum.WindowStyle.WS_DISABLED, hWnd);
// Wait for the application to complete
if(BFS.Application.WaitForExitByAppID(appId))
{
// Show message
BFS.Dialog.ShowMessageInfo("Work completed");
// And\or you can show dir with downloaded files
// BFS.Application.Start(pathToFiles);
}
}
// If url not youtube link show message
else BFS.Dialog.ShowMessageInfo("It's not youtube link");
return null;
}
}