Shell Script to download youtube files from playlist Shell Script to download youtube files from playlist bash bash

Shell Script to download youtube files from playlist


OK so after further research and updating my version of youtube-dl, it turns out that this functionality is now built directly into the program, negating the need for a shell script to solve the playlist download issue on youtube. The full documentation can be found here: (http://rg3.github.com/youtube-dl/documentation.html) but the simple solution to my original question is as follows:

1) youtube-dl will process a playlist link automatically, there is no need to individually feed it the URLs of the videos that are contained therein (this negates the need to use grep to search for "watch?" to find the unique video id

2) there is now an option included to format the filename with a variety of options including:

  • id: The sequence will be replaced by the video identifier.
  • url: The sequence will be replaced by the video URL.
  • uploader: The sequence will be replaced by the nickname of the person who uploaded the video.
  • upload_date: The sequence will be replaced by the upload date in YYYYMMDD format.
  • title: The sequence will be replaced by the literal video title.
  • ext: The sequence will be replaced by the appropriate extension (likeflv or mp4).
  • epoch: The sequence will be replaced by the Unix epoch when creatingthe file.
  • autonumber: The sequence will be replaced by a five-digit number thatwill be increased with each download, starting at zero.

the syntax for this output option is as follows (where NAME is any of the options shown above):

youtube-dl -o '%(NAME)s' http://www.youtube.com/your_video_or_playlist_url

As an example, to answer my original question, the syntax is as follows:

youtube-dl -o '%(title)s.%(ext)s' http://www.youtube.com/playlist?list=PL2284887FAE36E6D8&feature=plcp

Thanks again to those who responded to my question, your help is greatly appreciated.


If you want to use the title from youtube page as a filename, you could use -t option of youtube-dl. If you want to use the title from your "video list" page and you sure that there is exactly one watch? URL for every <span class="title video-title" title, then you can use something like this:

#!/bin/bashTMPFILE=/tmp/downloader-$$onexit() {  rm -f $TMPFILE}trap onexit EXITcurl -s "$1" -o $TMPFILEi=0grep '<span class="title video-title "' $TMPFILE | cut -d\> -f2 | cut -d\< -f1 | while read title; do  titles[$i]=$title  ((i++))donei=0grep "watch?" $TMPFILE | cut -d\" -f4 | while read url; do  urls[$i]="http://www.youtube.com$url"  ((i++))donei=0; while (( i < ${#urls[@]} )); do  youtube-dl -o "${titles[$i]}.%(ext)" "${urls[$i]}"  ((i++))done

I did not tested it because I have no "video list" page example.


this following method work and play you titanic from youtube

youtube-downloader.shyoutube-video-url.sh

#!/bin/bashdecode() {    to_decode='s:%([0-9A-Fa-f][0-9A-Fa-f]):\\x\1:g'    printf "%b" `echo $1 | sed 's:&:\n:g' | grep "^$2" | cut -f2 -d'=' | sed -r $to_decode`}data=`wget http://www.youtube.com/get_video_info?video_id=$1\&hl=pt_BR -q -O-`url_encoded_fmt_stream_map=`decode $data 'url_encoded_fmt_stream_map' | cut -f1 -d','`signature=`decode $url_encoded_fmt_stream_map 'sig'`url=`decode $url_encoded_fmt_stream_map 'url'`test $2 && name=$2 || name=`decode $data 'title' | sed 's:+: :g;s:/:-:g'`test "$name" = "-" && name=/dev/stdout || name="$name.vid"wget "${url}&signature=${signature}" -O "$name"#!/usr/bin/env /bin/bashfunction youtube-video-url {    local field=    local data=    local split="s:&:\n:g"    local decode_str='s:%([0-9A-Fa-f][0-9A-Fa-f]):\\x\1:g'    local yt_url="http://www.youtube.com/get_video_info?video_id=$1"    local grabber=`command -v curl`    local args="-sL"    if [ ! "$grabber" ]; then        grabber=`command -v wget`        args="-qO-"    fi    if [ ! "$grabber" ]; then        echo 'No downloader available.' >&2        test x"${BASH_SOURCE[0]}" = x"$0" && exit 1 || return 1    fi    function decode {        data="`echo $1`"        field="$2"        if [ ! "$field" ]; then            field="$1"            data="`cat /dev/stdin`"        fi        data=`echo $data | sed $split | grep "^$field" | cut -f2 -d'=' | sed -r $decode_str`        printf "%b" $data    }    local map=`$grabber $args $yt_url | decode 'url_encoded_fmt_stream_map' | cut -f1 -d','`    echo `decode $map 'url'`\&signature=`decode $map 'sig'`}[ $SHLVL != 1 ] && export -f youtube-video-url

bash youtube-player.sh saalGKY7ifU

#!/bin/bashdecode() {    to_decode='s:%([0-9A-Fa-f][0-9A-Fa-f]):\\x\1:g'    printf "%b" `echo $1 | sed 's:&:\n:g' | grep "^$2" | cut -f2 -d'=' | sed -r $to_decode`}data=`wget http://www.youtube.com/get_video_info?video_id=$1\&hl=pt_BR -q -O-`url_encoded_fmt_stream_map=` decode $data 'url_encoded_fmt_stream_map' | cut -f1 -d','`signature=` decode $url_encoded_fmt_stream_map 'sig'`url=`decode $url_encoded_fmt_stream_map 'url'`test $2 && name=$2 || name=`decode $data 'title' | sed 's:+: :g;s:/:-:g'`test "$name" = "-" && name=/dev/stdout || name="$name.mp4"# // wget "${url}&signature=${signature}" -O "$name"mplayer -zoom -fs "${url}&signature=${signature}"

It uses decode and bash, that you may have installed.