Mild achievements and severe disappointments

posted by Kirill on 2016-09-02

Update: This tutorial is out-of-date.

Since release of Firefox Quantum and subsequent changes to the extension API, launching external commands from Firefox requre installing some additional software, since WebExtensions have no OS level access. If you're not opposed to this idea, you can still adapt the following instruction to the new WebExtension addons, such as Open With or Send To External Media Player.

Let's integrate the best tool for downloading YouTube videos Youtube-dl with Firefox for the most pleasant downloading experience! Written for Windows users, as they are usually the ones that need the following instructions.

First, the motive behind this post. Being a musician, one of the actions I might perform multiple times in a day is downloading videos from YouTube. Being able to play them in my player of choice (mpv for now) is a huge convenience in case I need to transcribe some musical phrase, or speed some particularly slow speaker up by an arbitrary amount and having the video on my HDD gives me a slight sense of tranquility and confidence. In the past years people tried every accessible way to get the videos from YT with as little hassle as possible. Not all of these means worked good, and some of the suggestions in the Internet were, in fact, malicious, putting it mildly. As always, community to the rescue. Enter Youtube-dl!

BTW, there's TL-DR at the end!

For many years Youtube-dl remains the most reliable, flexible and safe way to download content from YT and many other video-hosting services. However, it's a commandline application, and most of the users manage to use their personal computers for hours at day and remain oblivious of mere existence of commandline software. There are many ways to integrate terminal in a gui-driven UX of modern browsers, but here's the easiest way to launch almost any application from Firefox and pass the link from the page as a parameter.


First of all, download the latest youtube-dl (direct link to the Windows build here). Place it anywhere on your drive, but remember that the folder the application resides in should be added to the PATH environment variable. Out of habit of the days past I place it in my Program Files directory, but for that you will probably need to have administrator rights.


Next, I suggest setting the automatic update procedure for the program, so any change in YouTube code, hopefully, would never affect the functionality of youtube-dl. To do this, open Task Scheduler: launch Run (press Win+R) and enter taskschd.msc /s. In the menu click Actions->Create Task… Name the new task youtube-dl update. On the Triggers tab make a new one, I recommend setting it to User log on with a small delay, in case your network adapter is slow to establish connection. In “actions” tab you need to select “Start a program” and enter (or browse for) the path to the youtube-dl executable. Then add -U argument in “Add arguments” textbox and hit OK. Run a newly created task to check if it's working.

Setting up FlashGot

And now, the main part. We need to install the FlashGot Firefox add-on. It's one of the oldest and most used add-ons ever, with more than 790000 users to date. After installation, type about:add-ons in you address bar, find FlashGot in the list and open its options. Add a new download manager and name it “youtube-dl”. Set the “Executable path” to %SystemRoot%\System32\cmd.exe (you can't edit the box directly, so just hit Browse and paste the line above). Why does the executable path leads to cmd.exe, and not to youtube-dl.exe? The thing is, in case anything goes wrong we want to be able to see what happened, but in case of just launching the CLI program directly the window will automatically close on completion or any error. So instead, we open an OS terminal and pass it the command to run as an argument. To do so, set everything like in the screenshot below and we're done!

Explaining the arguments

flashgot option

Let's look at what's in the arguments box: /c cd /d [FOLDER] & youtube-dl.exe [URL] & explorer.exe [FOLDER] & exit

With the /c passed all of the following string will be treated as a command to be launched. cd /d [FOLDER] switches the current directory to the one you will select on every FlashGot launch, youtube-dl.exe [URL] launches the actual downloading with the clicked/selected link as a parameter. explorer.exe [FOLDER] opens the folder where the file was downloaded and optional exit closes the terminal.

Note, that unfortunately we can't use quotes in this argument textbox, so we're limited to using the paths without them. This is the reason I suggested adding the place where you have your youtube-dl to your PATH variable. The other workaround that might have worked is escaping any whitespace with caret symbol ^. This would require changing the working dir to the place where youtube-dl sits and launching from there, but since we can't pass the output directory only, without the video name, with the --output option, this solution won't work. However, If you don't mind downloading to the same directory the program sits (in fact, in my case it downloads to %LOCALAPPDATA%\VirtualStore\Program Files\youtube-dl\ directory), the line should look similar to this: /c cd /d C:\Program^ Files\youtube-dl\ & youtube-dl.exe [URL].

After all the setting you should be able to download any YT video with minimum of one click (hold alt and click on a video link) and one Enter hit (on destination selection dialog). Easy Peasy!

TL-DR for the lazy:

  • Download youtube-dl
  • Open your Program Files dir, make a new one, name it “youtube-dl”
  • Press Win+R on a keyboard, enter taskschd.msc /s and run it.
    • Create a new regular task which launches youtube-dl with the -U parameter
  • Launch Firefox
    • Install the FlashGot addon
    • Open about:addons and open options for the FlashGot
    • Add a new download manager, enter %SystemRoot%\System32\cmd.exe as executable path and /c cd /d [FOLDER] & youtube-dl.exe [URL] & explorer.exe [FOLDER] & exit as its arguments below.
    • Check “Alt+Click = FlashGot” for convenience
  • Done! Alt-click everything you ever dreamed to!