This tutorial shows how to bulk download YouTube videos on Linux and then convert the FLV files to MPG video and MP3 audio files.
I am using Ubuntu Linux, but the concept should be the same for other distros. Make sure you already have all of the multimedia codecs including ffmpeg and mplayer. You will also need to install youtube-dl:
sudo apt-get install youtube-dl
To download YouTube videos on Linux, use youtube-dl in the terminal like this:
youtube-dl [options] video_url
To see available options type man youtube-dl in a terminal.
To convert YouTube movies from FLV to MPG on Linux use ffmpeg like this in the terminal:
ffmpeg -i old-file.flv new-file.mpg
It is easy to extract MP3 audio from a YouTube movie on Linux with mplayer.
The method to rip MP3 audio from FLV files with ffmpeg from this site doesn't work on my computer so I use mplayer to do it:
mplayer -dumpaudio old-file.flv -dumpfile new-file.mp3
If you want to download a set of YouTube movies and convert them to MP3 audio, or save them as MPG movies on your hard drive, you can automate the process with a shell script.
This is just a quick script showing how it might be done. Use the following code at your own risk, and make sure you understand what it does before doing it. It will delete all the FLV files in the current directory after it processes them.
#!/bin/sh
# This script downloads YouTube videos and converts them
# You will end up with an MPG video and MP3 audio of each YouTube movie
# You need to install the following three programs:
# youtube_dl, ffmpeg, and mplayer
# Use this script at your own risk!
# Make sure that you understand how it works before you use it!
# USAGE:
# Make a file called videos.txt with the URL of 1 YouTube video on each line.
# Don't leave any blank lines in the file
# Put the videos.txt file in an empty folder along with this script
# run this script with the following commands:
# $ ./youtube_downloader.sh
# It will take a long time to run, depending on
# how many videos you have in your videos.txt file.
while read inputline
do
youtube_url="$(echo $inputline)"
youtube-dl $youtube_url
done < videos.txt
# Convert the flv files to mpg and mp3 files
for i in *.flv
do
ffmpeg -i $i $i.mpg
# comment out the next line if you don't want MP3's extracted
mplayer -dumpaudio $i -dumpfile $i.mp3
# The next line deletes all FLV files in the current directory to cleanup
rm $i
done
See also pytube...
| Attachment | Size |
|---|---|
| youtube_downloader.sh.txt | 971 bytes |
Did you find this post helpful? Leave a comment below, and subscribe to my RSS feed.
Comments
http://www.bashterritory.com/
http://www.bashterritory.com/pytube
Where is the repository?
When I type "sudo apt-get install youtube-dl" in console I get "E: couldn't find package youtube-dl"
This tells me the repository where the file is located is probably unknown to my dear EEEpc. Could you please tell me where to find it, so I can try this promising program.
Universe
Sorry, I forgot to mention that it's in the Universe Repository (Ubuntu).
There's an Easier way to do this..
You're doing it the messy and somewhat painful way. Just visit http://www.vidimonkey.uni.cc click on bulk,
then paste in all your video links (can be from any site).
Then click submit or convert or hit enter. Wait as it starts to do its thing and it spits out a whole lot of video links which you can just download directly.
Now use SUPER or WinAVI (my fav) or any other converting program and most allow you to batch convert the videos, just add them and click convert to whatever format. Whole process takes about 1-2 hrs including download and conversion time on a 500mhz comp and doing about 20 30-40 minute videos.
Thanks!!
Works excellent! Thanks for taking the time to share this with us!
mp3 conversion
Is there a way to get mplayer to put out a stereo mp3 from an flv file?
I'm pretty new and I got lost in the man - the internet didn't do much for me either.
mplayer
I don't know how to do it, but there is some info the man pages.
I only had time to skim it — maybe mplayer -channel?
Automated download script
This is a great script! After using it for a while, I found a more sophisticated version (which does pretty much the same) here.
That variant allows downloading of videos in better quality (depending on whether the video has been uploaded to youtube in HQ or not of course).
Script
When i run the ./youtube_downloader.sh in terminal i get "Permission Denied" I have tried Sudo also but that isnt helping
youtube downloader
Did you make it executable first?
chmod +x ./youtube_downloader.shNo need to run as sudo...
Works Perfectly now
Thanks for your help works fine now
and congrats to whoever made this script
in my experience, I use
in my experience, I use Ubuntu 7.10 Gutsi, in $ sudo apt-get install youtube-dl command will looking for
http://archive.ubuntu.com/ubuntu/pool/universe/y/youtube-dl/youtube-dl_2007.08.24-1ubuntu0.1_all.deb
While the "youtube-dl_2007.08.24-1ubuntu0.1_all.deb" has been removed on the web.
So I open the web http://archive.ubuntu.com/ubuntu/pool/universe/y/youtube-dl/
There will be a list several newer version of the youtube-dl, click on the newest *.deb / matched with your system,
in my system there will be option "open with" which have default GDebi Package Installer, I use it.
It works :)