Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure?

PabloMartinez's profile on WallpaperFusion.com
So, we're going to need youtube-dl. The latest version can be downloaded here: https://github.com/rg3/youtube-dl/releases/latest, or if you use python, you can get youtube-dl using pip pip install --upgrade youtube-dl.
If you just want to download the video in the 720p default format, all you have to do is set your path to the youtube-dl.exe and directory to save files.
If you want a different quality of audio or video, you should read and understand the format of the arguments. You can find the readme here: https://github.com/rg3/youtube-dl/blob/master/README.md, you'll also need ffmpeg to merge video and audio files. ffmpeg can be found here: https://ffmpeg.zeranoe.com/builds/. Copy the ffmpeg.exe from the bin directory to the directory where youtube-dl.exe is stored.

I tried to comment on all the code for those who don't understand C#, and I hope the comments are clear. :)

Code

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;
    }
}
Apr 4, 2017 (modified Apr 4, 2017)  • #1
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)