JPeterson

justin.tv player

Aug 3rd, 2012
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.36 KB | None | 0 0
  1. #!/bin/bash
  2. # justin.tv player
  3. # (C) John Peterson, license GNU GPL 3
  4. if [ -z "$1" ]; then echo -e "Usage: jtv.sh channel [stream]"; exit 0; fi;
  5. channel=$1
  6. stream=$2
  7. player=$(curl -v "http://www-cdn.justin.tv/widgets/live_site_player.swf" 2>&1|grep Location:|cut -d" " -f3|cut -d\? -f1)
  8. xml=$(curl -s "http://usher.justin.tv/find/${channel}.xml?type=any")
  9. if [ "$xml" = "<nodes></nodes>" ]; then echo "${channel} is offline"; exit 1; fi;
  10. # stream node name form error
  11. xml=$(echo $xml|sed 's/<\([0-9]\)/<_\1/g'); xml=$(echo $xml|sed 's/<\/\([0-9]\)/<\/_\1/g');
  12. # stream selection
  13. if [ -n "${stream}" ] && [ -n "`echo $xml|xmllint --xpath "//${stream}/token" -`" ] ; then path="${stream}";
  14. else path="*[not(video_height < //*[token]/video_height) and token][1]"; fi;
  15. # print streams
  16. y=`echo $xml|xmllint --xpath "name($path)" -`
  17. for ((i=1;i<=$(echo $xml|xmllint --xpath "count(*[token])" -);i++)); do
  18.     x=$(echo $xml|xmllint --xpath "name(*[token][$i])" -)
  19.     if [ "$x" = "$y" ]; then echo -n "*"; fi;
  20.     echo "$x"
  21. done
  22. echo "";
  23. token=$(echo $xml|xmllint --xpath "${path}/token/text()" -)
  24. connect=$(echo $xml|xmllint --xpath "${path}/connect/text()" -)
  25. play=$(echo $xml|xmllint --xpath "${path}/play/text()" -)
  26. rtmpdump -vr"${connect}/${play}" -j"${token}" -W"${player}" -m5 -o-|{
  27. while read -rt 5 line; do
  28.     echo $line
  29. done
  30. echo "EOF or no writing for 5 seconds">&2
  31. }|vlc -
Advertisement
Add Comment
Please, Sign In to add comment