youtube-dl

Updated: September 28, 2024

Youtube Downloader allows audio and video to be formatted and downloaded off the web.


USING YOUTUBE-DL

GitHub YOUTUBE-DL

youtube-dl somesite.com/vid
youtube-dl -x --embed-thumbnail --audio-format m4a https://www.youtube.com/video   # download audio only in mxx format with thumnail picture
youtube-dl -F https://www.youtube.com/video   # check available formats
youtube-dl -f 137+141 https://www.youtube.com/video   # download listed formats
youtube-dl --playlist-start 1 --playlist-end 5 https://www.youtube.com/video  # download first 5 vids of playlist
-b           	# best quality, no longer used (depreciated)
-m            	# mobile version
-o            	# output filename template
youtube-dl -o - BaW_jenozKc   # stream video being downloaded to stdout
-d           	# high definition
-g           	# don’t download, just show the url
-c           	# resume download of a video which was interrupted before
-w            	# don’t overwrite existing file
--recode-video FORMAT            # encode the video to another format if
                                 # necessary (currently supported:
                                 # mp4|flv|ogg|webm|mkv|avi)
-k, --keep-video                 # keep the video file on disk after the post-
                                 # processing; the video is erased by default
sudo youtube-dl -U		# update youtube-dl or use brew update

--id					# use id for name of file downloaded

--no-call-home			# do not contact youtube-dl servers

# You will first need to tell youtube-dl to stream media to stdout with -o -, and also tell your media player to read from stdin (it must be capable of this for streaming) and then pipe former to latter. For example, streaming to vlc can be achieved with:
youtube-dl -o - "https://www.youtube.com/watch?v=BaW_jenozKcj" | vlc -

Create a config file

mkdir -p ~/.config/youtube-dl/
echo "-o ~/Movies/%(title)s-%(id)s.%(ext)s" > ~/.config/youtube-dl/config
# always extract audio
-x
# format video to mp4 post-process
--recode-video mp4

# do not copy the mtime
--no-mtime

# use this proxy
--proxy 127.0.0.1:3128

# you can use --ignore-config if you want to disable the configuration file for a particular youtube-dl run.