Skip to content

Instantly share code, notes, and snippets.

@mattiasghodsian
Created November 6, 2019 16:22
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattiasghodsian/085586dd0e26f74c5cd66853259e16e9 to your computer and use it in GitHub Desktop.
Save mattiasghodsian/085586dd0e26f74c5cd66853259e16e9 to your computer and use it in GitHub Desktop.
How to install and use youtube-dl

Ever needed a tutorial or just download non copyrighted material from YouTube to watch or listen offline?

YouTube-dl is a command-line tool which is open source and can be used to download videos from YouTube, Facebook, and other popular sites, see the full list here.


NOTE: Keep in mind some media contains copyrighted material.


Installation for

Step 1

Make a directory on your desktop or anywhere you like. Get a copy of youtube-dl.exe and copy the file in to your directory.

C:\Users\Username\Desktop\youtube-dl

Step 2

Create new text file and rename to download.ps1 (How to file extensions in the same directory.

file

Step 3

Get a copy of FFmpeg latest build for your windows architecture. Copy root folder in the zip file and copy over to your directory and rename it to FFmpeg.

Step 4 (Optional)

Edit download.ps1 with the editor of your choice. The code below downloads any YouTube video and converts to MP3 format(Requires FFmpeg or avconv).

Skip if you are familiar with commands.

if(![System.IO.File]::Exists('ffmpeg/bin/ffmpeg.exe')){
	break
}

Write-Host "####################################`n##  Youtube-dl Powershell script  ##`n##          by bitxo.se           ##`n####################################"   -ForegroundColor Red

$yturl = Read-Host -Prompt 'Enter YouTube URL' 
Write-Host "URL: $yturl" -ForegroundColor Red -BackgroundColor Yellow

.\youtube-dl.exe --ffmpeg-location "ffmpeg/bin" -f bestaudio --extract-audio --audio-format mp3 $yturl

PAUSE 

Step 5

By now your directory should look something like

file

If you skipped Step 4 you can run this command in Powershell in the same directory as youtube-dl.exe and your other files.

youtube-dl.exe --ffmpeg-location "ffmpeg/bin" -f bestaudio --extract-audio --audio-format mp3 https://www.youtube.com/watch?v=p4M3Gle4NQ4

[========]

Step 1

Update your system

sudo apt-get update

Step 2

The easy method is installing from the apt repository.

sudo apt-get install youtube-dl

Or using pip.

sudo apt-get install python-pip
sudo pip install youtube-dl

Step 3 (Optional)

If you wish to download a song from the channel NoCopyrightSounds and convert to MP3 format (Requires FFmpeg or avconv).

sudo apt-get install ffmpeg

Step 4

Before jumping straight to it read the the options youtube-dl has.

youtube-dl -h

Alias to simplify and less typing.

Command: ytdl-mp3 your-url-here

alias ytdl-mp3="sudo youtube-dl --extract-audio --audio-format mp3 $@"

Alias to empty youtube-dl cache.

Command: ytdl-cache

alias ytdl-cache="youtube-dl --rm-cache-dir" 

Youtube-dlg

A front-end GUI for youtube-dl for those who dislike the terminal

pip install youtube-dlg

Example: Download MP3 format

FFmpeg or avconv needed for this example. The argument --audio-format converts the video file to audio only, --audio-format the audio format in mp3, m4a etc and last the url.

youtube-dl --extract-audio --audio-format mp3 https://www.youtube.com/watch\?v\=IX2NQ1lq4ZM
@Poopooracoocoo
Copy link

Do you have another FFmpeg build for Windows? Zeranoe no longer builds.

@mattiasghodsian
Copy link
Author

Do you have another FFmpeg build for Windows? Zeranoe no longer builds.

Sure, this guy does builds for windows BtbN

@RohanNavlakhe2
Copy link

Thank You for sharing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment