Lazza

ismdownloader2 Bash Smooth Streaming Wrapper

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