wget -O- -q --save-cookies .vk-cookie.txt "http://vk.com/login.php?act=login&email=$mail&pass=$pass" >>/dev/null
echo "/me/" | sed "s/\//\\\//"g>>var echo "/me/" | sed s/'\/'/'\\\/'/g >>var var=`echo "/me/" | sed s/'\/'/'\\\/'/g` var=`echo "/me/" | sed s#'\/'#'\\\/'#g` var=`echo "/me/" | sed "s/\//\\\//"g`
In the first and third cases, the command is not executed, reporting a syntax error somewhere in the middle of the line. In the fifth case, the command does nothing with the string being transmitted. And only using the second and fourth options - we get the desired result (replacing "/" with "\ /"). wget --spider $addr >>/dev/null # checking if [ $? -ne 0 ]; then #if file not exist else fi
action=$(yad --center --width=400 --title="Vkvideo Save" --text="Simple video downloader" --form --field="Select Resolution::CB" --field="Name" --field="Folder:DIR" --field="Keep Cookies:CHK" "720!480!360!240" "$tname" "$HOME" TRUE --button="Open File:2" --button="Save File:0" --button="gtk-cancel:1")
tres=`echo $action | sed -es/'|.*|'/''/` tname=`echo $action | sed -es/"$tres"'|'/''/ | sed -es/"|.*"/''/` tfolder=`echo $action | sed -es/"$tres"'|'"$tname"'|'/''/ | sed -es/"|.*"/''/`
wget $addr -O "$tfolder/$tname.$tres.mov" 2>&1 |sed -u 's/.* \([0-9]\+%\)\ \+\([0-9.]\+.\) \(.*\)/\1\n# Downloading at \2\/s, time left: \3/'| yad --width=500 --center --title="Downloading progress" \ --text="Downloading '$tname.$tres.mov' " --progress --auto-close --auto-kill &
#!/bin/bash #$1 link name #$2 resolution #$3 save file name #checking for existing cookies res=(720 480 360 240) tadr=$1 tres=$2 tname=$3 if [ -z "$tres" ]; then echo "$tres" tres=720 fi if [ ! -f "$HOME/.vk-cookie.txt" ]; then action1=$(yad --center --title="Lost cookies" --text="You need to enter mail and password" --form --field='Mail' --field='Password':H --button="gtk-ok:0" --button="gtk-cancel:1") mail=`echo $action1 | sed -es/'|.*|'/''/` password=`echo $action1 | sed -es/"$mail|"/''/ | tr -d '|'` echo "Getting cookies" wget -O- -q --save-cookies .vk-cookie.txt "http://vk.com/login.php?act=login&email=$mail&pass=$pass" >>/dev/null echo "Cookies saved" fi while [ "$SoD" != "finishdone" ] do echo "Page downloading...." LANG=ru_RU.CP1251 wget -q --load-cookies .vk-cookie.txt "$tadr" -O .tempf #download the page echo "Page recieved" enconv -x=UTF-8 -L ru .tempf grep -i ltag .tempf| egrep -o "http:\\\/\\\/cs[0-9]*.vkontakte.ru\\\/[az][0-9]*\\\/"| sed -es/'http:\\\/\\\/cs'/'http:\/\/cs'/ | sed -es/'vkontakte.ru\\\/'/'vk.com\/'/| sed -es/'\\'/''/ >> .tempama #get server and owner names echo video/>> .tempama if [ "$tname" == "" ]; then #echo `cat .tempf` egrep -o "md_title.*md_author" .tempf | sed -es/'md_title\\\"\:\\\"'/''/ |sed -es/'\\\"\,\\\"md_author.*'/''/>>.tempnam tname=`cat .tempnam|sed s#' | '#' '#g|sed s#'[|,/,\]'#' '#g|tr --squeeze-repeats ' '| tr '[]{}' '()()'|sed s#' \([(,)]\)'#'\1'#g|sed s#'\([(,)]\) '#'\1'#g` rm .tempnam fi addr=`cat .tempama` addr=`echo $addr | tr -d ' '` if [ $addr == "video/" ]; then tadr=$(yad --width 500 --center --title="Bad address" --text="Bad address. Reenter please" --entry --button="gtk-cancel:1" ) rm .tempama rm .tempf else SoD=finishdone fi done echo "Ready for downloading" action=$(yad --center --width=400 --title="Vkvideo Save" --text="Simple video downloader" --form --field="Select Resolution::CB" --field="Name" --field="Folder:DIR" --field="Keep Cookies:CHK" "720!480!360!240" "$tname" "$HOME" TRUE --button="Open File:2" --button="Save File:0" --button="gtk-cancel:1") SO=$? tres=`echo $action | sed -es/'|.*|'/''/` tname=`echo $action | sed -es/"$tres"'|'/''/ | sed -es/"|.*"/''/` tfolder=`echo $action | sed -es/"$tres"'|'"$tname"'|'/''/ | sed -es/"|.*"/''/` echo $tfolder | sed "s$\/$\\\/$"g>>tvar tvar=`cat tvar` keep=`echo $action | sed -es/"$tres"'|'"$tname"'|'"$tvar"'|'/''/ | tr -d '|'` rm tvar grep -i ltag .tempf| egrep -o 'vtag\\\"\:\\\"[a-z0-9]*\\'| sed 's/vtag\\\"\:\\\"//'|sed -es/'\\'/'\.'"$tres"'\.mov'/ >>.tempam #get video file name addr=`cat .tempama .tempam` #recover full link addr=`echo $addr | tr -d ' '` #remove spaces rm .tempama rm .tempam rm .tempf case $keep in TRUE) ;; FALSE) rm $HOME/.vk-cookie.txt;; esac case $SO in 0) wget --spider $addr >>/dev/null if [ $? -ne 0 ]; then rm "$tname.$tres.mov" for ((i=0; i <= 3 ; i++)) do if [ $i -ne 0 ];then let "j = $i - 1" else j=0; fi if [ ${res[$i]} -le $tres ]; then addr=`echo $addr | sed -es/"${res[$j]}"/"${res[$i]}"/` if [ ${res[$i]} -ne $tres ];then wget --spider $addr >>/dev/null if [ $? -eq 0 ]; then RtD=2 tres=${res[$i]} i=10 fi fi fi done else RtD=1 fi rand="$RANDOM `date`" pipe="/tmp/pipe.`echo '$rand' | md5sum | tr -d ' -'`" mkfifo $pipe tdown=0 tnamesp=`echo "$tname" |tr -d '|'| tr ' ' '_'` wget -c $addr -O "$tfolder/$tnamesp.$tres.mov" 2>&1 | while read data; do if [ "`echo $data | grep '^Length:'`" ]; then total_size=`echo $data | grep "^Length:" | sed 's/.*\((.*)\).*/\1/' | tr -d '()'` fi if [ "`echo $data | grep '[0-9]*%' `" ];then percent=`echo $data | grep -o "[0-9]*%" | tr -d '%'` current=`echo $data | grep "[0-9]*%" | sed 's/\([0-9BKMG.]\+\).*/\1/' ` echo $percent echo "#Name: $tnamesp \nVideo size: $tres \nFrom: $1\n$current of $total_size ($percent%)\n" fi if [ "$current" != "$total_size" ];then tdown=fail fi done > $pipe & wget_info=`ps ax |grep "wget.*$addr" |awk '{print $1"|"$2}'` wget_pid=`echo $wget_info|cut -d'|' -f1 ` zenity --progress --auto-close --text="Connecting to $addr\n\n\n" --width="350" --title="Downloading"< $pipe if [ "`ps -A |grep "$wget_pid"`" ];then kill $wget_pid rm $tnamesp.$tres.mov tdown=fail fi rm -f $pipe if [ "$tdown" != "fail" ] then case $RtD in 2) echo "Resolution change. File "$tnamesp"."$tres".mov successfully saved" yad --center --text-align=center --height=25 --title="File Saved" --no-buttons --timeout=8 --text="Resolution change. File $tnamesp.$tres.mov successfully saved";; 1) yad --center --text-align=center --height=25 --title="File Saved" --no-buttons --timeout=8 --text="File $tnamesp.$tres.mov successfully saved" echo "File "$tnamesp"."$tres".mov successfully saved";; esac else yad --center --text-align=center --height=25 --title="ERROR" --no-buttons --timeout=8 --text="File $tname.$tres.mov has NOT been saved" fi;; 2) wget --spider $addr >>/dev/null # checking if [ $? -ne 0 ]; then for ((i=0; i <= 3 ; i++)) do if [ $i -ne 0 ];then let "j = $i - 1" else j=0; fi if [ ${res[$i]} -le $tres ]; then addr=`echo $addr | sed -es/"${res[$j]}"/"${res[$i]}"/` if [ ${res[$i]} -ne $tres ];then wget --spider $addr >>/dev/null # checking if [ $? -eq 0 ]; then i=10; fi fi fi done fi echo "Playing file" echo "$tname" #vlc --started-from-file --playlist-enqueu "$addr" & smplayer -minigui -add-to-playlist $addr & sleep 5 echo "File is playing";; esac exit
rand="$RANDOM `date`" pipe="/tmp/pipe.`echo '$rand' | md5sum | tr -d ' -'`" mkfifo $pipe wget -c $addr -O "$tfolder/$tname.$tres.mov" 2>&1 | while read data; do if [ "`echo $data | grep '^Length:'`" ]; then total_size=`echo $data | grep "^Length:" | sed 's/.*\((.*)\).*/\1/' | tr -d '()'` fi if [ "`echo $data | grep '[0-9]*%' `" ];then percent=`echo $data | grep -o "[0-9]*%" | tr -d '%'` current=`echo $data | grep "[0-9]*%" | sed 's/\([0-9BKMG.]\+\).*/\1/' ` echo $percent echo "#Name: $tname \nVideo size: $tres \nFrom: $1\n$current of $total_size ($percent%)\n" fi if [ "$current" != "$total_size" ];then tdown=fail fi done > $pipe & wget_info=`ps ax |grep "wget.*$addr" |awk '{print $1"|"$2}'` wget_pid=`echo $wget_info|cut -d'|' -f1 ` zenity --progress --auto-close --text="Connecting to $addr\n\n\n" --width="350" --title="Downloading"< $pipe
Source: https://habr.com/ru/post/138932/
All Articles