Lazza

ismdownloader2 Bash Smooth Streaming Wrapper

Jul 25th, 2012
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.12 KB | None | 0 0
  1. #!/bin/bash
  2. # Author: Andrea Lazzarotto
  3. # http://andrealazzarotto.com
  4.  
  5. # Smooth Streaming Bash Wrapper
  6. # This is a wrapper for the ismdownloader2 Windows executable under Wine.
  7.  
  8. # License:
  9. # Copyright 2012 Andrea Lazzarotto
  10. # This script is licensed under the Gnu General Public License v3.0.
  11. # You can obtain a copy of this license here: http://www.gnu.org/licenses/gpl.html
  12.  
  13. export WINEPREFIX=$HOME/.smoothwine
  14.  
  15. URL="$1"
  16. NAME="$2"
  17.  
  18. if [ $# -ne 2 ]
  19. then
  20.   echo "Usage: `basename $0` url filename"
  21.   exit 1
  22. fi
  23.  
  24. function percentage {
  25.     n=50
  26.     p=$1
  27.  
  28.     echo -n '['
  29.     while [ $n -gt 0 ]; do
  30.         if [ $p -gt 0 ];
  31.             then
  32.                 echo -n '#'
  33.                 p=$(( $p - 2 ))
  34.             else echo -n '-'
  35.         fi
  36.         n=$(( $n - 1 ))
  37.     done
  38.     echo -n ']'
  39.     echo -n " ${1}%"
  40. }
  41.  
  42. dur="u"
  43.  
  44. echo "Verrà scaricato il video dall'url $URL"
  45. echo ""
  46. echo "Caricamento in corso..."
  47. echo ""
  48.  
  49. wine $WINEPREFIX/drive_c/ismdownloader.exe "$URL" "C:\\$NAME.mkv" 2>/dev/null | while read -r -d '.' line; do
  50.     line=`echo $line | tr '\r' ' '`
  51.  
  52.     if [ $dur = "u" ]; then # deve leggere la durata
  53.         line=`echo $line | sed -s "s/.*Dur/Dur/g"`
  54.         line1=`echo $line | cut -d ' ' -f 1`
  55.         line2=`echo $line | cut -d ' ' -f 2`
  56.         if [ $line1 = "Duration:" ]; then
  57.             dur="$line2"
  58.             h=`echo $dur | cut -d ':' -f 1`
  59.             m=`echo $dur | cut -d ':' -f 2`
  60.             s=`echo $dur | cut -d ':' -f 3`
  61.             time=`echo "(($h * 60) + $m) * 60 + $s" | bc`
  62.  
  63.             echo -e "Durata del video: $dur\n"
  64.         fi
  65.     else # stampa la percentuale ogni volta che può
  66.         line=`echo $line | cut -d ' ' -f 2`
  67.         case $line in
  68.             (*:*:*)
  69.                 par="$line"
  70.                 h=`echo $par | cut -d ':' -f 1`
  71.                 m=`echo $par | cut -d ':' -f 2`
  72.                 s=`echo $par | cut -d ':' -f 3`
  73.                 part=`echo "(($h * 60) + $m) * 60 + $s" | bc`
  74.                 perc=`echo "($part * 100) / $time" | bc`
  75.  
  76.                 echo -e -n "\r"
  77.                 echo -n "$par "
  78.                 percentage $perc
  79.                 echo -n ' '
  80.             ;;
  81.         esac
  82.     fi
  83. done # ha finito di leggere l'output
  84.  
  85. echo -e "\n"
  86. echo "Pulizia in corso..."
  87. rm -rf "$WINEPREFIX/drive_c/$NAME"
  88. mv "$WINEPREFIX/drive_c/$NAME.mkv" .
  89. echo ""
  90. echo "Download terminato, il video si trova in `pwd`/$NAME.mkv"
Add Comment
Please, Sign In to add comment