Difference between revisions of "XBMC remote control script for streams"

From Hackerspace ACKspace
Jump to: navigation, search
(added OpenELEC XBMC remote control script)
 
(updated script: added language and quality)
Line 8: Line 8:
 
4. Room G
 
4. Room G
 
6. Room six
 
6. Room six
q. quit
+
x. exit
n. Native
+
l. Language
t. Translated
+
q. Quality
Input(native): _</pre>
+
Input(n:hq): _</pre>
  
 
=== code ===
 
=== code ===
 
It's a bash script and uses pproximately 20x10 characters so you can place it next to your stream schedule
 
It's a bash script and uses pproximately 20x10 characters so you can place it next to your stream schedule
 
<pre>
 
<pre>
 +
#!/bin/bash
 
#!/bin/bash
 
#!/bin/bash
 
# IP address of Raspbian/OPENELEC/XBMC box
 
# IP address of Raspbian/OPENELEC/XBMC box
 
IP=192.168.2.11
 
IP=192.168.2.11
 
# Base stream url where [KEY] and [LANG] are replaced
 
# Base stream url where [KEY] and [LANG] are replaced
STREAM=rtmp://rtmp.streaming.media.ccc.de:1935/stream/saal[KEY]_[LANG]_hq
+
STREAM=rtmp://rtmp.streaming.media.ccc.de:1935/stream/saal[KEY]_[LANG]_[QUALITY]
 
LANG=native
 
LANG=native
 +
MENU_LANG=n
 +
QUALITY=hq
 +
MENU_QUALITY=hq
 +
# ld hq hd
 
###############
 
###############
 
if [[ $* == -h || $* == -? || $* == --help ]]; then
 
if [[ $* == -h || $* == -? || $* == --help ]]; then
Line 28: Line 33:
 
fi
 
fi
 
# print menu and save cursor (menu including input is 20x10 chars)
 
# print menu and save cursor (menu including input is 20x10 chars)
echo -en "CCC OPENELEC remote\n\n1. Room one\n2. Room two\n4. Room G\n6. Room six\nq. quit\nn. Native\nt. Translated\n\0337"
+
echo -en "CCC OPENELEC remote\n\n1. Room one\n2. Room two\n4. Room G\n6. Room six\nx. exit\nl. Language\nq. Quality\n\0337"
while [[ $key != "q" ]]; do
+
while [[ $KEY != "x" ]]; do
 
     echo -en "\0338" # restore cursor
 
     echo -en "\0338" # restore cursor
 
     # Clear line and print previous entry
 
     # Clear line and print previous entry
     echo -en "\033[KInput($LANG): $key"
+
     echo -en "\033[KInput($MENU_LANG:$MENU_QUALITY): $KEY"
     read -n1 -s key
+
     read -n1 -s KEY
     case $key in
+
     case $KEY in
 
         1|2|g|6)
 
         1|2|g|6)
             RESULT=${STREAM//'[KEY]'/$key}
+
             RESULT=${STREAM//'[KEY]'/$KEY}
 
             RESULT=${RESULT//'[LANG]'/$LANG}
 
             RESULT=${RESULT//'[LANG]'/$LANG}
 +
            RESULT=${RESULT//'[QUALITY]'/$QUALITY}
 
             wget -q "http://${IP}/jsonrpc?request={%22jsonrpc%22:%222.0%22,%22method%22:%22Player.Open%22,%22params%22:{%22item%22:{%22file%22:%22${RESULT}%22}}}" -O /dev/null;;
 
             wget -q "http://${IP}/jsonrpc?request={%22jsonrpc%22:%222.0%22,%22method%22:%22Player.Open%22,%22params%22:{%22item%22:{%22file%22:%22${RESULT}%22}}}" -O /dev/null;;
  
         n|N)
+
         l|L)
             LANG=native;;
+
             if [[ $MENU_LANG == n ]]; then
 +
                LANG=translated;MENU_LANG=t
 +
            else
 +
                LANG=native;MENU_LANG=n
 +
            fi;;
 +
 
 +
        q|Q)
 +
            if [[ $MENU_QUALITY == hd ]]; then
 +
                QUALITY=lq;MENU_QUALITY=lq
 +
            elif [[ $MENU_QUALITY == lq ]]; then
 +
                QUALITY=hq;MENU_QUALITY=hq
 +
            else
 +
                QUALITY=hd;MENU_QUALITY=hd
 +
            fi;;
 +
 
 +
        x|X)
 +
            break;;
 +
 
 +
        *)
 +
            KEY=;;
  
        t|T)
 
            LANG=translated;;
 
 
     esac
 
     esac
 
done
 
done
 
echo -en "\0338\033[9A\033[J" # Clean up 9 lines
 
echo -en "\0338\033[9A\033[J" # Clean up 9 lines
 
</pre>
 
</pre>

Revision as of 19:59, 29 December 2013

synopsis

Xopr needed a quick way of 'zapping' through the streams of the 30C3 congress (also see no nerd left behind), so he wrote a remote control for his OpenELEC (XBMC, but it might work on RaspBMC as well) to open a predefined stream with one keypress from within a console:

CCC OPENELEC remote

1. Room one
2. Room two
4. Room G
6. Room six
x. exit
l. Language
q. Quality
Input(n:hq): _

code

It's a bash script and uses pproximately 20x10 characters so you can place it next to your stream schedule

#!/bin/bash
#!/bin/bash
# IP address of Raspbian/OPENELEC/XBMC box
IP=192.168.2.11
# Base stream url where [KEY] and [LANG] are replaced
STREAM=rtmp://rtmp.streaming.media.ccc.de:1935/stream/saal[KEY]_[LANG]_[QUALITY]
LANG=native
MENU_LANG=n
QUALITY=hq
MENU_QUALITY=hq
# ld hq hd
###############
if [[ $* == -h || $* == -? || $* == --help ]]; then
    echo -e "\tusage: $0\n\n\twill trigger openelec links for ccc\n"
    exit 0
fi
# print menu and save cursor (menu including input is 20x10 chars)
echo -en "CCC OPENELEC remote\n\n1. Room one\n2. Room two\n4. Room G\n6. Room six\nx. exit\nl. Language\nq. Quality\n\0337"
while [[ $KEY != "x" ]]; do
    echo -en "\0338" # restore cursor
    # Clear line and print previous entry
    echo -en "\033[KInput($MENU_LANG:$MENU_QUALITY): $KEY"
    read -n1 -s KEY
    case $KEY in
        1|2|g|6)
            RESULT=${STREAM//'[KEY]'/$KEY}
            RESULT=${RESULT//'[LANG]'/$LANG}
            RESULT=${RESULT//'[QUALITY]'/$QUALITY}
            wget -q "http://${IP}/jsonrpc?request={%22jsonrpc%22:%222.0%22,%22method%22:%22Player.Open%22,%22params%22:{%22item%22:{%22file%22:%22${RESULT}%22}}}" -O /dev/null;;

        l|L)
            if [[ $MENU_LANG == n ]]; then
                LANG=translated;MENU_LANG=t
            else
                LANG=native;MENU_LANG=n
            fi;;

        q|Q)
            if [[ $MENU_QUALITY == hd ]]; then
                QUALITY=lq;MENU_QUALITY=lq
            elif [[ $MENU_QUALITY == lq ]]; then
                QUALITY=hq;MENU_QUALITY=hq
            else
                QUALITY=hd;MENU_QUALITY=hd
            fi;;

        x|X)
            break;;

        *)
            KEY=;;

    esac
done
echo -en "\0338\033[9A\033[J" # Clean up 9 lines