# How to save YouTube videos



## balanga (Aug 19, 2019)

How do people save YouTube videos for watching them offline?


----------



## tedbell (Aug 19, 2019)

FreshPorts -- www/youtube_dl: Program for downloading videos from various services
					

youtube-dl is a small command-line program for downloading videos from YouTube.com, metacafe.com, google video, photobucket videos, yahoo videos, dailymotion and others




					www.freshports.org
				











						youtube-dl/README.md at master · ytdl-org/youtube-dl
					

Command-line program to download videos from YouTube.com and other video sites - youtube-dl/README.md at master · ytdl-org/youtube-dl




					github.com


----------



## sol289 (Aug 19, 2019)

there's great firefox (and apparently chrome too) extension, video downloadhelper, try it.


----------



## olli@ (Aug 19, 2019)

I also recommend youtube-dl(1) from the Ports collection (www/youtube_dl). It does not only support youtube, but literally thousands of video sites, including some that are not allowed to be mentioned here.  
Also, being a command line tool, youtube_dl can easily be embedded in your own scripts. It works independent of a browser, and it doesn't even require Xorg. By default it downloads and saves the best format (highest resolution) of the video available, but there are options to select other formats of video and audio. It can also convert the video to other formats if desired (using ffmpeg), extract the audio only (if you're just interested in the music of a video clip), and a plethora of other features.


----------



## balanga (Aug 19, 2019)

Just in case anyone want to grab youttube-dl() you should `pkg install youtube_dl` - note '*_*' rather than '*-*'.


----------



## hukadan (Aug 19, 2019)

If you want to avoid using the Youtube interface, I recommend multimedia/mps-youtube. From the description:


> Terminal based YouTube jukebox with playlist management.
> Main features:
> - Search and play audio/video from YouTube
> - Search tracks of albums by album title
> ...


----------



## balanga (Aug 19, 2019)

Am I missing something obvious?


```
youtube-dl https://www.youtube.com/watch?v=Ib7tFvw34DM
youtube-dl: No match.
```
I have no problem using YouTube with this video 



_View: https://www.youtube.com/watch?v=Ib7tFvw34DMe_
.

Same happens with every URL I've tried


----------



## T-Daemon (Aug 19, 2019)

Run `youtube-dl -F URL`, choose format, run `youtube-dl -f URL`

More options -h or READEME.md


----------



## twllnbrck (Aug 19, 2019)

balanga said:


> Am I missing something obvious?


Which shell do you use? I think e.g. zsh needs double quotes for the URL.


----------



## SirDice (Aug 19, 2019)

balanga said:


> Am I missing something obvious?


You need to put quotes around the URL due to the question mark in it.


----------



## svinoba (Aug 19, 2019)

twllnbrck said:


> Which shell do you use? I think e.g. zsh needs double quotes for the URL.


