2009-03-11, 07:41
i wrote the external linux bash script to control xbmc using command line interface but currently i'm not happy with it since it uses xbmc httpApi (which needs the xbmc web server running). I cannot find other xbmc Api that can be run externally (not within xbmc) to interface with my script.
Is there anyway I can use the xbmc python 'import xbmc' in my external script?
i'm sharing my bash script here;
thanx!
Is there anyway I can use the xbmc python 'import xbmc' in my external script?
i'm sharing my bash script here;
Code:
#!/bin/bash
#===============================================================================
#
# FILE: xbmccmd
#
# USAGE: ./xbmccmd "HttpApi command/parameter"
#
# DESCRIPTION: XBMC CLI using bash /dev/tcp sockets
#
# OPTIONS: ---
# REQUIREMENTS: BASH with /dev/tcp enables
# BUGS: ---
# NOTES: ---
# AUTHOR: Khairil Anuar Abdul Hamid (Khairil), [email protected]
# COMPANY: Global Operation Supplies and Engineering Sdn. Bhd.
# VERSION: 1.0
# CREATED: 03/08/2009 01:33:45 PM MYT
# REVISION: ---
#===============================================================================
set -o pipefail
### Configuration
#
HOST="localhost"
PORT=8080
CMD_PATH="/xbmcCmds/xbmcHttp?command="
#
CMD=${1}
PATH=${CMD_PATH}${CMD}
#PATH=${PATH-/}
exec 6<>/dev/tcp/${HOST}/${PORT} 2>/dev/null
ret=$?
if [ $ret -ne 0 ]; then
echo "$? : Cannot connect to ${HOST}:${PORT}"
exit
fi
echo -e "GET ${PATH} HTTP/1.1" >&6
echo -e "Host: ${HOST}\nConnection: close\n" >&6
#read and discard the header
while read <&6
do
LINE=${REPLY//$'\r'/}
if [ -z "$LINE" ]; then
break
fi
done
#read the page
while read <&6
do
echo -n $REPLY >&1
done
# close the file descriptor
exec 6<&-
exec 6>&-
echo
thanx!