Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 19/10/2010, à 00:52

bluelemon

script: telecharger megavideo avec wget / download megavideo with wget

I have reused a script from bitbit - http://userscripts.org/scripts/show/42944
and wrote a script to download on megavideo without premium account
so the script is sleeping every hour, and remove extra stream postfix
it have been tested on ubuntu and macos

Usage
    . url [filename]
    . urlfile
         file format: one line per video with url first and optionally filename separated by a tabulation
         while the script is running you can append lines in it (without removing completed lines)

url is something like http://www.megavideo.com/?v=xxxxxxxx

default download folder is the current one
to set another one: in ~/.megavideo/conf add destination=/home/user/....

Needed Tools (available via macports for macos)
    . wget
    . spidermonkey to execute javascript from console: apt-get install spidermonkey-bin

Source: http://code.google.com/p/openlemon/sour … /megavideo

#!/bin/bash

#
# author: openlemon
# the decrypt url part is from bitbit - http://userscripts.org/scripts/show/42944 
#

filesize () 
{
    [ ! -f "$1" ] && { echo 0; return; }
    echo $OSTYPE | grep linux  > /dev/null && echo `stat -c %s "$1"`
    echo $OSTYPE | grep darwin > /dev/null && echo `stat -f %z "$1"`
}

log () 
{ 
    echo -e `date '+%Y.%m.%d %T'` $* ; 
}

fail ()
{
    echo -e $*
    exit 1
}

getprm ()
{
    [ ! -f $1 ] && { echo $3; return; }
    [   -z $2 ] && { echo $3; return; }

    value=`cat $1 | grep "^$2" | head -n 1 | sed 's:[^=]*=\(.*\):\1:'`

    [ -z "$value" ] && { echo $3; return; }

    echo $value
}

echourl () 
{ 
    wget -q -O - "$1" 2> /dev/null
}

flvlink () 
{
    videoid=`expr $1  : '.*=\(.*\)'`
    [ -z "$videoid"  ] && return

    mkdir -p ~/.megavideo/tmp
    tmp=~/.megavideo/tmp/$videoid

    try=0
    while [ $try -lt 20 ] ; do 

        echourl $1 > $tmp-1
        id=`   cat $tmp-1 | grep "flashvars.v ="     | sed 's:.*"\(.*\)".*:\1:'`
        s=`    cat $tmp-1 | grep "flashvars.s ="     | sed 's:.*"\(.*\)".*:\1:'`
        title=`cat $tmp-1 | grep "flashvars.title =" | sed 's:.*"\(.*\)".*:\1:'`

        echourl "http://www.megavideo.com/xml/videolink.php?v=$id" | grep "<ROW " > $tmp-2
        un=`cat $tmp-2 | sed 's:.*un="\([^"]*\)".*:\1:'`
        k1=`cat $tmp-2 | sed 's:.*k1="\([^"]*\)".*:\1:'`
        k2=`cat $tmp-2 | sed 's:.*k2="\([^"]*\)".*:\1:'`

        hash=`smjs -e "$decrypt decrypt('$un', '$k1', '$k2');"`

        echo $hash | grep -qv ^0*$ && break
        
        try=$(($try+1))

    done
    rm -f $tmp-*

    echo http://www$s.megavideo.com/files/$hash/$title.flv
}


