Advertisement
deckoff

Sopcast

Sep 20th, 2012
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.13 KB | None | 0 0
  1. #!/bin/sh
  2. # Start streaming sopcast address $1 with sp-sc-auth, then start VLC and monitor both processes.
  3. # Author: Chickamade <anh.chick@gmail.com>
  4.  
  5. if ! test $# -eq 1
  6. then
  7.     echo 'Usage: sopcast <sop://address>'
  8.     exit 0
  9. fi
  10.  
  11. if pgrep -f "sp-sc-auth $1"
  12. then
  13.     echo sopcast: channel $1 already streaming, quitting >&2
  14.     exit 0
  15. fi
  16.  
  17. PORT=${1##*/}
  18.  
  19. while [ $PORT -gt 60000 ]; do
  20.     PORT=$((PORT-10000))
  21.     # echo $PORT
  22. done
  23.  
  24.  
  25. echo sopcast: starting stream $1 on port $PORT >&2
  26. sp-sc-auth "$1" 3908 $PORT >/dev/null &
  27. SP_SC=`pgrep -f "sp-sc-auth $1 3908 $PORT"`
  28. if test -z $SP_SC
  29. then
  30.     echo sopcast: stream $1 failed to start >&2
  31.     exit 1
  32. fi
  33.  
  34. sleep 3
  35.  
  36. vlc http://localhost:$PORT/tv.asf >/dev/null 2>&1 &
  37. VLC=`pgrep -f "vlc http://localhost:$PORT/tv.asf"`
  38. if test -z $VLC
  39. then
  40.     echo sopcast: VLC failed to start >&2
  41.     kill -9 $SP_SC
  42.     exit 1
  43. fi
  44.  
  45. while true
  46. do
  47.     if ! ps $SP_SC > /dev/null
  48.     then
  49.         echo sopcast: stream $1 died, killing VLC >&2
  50.         kill $VLC
  51.         exit 1
  52.     fi
  53.     if ! ps $VLC > /dev/null
  54.     then
  55.         echo sopcast: VLC not running, killing stream $1 >&2
  56.         kill -9 $SP_SC
  57.         exit 0
  58.     fi
  59.     sleep 10
  60. done
  61. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement