PDA

View Full Version : Download Youtube videos, browser independent



sea
7th December 2012, 12:19 PM
Hello Community

Chromium is a cool browser, sadly it doesnt let me download any youtube videos anymore.
And just for this cause i dont want to install Firefox for that task only.

In the default fedora repos there is a cool cli application named youtube-dl.
So, we're back to the console :D

As i'm lazy and sometimes want to download several videos, i wrote a little script that asks me to copy paste the urls from youtube into a file and downloads them automaticly for me.

For the least trouble running on/with linux, the default values are:
video format : webm
download dir: $XDG_DOWNLOAD_DIR
NOTE: Some older videos do not support webm, you might need to run the script for these videos again with other settings.

And for collectors it also saves the videos description and meta data in the same folder.

Install the script:

wget http://sea.hostingsociety.com/scripts/yt -o $HOME/bin/yt
chmod +x $HOME/bin/yt

Use the script:
Call the script from any kind of terminal window.
Paste the youtube url(s) into the editor, save and exit (nano: ctrl+o ; ctrl+x)
And watch the videos beeing downloaded one by one.

If you're using my script tools you'll get some colored output for easier reading and differ output,
whereas it (should) works just as well without it, it'll be just more plain text spam.
(see screenshots).

In 2013 and later, you'll find the latest script at: http://sea.hostingsociety.com/?p=Scripts&stc=yt

#!/bin/bash
#
# Description: Downloads multiple youtube videos from a list file
# Use -pl for playlists, -s for sound or -a for all infos.
# Pass an URL for a single video, or dont supply an URL
# and fill the list file.
#
# File: ~/youtube-dl
# Lisence: GPL v3
# Author: Simon A. Erat (sea), erat . simon gmail . com
# Release Date: 2012.12.07
# Changed Date: 2012.12.10
script_version=0.4
#
# non-Script-tools compatiblity
#
if [ ! -f /usr/share/script-tools/st.cfg ]
then alias sInst="sudo yum install -y "
alias sEdit="nano "
alias sE="echo -e '\n$@\n\n '"
alias sP="printf '\n$@\n\n '"
alias sT="echo -e '\n\t$@\n\n '"
fi
#
#
# Title
sT " sea's Youtube download Script ($script_version)"
#
# Variables
source $HOME/.config/user-dirs.dirs || \
XDG_DOWNLOAD_DIR=$HOME/Downloads
thisFile=$HOME/youtube-dl
targetDir=$XDG_DOWNLOAD_DIR/youtube
format=webm
audio=vorbis
url=""
#
# Requires
#
[ "" = "$(echo $(rpm -q youtube-dl|grep -v not))" ] && \
sInst youtube-dl
#
# Parse arguments
#
cmd="youtube-dl -c --console-title -t --max-quality $format"
for arg in $@;do
case ${arg:0:4} in
[-]-pl) cmd="$cmd --playlist-start --playlist-end" ;;
[-]-s) cmd="$cmd --extract-audio --audio-format $audio" ;;
[-]-a) cmd="$cmd --write-description --write-info-json" ;;
http) url="$arg" ;;
-h|--h|[-]-help) sE "Use -s for sound files, -a for all info or use -pl for playlists"
sE "Call it like:" "st net yt -pl \"http://www.youtube.com/?v=a9hflkn4\""
sE "Or simply:" "st net yt"
return 1
esac
done
#
# Read the file
#
[ ! -d $targetDir ] && mkdir -p $targetDir
cd $targetDir
if [ "" = "$url" ]
then sE "Please fill the file with some urls..." "$PROGRESS" && \
sleep 3 && \
sEdit $thisFile
while read line;do
if [ ! "" = "$(echo $line)" ]
then sT "Downloading $(echo $(youtube-dl --get-title $line --get-filename ))" "$PROGRESS"
$cmd $line
if [ $? -eq 0 ]
then sed s/'$line'/' '/g -i $thisFile
else sE "Failed downloading $(echo $(youtube-dl --get-title $line --get-filename ))"
sE "Use one of these formats:"
youtube-dl --list-formats $line
fi
fi
done < $thisFile
else $cmd $url
fi

Of course you can use youtube-dl directly as well:

sudo yum install youtube-dl -y

For all the commands below, i'll use the variable url which could represent any video url you copied from youtube. In this example i'll use this:

url=http://www.youtube.com/watch?v=N2tngd9F8N4

To get available video formats:

youtube-dl $url -F

To download all available free codecs, it could look like this:

youtube-dl $url --prefer-free-formats --all-formats

To make the downloaded file easier to be reckognized, as by default it saves the linkvalue with the file extension, you could use either one of these lines:

youtube-dl $url -t
youtube-dl -o "%(stitle)s.%(ext)s" $url
NOTE: There are more options to be used with -o. But stitle is the savest one.

EDIT: /*
Script handler Updated: 0.4
You may or may not supply a valid youtube video url to the script.
If you do, it will work with this url only.
If you dont, it will open a text editor (nano) and wants you to copy-paste several video urls.

There are now easy 'toggles' for my most used tasks
-pl : Expects playlist urls and downloads complete playlist.
-s : Will extract audio track from downloaded video, free codec preferred (vorbis)
-a : Save description and video meta data json file
*/

Hope this helps / ease the task.
Regards
sea

secipolla
7th December 2012, 04:04 PM
Hi. Just a heads up that you can download YT videos from Chromium.
Download this script at http://userscripts.org/scripts/show/62634 , then open the 'Extensions' page in Chromium and drag&drop the script.

Aso you might like this app: http://clipgrab.de/

nonamedotc
7th December 2012, 04:07 PM
Simon, that's a pretty handy tool! I have not had the need to use youtube-dl yet. But this is a convenient tool ...

sea
13th December 2012, 06:24 AM
Script handler Updated: 0.4
You may or may not supply a valid youtube video url to the script.
If you do, it will work with this url only.
If you dont, it will open a text editor (nano) and wants you to copy-paste several video urls.

There are now easy 'toggles' for my most used tasks
-pl : Expects playlist urls and downloads complete playlist.
-s : Will extract audio track from downloaded video, free codec preferred (vorbis)
-a : Save description and video meta data json file