download () 
{
    url=$1

    videoid=`expr $url  : '.*=\(.*\)'`

    link=`flvlink $url`
    flv=`expr $link : '\(.*\)/[^/]*'`
    flvname=`expr $link : '.*/\([^/]*\)'`

    if [ ! -z "$2" ] 
        then name=$destination/$2.flv
        else name=$destination/$flvname
    fi
    out=$destination/_$videoid
    part=$out.part
    log=~/.megavideo/log/$videoid

    echo -e "\nurl\t$url\nid\t$videoid\nflv\t$flv\nout\t$name\n"

    [ -z "$videoid"  ] && { echo "videoid not found"; return; }
    [ "$name" == "$destination/" ] && { echo "name not found"; return; }
    [ "$name" == "$destination/.flv" ] && { echo "name not found"; return; }

    mkdir -p "$destination" ~/.megavideo/log
    touch "$out" 
    echo -n > "$part"
    
    while [ 1 ] ; do

        log "downloading"

        filesize=`filesize "$out"`

        wget --tries=1 -o $log -O "$part" $flv/$filesize

        grep -q 'ERROR' $log &&
        {    
            grep 'ERROR' $log
            echo -e "\nFAIL\t$*"
            log "FAIL"
            rm -f "$out"
            break
        }
        grep -q 100% $log &&
        {
            [ $filesize -eq 0 ] && cat "$part" >> "$out"
            [ $filesize -gt 0 ] && tail -c +10 "$part" >> "$out"
            mv "$out" "$name"
            log "DONE"
            break
        }

        partsize=`filesize "$part"`
        lastline=`cat "$part" | tail -n 1 | tr -Cd '[:alnum:]'`

        postfixsize=0
        echo $lastline | grep -q parameterswait &&
        {
            postfixsize=$((`tail -n 2 "$part" | wc -c`+14)) # 158
            waittime=$((`echo $lastline | sed 's:parameterswait\([0-9]*\)played.*:\1:'`+120))
        }
        [ -z "$waittime" ] && waittime=300

        [ $partsize -gt 1000000 ] &&
        {
            [ $filesize -eq 0 ] && head -c $(($partsize-$postfixsize)) "$part" >> "$out"
            [ $filesize -gt 0 ] && head -c $(($partsize-$postfixsize)) "$part" | tail -c +10 >> "$out"
        }

        echo -n > "$part"

        log wait $(($waittime/60)) minutes
        sleep $waittime

    done
    rm -f $log "$part"

}


main ()
{
    [ $# -lt 1 ] && fail "usage: megavideourl [flvfile] | urlfile"

    conf=~/.megavideo/conf
    destination=`getprm $conf destination .`

    if     echo $1 | grep -q ^http
    then 
        download "$1" "$2"
    else
        urlfile=$1

        [ ! -f $urlfile ] && fail "file not found: $urlfile"

        i=1
        while [ $i -le `cat "$urlfile" | wc -l` ]
        do
            line=`head -n $i "$urlfile" | tail -n 1`
            url=`echo "$line" | awk -F'\t' '{print $1}'`
            out=`echo "$line" | awk -F'\t' '{print $2}'`

            echo -e "\n$i : $url \t $out"
            download "$url" "$out"

            i=$(($i+1))
            [ ! -f "$urlfile" ] && fail "file not found: $urlfile"
        done
    fi
}

#
# this part is from bitbit - http://userscripts.org/scripts/show/42944
#

decrypt=\
"
function decrypt (str, key1, key2) 
{
    var loc1 = [];
    for (var loc3 = 0; loc3 < str.length; ++loc3) {
        loc1.push(('000' + parseInt(str.charAt(loc3), 16).toString(2)).slice(-4));
    }
    loc1 = loc1.join('').split('');
    var loc6 = [];
    for (var loc3 = 0; loc3 < 384; ++loc3) {
        key1 = (key1 * 11 + 77213) % 81371;
        key2 = (key2 * 17 + 92717) % 192811;
        loc6[loc3] = (key1 + key2) % 128;
    }
    for (var loc3 = 256; loc3 >= 0; --loc3) {
        var loc5 = loc6[loc3];
        var loc4 = loc3 % 128;
        var loc8 = loc1[loc5];
        loc1[loc5] = loc1[loc4];
        loc1[loc4] = loc8;
    }
    for (var loc3 = 0; loc3 < 128; ++loc3) {
        loc1[loc3] = loc1[loc3] ^ loc6[loc3 + 256] & 1;
    }
    var loc12 = loc1.join('');
    var loc7 = [];
    for (var loc3 = 0; loc3 < loc12.length; loc3 = loc3 + 4) {
        var loc9 = loc12.substr(loc3, 4);
        loc7.push(loc9);
    }
    var loc2 = [];
    for (var loc3 = 0; loc3 < loc7.length; ++loc3) {
        loc2.push(parseInt(loc7[loc3], 2).toString(16));
    }
    print (loc2.join(''));
}
"
 
main "$@"

Dernière modification par bluelemon (Le 24/11/2010, à 00:22)

Hors ligne