Advertisement
Guest User

Untitled

a guest
Sep 1st, 2012
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.60 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. browser="/usr/bin/firefox -new-tab"
  4. viewer="/usr/bin/youtube-viewer"
  5. args="--non-interactive --really-quiet -id"
  6. youtube=(
  7.     "http://www.youtube.com.tw/watch?v="
  8.     "http://www.youtube.com/watch?v="
  9.     "http://youtu.be/"
  10. )
  11. url=$1
  12. percent=( 10 12 15 17 20 23 28 33 41 50 61 78 100 )
  13.  
  14. function fadeout(){
  15.     #Specify gap time by assign decimal to gap in seconds
  16.     #You may use expenential fade. Comment the linear one and uncomment the exponential one
  17.     gap=1.6     #gap time
  18.     for((i=0; i < $((${#percent[@]} - 1)); i++)); do
  19.         mpc -q volume $(( $1 - ($1/(${#percent[@]} - 1)) * ( $i + 1 ) ))
  20.         sleep $(echo "scale=4; $gap / (${#percent[@]} - 1)" | bc)       #linear
  21.                 #sleep $(echo "scale=4; $gap * $((${percent[$((i+1))]}-${percent[$i]})) /100" | bc) #exponential
  22.     done
  23.     mpc -q volume 0
  24. }
  25.  
  26. function fadein(){
  27.     gap=1.6     #gap time
  28.     for((i=$((${#percent[@]} - 1)); i > 0; i--)); do
  29.         mpc -q volume $(( $1 - ($1/(${#percent[@]} - 1)) * $i ))
  30.         sleep $(echo "scale=4; $gap / (${#percent[@]} - 1)" | bc)       #linear
  31.         #sleep $(echo "scale=4; $gap * $((${percent[$i]}-${percent[$(($i-1))]})) /100" | bc)    #exponential
  32.     done
  33.     mpc -q volume $1
  34. }
  35.  
  36.  
  37.  
  38. for((i=0; i < ${#youtube[@]}; i++)); do
  39.     if [[ ${url} == ${youtube[i]}* ]]; then
  40.         id=${url#${youtube[i]}}
  41.         id=${id:0:11}
  42.         if [[ ${#id} = 11 ]]; then
  43.             vol=$(mpc | tail -1 | cut -d "%" -f 1 | cut -d ":" -f 2)
  44.             fadeout ${vol}      #comment this line to disable fadeout
  45.             ${viewer} ${args} ${id}
  46.             fadein ${vol}       #comment this line to disable fadein
  47.             break
  48.         fi          
  49.     fi
  50. done
  51.  
  52. if [[ $i = ${#youtube[@]} ]]; then
  53.     ${browser} $1
  54. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement