#!/bin/bash # dailymotion-dld # # A downloader for dailymotion video # # usage: # dailymotion-dld urlofmovie outputfile # # License : Public Domain # # Author: Mjules # # Changelog : # 20080415 fix HD video link extraction (as h264 doesn't seems to be used anymore) # 20080207 initial version unset input unset output unset tmpfile unset have_curl unset url unset movie_part input="$1" output="$2" create_temporary_file() { tmpfile=`mktemp` || exit 1 if [ $? -ne 0 ]; then echo -e "\033[1m\033[31m Error:\033[0m Unable to create temporary file. Aborting." exit 1 fi } test_for_curl() { which curl >/dev/null 2>&1 if [ "$?" = "1" ]; then echo -e "\033[1mWarning:\033[0m curl not found" echo -e "\033[1mWarning:\033[0m fallback to wget" echo -e "\033[1mWarning:\033[0m You will not have a nice progress bar ;-) \n" have_curl="0" else have_curl="1" fi } download_page() { echo " Retrieving webpage" if [ "$have_curl" = "1" ]; then curl -f -s -o $tmpfile --url $input if [ "$?" = "22" ]; then echo -e "\033[1m\033[31m Error:\033[0m Page not found on server" exit 1 fi else wget -q "$input" -O if [ $? -gt 0 ]; then echo -e "\033[1m\033[31m Error:\033[0m Page not found on server" exit 1 fi fi echo " Page retrieved" } extraction() { echo " Let's go to extract real movie URL" if [ -f $tmpfile ]; then if [ `grep -hm 1 \(\"video\", $tmpfile | grep -o '1280x720%2Fon2' ` ] then #if we can, we download on2 stream echo -e " Found a \033[1m1280x720 on2\033[0m stream \n" movie_part=`grep -hm 1 \(\"video\", $tmpfile |awk -F'%40%40' '{print $3}'| grep -hom 1 'get%2F[^\"]*' | sed -e 's|%2F|/|g' -e 's|%3F|?|g' -e 's|%3D|=|g' ` else # we fallback on flv stream (mp4 ?) echo -e " Found a \033[1m320x240 flv\033[0m stream \n" movie_part=`grep -hm 1 \(\"video\", $tmpfile |awk -F'%40%40' '{print $1}'| grep -hom 1 'get%2F[^\"]*' | sed -e 's|%2F|/|g' -e 's/%3F/?/g' -e 's/%3D/=/g' ` fi url="http://www.dailymotion.com/"$movie_part else echo -e "\033[1m\033[31m Error:\033[0m Temporary file unavailable \n Unable to extract real URL, ending" exit 1 fi } download_movie() { echo -e " Now downloading movie: $url\n" if [ "$have_curl" = "1" ]; then curl --progress-bar -L -o $output --url $url else wget -q $url -O $output fi echo -e "\n Finished" rm -f $tmpfile } if [ ! "$input" ] || [ ! "$output" ] ; then echo -e "\n \033[1m Dailymotion-dld\033[0m \n " echo -e " Usage: dailymotion-dld urlofmovie outputfile \n " echo -e " needs wget or curl (preferred) to work \n" exit 1 else echo -e "\n \033[1m Dailymotion-dld\033[0m \n" if [ `echo $input | grep -o 'dailymotion.com'` ] || [ `echo $input | grep -o 'neufstream.com'` ]; then test_for_curl create_temporary_file download_page extraction download_movie else echo -e "\033[1m\033[31m Error:\033[0m urlofmovie should be a dailymotion or neufstream URL \n" exit 1 fi fi exit 0