Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- browser="/usr/bin/firefox -new-tab"
- viewer="/usr/bin/youtube-viewer"
- args="--non-interactive --really-quiet -id"
- youtube=(
- "http://www.youtube.com.tw/watch?v="
- "http://www.youtube.com/watch?v="
- "http://youtu.be/"
- )
- url=$1
- percent=( 10 12 15 17 20 23 28 33 41 50 61 78 100 )
- function fadeout(){
- #Specify gap time by assign decimal to gap in seconds
- #You may use expenential fade. Comment the linear one and uncomment the exponential one
- gap=1.6 #gap time
- for((i=0; i < $((${#percent[@]} - 1)); i++)); do
- mpc -q volume $(( $1 - ($1/(${#percent[@]} - 1)) * ( $i + 1 ) ))
- sleep $(echo "scale=4; $gap / (${#percent[@]} - 1)" | bc) #linear
- #sleep $(echo "scale=4; $gap * $((${percent[$((i+1))]}-${percent[$i]})) /100" | bc) #exponential
- done
- mpc -q volume 0
- }
- function fadein(){
- gap=1.6 #gap time
- for((i=$((${#percent[@]} - 1)); i > 0; i--)); do
- mpc -q volume $(( $1 - ($1/(${#percent[@]} - 1)) * $i ))
- sleep $(echo "scale=4; $gap / (${#percent[@]} - 1)" | bc) #linear
- #sleep $(echo "scale=4; $gap * $((${percent[$i]}-${percent[$(($i-1))]})) /100" | bc) #exponential
- done
- mpc -q volume $1
- }
- for((i=0; i < ${#youtube[@]}; i++)); do
- if [[ ${url} == ${youtube[i]}* ]]; then
- id=${url#${youtube[i]}}
- id=${id:0:11}
- if [[ ${#id} = 11 ]]; then
- vol=$(mpc | tail -1 | cut -d "%" -f 1 | cut -d ":" -f 2)
- fadeout ${vol} #comment this line to disable fadeout
- ${viewer} ${args} ${id}
- fadein ${vol} #comment this line to disable fadein
- break
- fi
- fi
- done
- if [[ $i = ${#youtube[@]} ]]; then
- ${browser} $1
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement