description

Script de telechargement des videos dailymotion (au 20-10-2009)

Usage:

$ ./dailymotion-dl-19-10-09 http://www.dailymotion.com/video/xatsjf_zero-info-emission-du-12-octobre-20_news
[.] doesn't looks like an embed/object source, processing
[v] got FLV initial filename: http://www.dailymotion.com/cdn/FLV-320x240/video/xatsjf?auth=1256158869-c55a1fb2af0a9965edf8c8d33c7a1ca5
[.] will download in /home/fosco/temp/.19400, logging in /tmp/tmp.BrasFLewA8
[.] trying to download to .19400
[v] file downloaded
[.] trying to detect real filename
[v] real filemame detected as: 18186171.flv, renaming
$ ./dailymotion-dl-19-10-09 http://www.dailymotion.com/swf/xatehe
[.] looks like an embed/object source, flasm to the rescue
[.] trying to download http://www.dailymotion.com/swf/xatehe to /tmp/tmp.8OGvvHmVCj
[v] http://www.dailymotion.com/swf/xatehe downloaded, uncompressing
[.] scanning swf for streams
[v] found FLV-320x240 data
[v] found H264-848x480 data
[v] found H264-512x384 data
[.] using H264-848x480
[v] got FLV initial filename: http://www.dailymotion.com/cdn/H264-848x480/video/xatehe?auth=1256158879-8e952038862819a7f4bd6e5f893f3854@@h264-hq
[.] will download in /home/fosco/temp/.19418, logging in /tmp/tmp.38JQdScfjq
[.] trying to download to .19418
[v] file downloaded
[.] trying to detect real filename
[v] real filemame detected as: 18167954:mp4_h264_aac_hq.mp4, renaming

code bash

#!/usr/bin/env bash
#
#     dailymotion-dl
#     version 0.3.0
#
#
#  Copyright (C) 2009 Trecourt Nicolas
#
#  dailymotion-dl is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
# ------------------------------------------------------------
 
if [ "$1" = "" ]
then
        echo "Please specify an URL"
        exit 1
fi
 
# this will be used to store cookies
cookfile=`mktemp`
 
if [ "`echo $1 | grep "^http://www.dailymotion.com/swf/"`" ]
then
        echo "[.] looks like an embed/object source, flasm to the rescue"
        tmpfile=`mktemp`
 
        echo "[.] trying to download $1 to $tmpfile"
        wget -q "$1" -O "$tmpfile" --user-agent="Mozilla/5.0" \
             --keep-session-cookies \
             --save-cookies "$cookfile"
        ret=$?
        if [ $ret -gt 0 ]
        then
                echo "[!] something went bad, wrong URL?"
                rm "$cookfile" "$tmpfile"
                exit 2
        fi
 
        echo "[v] $1 downloaded, uncompressing"
        flasm -x "$tmpfile" &> /dev/null
        if [ $ret -gt 0 ]
        then
                echo "[!] something went bad, is flasm installed?"
                rm "$cookfile" "$tmpfile"
                exit 3
        fi
 
        # this is to help parsing...
        sed -i -e 's/||/\t/g' "$tmpfile"
 
        echo "[.] scanning swf for streams"
        for k in `cat $tmpfile`
        do
                if [ "`echo "$k" | grep H264-848x480`" ]
                then
                        echo "[v] found H264-848x480 data"
                        H264848=$k
                elif [ "`echo "$k" | grep H264-512x384`" ]
                then
                        echo "[v] found H264-512x384 data"
                        H264512=`echo "$k" | cut -d{ -f1 | sed 's/}//g'`
                elif [ "`echo "$k" | grep FLV-320x240`" ]
                then
                        echo "[v] found FLV-320x240 data"
                        FLV320=`echo "$k" | gawk '{ print substr($1, index($1, "{{video}}")+11)}'`
                fi
        done
        if [ "$H264848" != "" ]
        then
                localpart="$H264848"
                echo "[.] using H264-848x480"
        else
                if [ "$H264512" != "" ]
                then
                        localpart="$H264512"
                        echo "[.] using H264-512x384"
                else
                        localpart="$FLV320"
                        echo "[.] using FLV-320x240"
                fi
        fi
 
        rm "$tmpfile"
else
        echo "[.] doesn't looks like an embed/object source, processing"
fi
 
# First we get the damn "dummy" flv URL, this time we should be more carefull
if [ "$localpart" = "" ]
then
        localpart=`wget "$1" -O /dev/stdout -q --user-agent="Mozilla/5.0" \
                                               --keep-session-cookies \
                                               --save-cookies "$cookfile" \
                   | grep '.addVariable("video"' \
                   | sed -e "s/%3A/:/g" \
                       -e "s/%2F/\//g" \
                       -e "s/%3F/?/g" \
                       -e "s/%3D/=/g" \
                       -e "s/%40/@/g" \
                       -e "s/%7C/|/g" \
                       -e "s/%2C/,/g" \
                       -e "s/%25/%/g" \
                       -e "s/%26/\&/g" \
                   | gawk '// { print substr($0, index($0, "video=")+6, index($0, "@@spark") - index($0, "video=")-6) }' \
                   | cut -d " " -f 2 | sed -e "s/\"//g" -e "s/);//g"`
fi
 
if [ "$localpart" = "" ]
then
        echo "[!] cannot get FLV filename, maybe some HTML code change, or video don't exist"
        rm "$cookfile"
        exit 4
else
        tmpfile=`mktemp`
        echo "[v] got FLV initial filename: $localpart"
        echo "[.] will download in `pwd`/.$$, logging in $tmpfile"
fi
 
# ok now, the "tricky" (sort of) part, must got the "real" FLV
echo "[.] trying to download to .$$"
wget "$localpart" \
     --user-agent="Mozilla/5.0" \
     --keep-session-cookies \
     --save-cookies "$cookfile" \
     -o $tmpfile \
     -O .$$
 
ret=$?
if [ $ret -gt 0 ]
then
        echo "[!] something went bad, maybe some HTML code change, or video don't exist"
        exit 5
fi
 
rm "$cookfile"
echo "[v] file downloaded"
echo "[.] trying to detect real filename"
 
finalfile=`grep Location: "$tmpfile" | cut -d/ -f7 | cut -d? -f1`
if [ "$finalfile" = "" ]
then
        echo "[!] Unable to determine real filename from Location: header"
        echo "[.] renaming to $$.flv"
        mv .$$ $$.flv
else
        echo "[v] real filemame detected as: $finalfile, renaming"
        mv .$$ "$finalfile"
fi
 
rm "$tmpfile"
shell/pompaize_de_vidz_dailymotion.txt · Last modified: 2010/01/12 13:29 (external edit)
www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0