Download this Youtube flash video converter

Here's a modified shell script which does the same as the online flv file format converters.
This shell script requires ffmpegX to be installed.

Source code is also below modified from another unix web example using wget the URL escapes me.


#!/bin/bash
# Darwin port @author:devnill 2008
#set -x # remove 1st hash to see debug

# check for no url provided Chocolate Gorilla Viral Advert as an example
if [ $# -lt 1 ]; then
echo "Please supply a youtube url e.g. $0 http://uk.youtube.com/watch?v=TnzFRV1LwIo"
exit 1
fi

ID=`echo $1 | cut -d= -f2 | cut -d\& -f1`
FILE="youtube_${ID}"
URL="http://youtube.com/get_video.php"

# -s is silent no display
curl -s $1 -o /tmp/${FILE}

if [ $? == 0 ]; then
PARAM=`grep '&t=' /tmp/${FILE} | head -n 1 | awk -F'&t=' '{print $2}' | cut -d\& -f 1`
echo
echo "Downloading flv file";
echo
# without -L it will not work
curl -L "${URL}?video_id=${ID}&t=${PARAM}" -o ${FILE}.flv
echo

# ask the user for a new format to convert to
read -p "Convert flv file, Enter one of these formats (avi, mov, mpg) : " format
echo

# set to default mov
if [ "${format}" == "" ]; then
format="mov";
fi


# this is required if path has space which needs escaping
OLD_IFS=$IFS
IFS=:

# give the file a more discriptive name
FLASH_TITLE="$(grep '&title=' /tmp/${FILE} | head -n 1 | awk -F'&title=' '{print $2}' | cut -d\; -f 1 | sed 's/ /_/g' )"

# make sure locatedb is uptodate run : /usr/libexec/locate.updatedb
ff_filepath="$( dirname `locate Resources/ffmpeg | head -1 | sed 's/ /\\ /g'` )"
export PATH=$PATH:$ff_filepath
IFS=$OLD_IFS
$(ffmpeg -i ./${FILE}.flv ./${FLASH_TITLE}.${format})
echo
fi

# clean up temp files and downloaded file
echo
echo "Removing temp file."rm -f /tmp/${FILE}
echo "Confirm downloaded flash video delete"
rm -i ./${FILE}.flv


Enjoy....

1 comments:

James said...

It's too complicated for me and other beginners. So I highly recommend My YouTube Converter. It can easily download and convert YouTube streaming video for playback on your iPod, PSP, Mobile Phones, PC, MP3 player...