Thank you. I confirm your observation. I first tried with my default shell sh, and youtube-dl() worked without issue. When changed to csh (I don't have zsh installed), got same error as balanga mentioned. Used quotes (both single and double) and it worked fine again.


----------



## balanga (Aug 19, 2019)

T-Daemon said:


> Run `youtube-dl -F URL`, choose format, run `youtube-dl -f URL`



I tried both, but it works now after following SirDice 's advice.


----------



## Beastie (Aug 19, 2019)

balanga said:


> Am I missing something obvious?
> 
> 
> ```
> ...


Actually for YouTube you don't even need the entire URL. The video ID (e.g. `$ youtube-dl Ib7tFvw34DMe`) will suffice. Yep, it _is_ that great!

And I know this may sound rather unorthodox, but I suggest you keep a copy of the script in your own ~/bin directory so that you can run `$ youtube-dl.py -U` every few days. YouTube changes frequently and the script is changed accordingly. Changes in the ports tree may be too slow, so doing what I suggest will guarantee you it's always up to date and ready to go. Case in point, the tree has 2019.07.30 while I'm at 2019.08.13. Sometimes it may not be a big deal but oftentimes it will be completely broken.

By the way, you can pass it multiple video IDs. E.g. `$ youtube-dl.py -f '160+worstaudio[ext=m4a]' -- vid_ID_1 vid_ID_2 vid_ID_3 vid_ID_4`. As you can see, you can be very creative with audio and video formats. The double dash is of course to tell the shell it's the end of command options because YouTube IDs will sometimes start with a dash and confuse the shell.

Check `$ youtube-dl.py --help` and have fun.


----------



## Alexander Huemeyer (Aug 19, 2019)

If you are looking for a gui, you can use jdownloader.


----------



## userxbw (Aug 20, 2019)

Here are some alias you can try, I have not tried these yet in here (Fbsd), they are from my arcoLinux install off of their .bashrc, so you might or might not be able to use them. but the actual command line part should work.


```
#youtube-dl
alias yta-aac="youtube-dl --extract-audio --audio-format aac "
alias yta-best="youtube-dl --extract-audio --audio-format best "
alias yta-flac="youtube-dl --extract-audio --audio-format flac "
alias yta-m4a="youtube-dl --extract-audio --audio-format m4a "
alias yta-mp3="youtube-dl --extract-audio --audio-format mp3 "
alias yta-opus="youtube-dl --extract-audio --audio-format opus "
alias yta-vorbis="youtube-dl --extract-audio --audio-format vorbis "
alias yta-wav="youtube-dl --extract-audio --audio-format wav "

alias ytv-best="youtube-dl -f bestvideo+bestaudio "
```


----------



## badbrain (Aug 20, 2019)

If you use Firefox there are a bunch of extensions support not only this but also with the help of ffmpeg, joint  audio and video, or extract audio from media file or even converting between media format. You don't have to mess with youtube-dl.


----------



## garry (Aug 21, 2019)

balanga said:


> How do people save YouTube videos for watching them offline?


I often download entire playlists like BSDCan proceedings or MIT OpenCourseware lectures and it's handy to keep the downloaded videos in proper order by prepending the index and make it all look better by removing the no-longer needed IDs such as Ib7tFvw34DMe.  I just put the appropriate command in a *youtube-playlist *shell script in my ~/bin directory.

```
#!/bin/sh
url="$1"
shift
opts="$@"
youtube-dl $opts -o "%(playlist_index)s-%(title)s.%(ext)s" $url
sync
```
so for example

```
youtube-playlist 'https://www.youtube.com/playlist?list=PL0C2D950BA6965E22'  -f bestvideo+bestaudio
```
and I get files with names such as
01-<title1>.mp4
02-<title2>.mp4


----------



## rationality (Mar 23, 2020)

balanga said:


> How do people save YouTube videos for watching them offline?


I also used the Firefox extension, but now I'm using a video converter for downloading videos from YouTube, Instagram or even Facebook. The downloader that I have is free and I need no registration to use it. Also, it's quick and easy to download. Usually, I use it to convert videos from Facebook to mp4, but what I like the most is that the videos are of good quality, moreover, I can download them in HD format. However, there are many other platforms for downloading, I recommend the one that I use, you should check it.


----------



## ziomario (Nov 11, 2021)

Hello to everyone. I was looking for a tool to download a youtube video and I've reached this page. After having read the whole post,I didn't understand well how to get the best video and audio for a single video downloaded from youtube. 

```
marietto@marietto:/usr/home/marietto/Desktop/TUTs $ youtube-dl -F https://www.youtube.com/watch?v=c9lylHK4jmo -f bestvideo+bestaudio 

[youtube] c9lylHK4jmo: Downloading webpage
[info] Available formats for c9lylHK4jmo:
format code  extension  resolution note
249          webm       audio only tiny   50k , webm_dash container, opus @ 50k (48000Hz), 9.96MiB
250          webm       audio only tiny   65k , webm_dash container, opus @ 65k (48000Hz), 12.94MiB
251          webm       audio only tiny  125k , webm_dash container, opus @125k (48000Hz), 24.83MiB
140          m4a        audio only tiny  129k , m4a_dash container, mp4a.40.2@129k (44100Hz), 25.60MiB
160          mp4        256x144    144p   74k , mp4_dash container, avc1.4d400c@  74k, 30fps, video only, 14.68MiB
278          webm       256x144    144p   93k , webm_dash container, vp9@  93k, 30fps, video only, 18.42MiB
133          mp4        426x240    240p  143k , mp4_dash container, avc1.4d4015@ 143k, 30fps, video only, 28.42MiB
242          webm       426x240    240p  181k , webm_dash container, vp9@ 181k, 30fps, video only, 35.95MiB
134          mp4        640x360    360p  300k , mp4_dash container, avc1.4d401e@ 300k, 30fps, video only, 59.42MiB
243          webm       640x360    360p  323k , webm_dash container, vp9@ 323k, 30fps, video only, 63.94MiB
135          mp4        854x480    480p  459k , mp4_dash container, avc1.4d401f@ 459k, 30fps, video only, 90.81MiB
244          webm       854x480    480p  467k , webm_dash container, vp9@ 467k, 30fps, video only, 92.50MiB
298          mp4        1280x720   720p60  741k , mp4_dash container, avc1.4d4020@ 741k, 60fps, video only, 146.65MiB
302          webm       1280x720   720p60 1136k , webm_dash container, vp9@1136k, 60fps, video only, 224.65MiB
247          webm       1280x720   720p 1289k , webm_dash container, vp9@1289k, 30fps, video only, 255.02MiB
136          mp4        1280x720   720p 1362k , mp4_dash container, avc1.4d401f@1362k, 30fps, video only, 269.43MiB
299          mp4        1920x1080  1080p60 2591k , mp4_dash container, avc1.64002a@2591k, 60fps, video only, 512.42MiB
303          webm       1920x1080  1080p60 3459k , webm_dash container, vp9@3459k, 60fps, video only, 683.94MiB
18           mp4        640x360    360p  656k , avc1.42001E, 30fps, mp4a.40.2 (44100Hz), 129.79MiB
22           mp4        1280x720   720p 1491k , avc1.64001F, 30fps, mp4a.40.2 (44100Hz) (best)

marietto@marietto:/usr/home/marietto/Desktop/TUTs $ youtube-dl -F https://www.youtube.com/watch?v=c9lylHK4jmo -f 22


[youtube] c9lylHK4jmo: Downloading webpage
[info] Available formats for c9lylHK4jmo:
format code  extension  resolution note
249          webm       audio only tiny   50k , webm_dash container, opus @ 50k (48000Hz), 9.96MiB
250          webm       audio only tiny   65k , webm_dash container, opus @ 65k (48000Hz), 12.94MiB
251          webm       audio only tiny  125k , webm_dash container, opus @125k (48000Hz), 24.83MiB
140          m4a        audio only tiny  129k , m4a_dash container, mp4a.40.2@129k (44100Hz), 25.60MiB
160          mp4        256x144    144p   74k , mp4_dash container, avc1.4d400c@  74k, 30fps, video only, 14.68MiB
278          webm       256x144    144p   93k , webm_dash container, vp9@  93k, 30fps, video only, 18.42MiB
133          mp4        426x240    240p  143k , mp4_dash container, avc1.4d4015@ 143k, 30fps, video only, 28.42MiB
242          webm       426x240    240p  181k , webm_dash container, vp9@ 181k, 30fps, video only, 35.95MiB
134          mp4        640x360    360p  300k , mp4_dash container, avc1.4d401e@ 300k, 30fps, video only, 59.42MiB
243          webm       640x360    360p  323k , webm_dash container, vp9@ 323k, 30fps, video only, 63.94MiB
135          mp4        854x480    480p  459k , mp4_dash container, avc1.4d401f@ 459k, 30fps, video only, 90.81MiB
244          webm       854x480    480p  467k , webm_dash container, vp9@ 467k, 30fps, video only, 92.50MiB
298          mp4        1280x720   720p60  741k , mp4_dash container, avc1.4d4020@ 741k, 60fps, video only, 146.65MiB
302          webm       1280x720   720p60 1136k , webm_dash container, vp9@1136k, 60fps, video only, 224.65MiB
247          webm       1280x720   720p 1289k , webm_dash container, vp9@1289k, 30fps, video only, 255.02MiB
136          mp4        1280x720   720p 1362k , mp4_dash container, avc1.4d401f@1362k, 30fps, video only, 269.43MiB
299          mp4        1920x1080  1080p60 2591k , mp4_dash container, avc1.64002a@2591k, 60fps, video only, 512.42MiB
303          webm       1920x1080  1080p60 3459k , webm_dash container, vp9@3459k, 60fps, video only, 683.94MiB
18           mp4        640x360    360p  656k , avc1.42001E, 30fps, mp4a.40.2 (44100Hz), 129.79MiB
22           mp4        1280x720   720p 1491k , avc1.64001F, 30fps, mp4a.40.2 (44100Hz) (best)
```


----------



## eternal_noob (Nov 11, 2021)

ziomario said:


> I didn't understand well how to get the best video and audio for a single video downloaded from youtube.


Have you seen the examples in the man page of youtube-dl?

```
#    Download best mp4 format available or any other best if no mp4 available
$    youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'

#    Download best format available but no better than 480p
$    youtube-dl -f 'bestvideo[height<=480]+bestaudio/best[height<=480]'

#    Download best video only format but no bigger than 50 MB
$    youtube-dl -f 'best[filesize<50M]'

#    Download best format available via direct link over HTTP/HTTPS protocol
$    youtube-dl -f '(bestvideo+bestaudio/best)[protocol^=http]'

#    Download the best video format and the best audio format without merging them
$    youtube-dl -f 'bestvideo,bestaudio' -o '%(title)s.f%(format_id)s.%(ext)s'
```

Note that


> By default youtube-dl tries to download the best available quality, i.e. if you want the best quality you *don't* *need* to pass any special options, youtube-dl will guess it for you by *default*.


----------



## ziomario (Nov 11, 2021)

marietto@marietto:/usr/home/marietto/Desktop/TUTs $ youtube-dl -f '(bestvideo+bestaudio/best)protocol=http://youtubec9lylHK4jmo'

Usage: youtube-dl [OPTIONS] URL [URL...]

youtube-dl: error: You must provide at least one URL.

my achilles' heel is the difficulty in strictly respecting the syntactic form.


----------



## eternal_noob (Nov 11, 2021)

Yeah, you're doing it wrong. You mix up options and the url.


----------



## ziomario (Nov 11, 2021)

eternal_noob said:


> Yeah, you're doing it wrong. You mix up options and the url.



don't make me suffer . I've got the file using the command below,but it's not good for me. It grabs the webm file,but I want the mp4 file with the maximum quality.


```
marietto@marietto:/usr/home/marietto/Desktop/TUTs $ youtube-dl wDox97l3fcQ
```


----------



## eternal_noob (Nov 11, 2021)

Ok. 

But you know the saying "give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime".
Understanding the syntax of man pages is essential to be sucessful in the long term.


```
youtube-dl -f '(bestvideo+bestaudio/best)[protocol^=http]' http://youtubec9lylHK4jmo
```

Edit:


ziomario said:


> I want the mp4 file with the maximum quality.



Then you would use

```
youtube-dl -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best' wDox97l3fcQ
```


----------



## ziomario (Nov 11, 2021)

eternal_noob said:


> Ok.  But you know the saying "give a man a fish and you feed him for a day; teach a man to fish and you feed him for a lifetime"
> 
> 
> ```
> ...



I knew nothing of yesterday or tomorrow, I was enveloped and gently caressed by a happy today. Herman Hesse.


----------



## eternal_noob (Nov 11, 2021)

"Whoever fights monsters should see to it that in the process he does not become a monster. And if you gaze long enough into an abyss, the abyss will gaze back into you."
-- Friedrich Nietzsche


----------



## Abraham79 (Nov 11, 2021)

youtube-dl seems to be less active nowadays. There are forks and I am using `yt-dlp`  FYI.


----------



## ziomario (Nov 12, 2021)

eternal_noob said:


> "Whoever fights monsters should see to it that in the process he does not become a monster. And if you gaze long enough into an abyss, the abyss will gaze back into you."
> -- Friedrich Nietzsche



"Sometimes a cigar is just a cigar, but sometimes it's something else". Sigmund Freud.


----------

