flash2xbmc: Send a flash video from your browser to xbmc

Some time ago I posted how to send a video to xbmc from your terminal. This script already makes live a little bit more comfortable. I didn’t mention that this script was just a part of another script, which wasn’t useable at that time: Today I present a script which allows you to “send” a flash video from your browser to xbmc.

First of all the reason why I wanted to have this script: Browsing is very convenient using a laptop but for watching (longer) videos I prefer using the bigger screen of my media center. Another advantage of the bigger screen is that you can show videos to other people more easily. So what I needed is an interface between browser and media center. There is one for youtube, but I didn’t find a generic tool.

The best solution would be a browser add-on which provides a button like the youtube plugin saying “send to xbmc”. But since I haven’t done any add-on development yet and since I wasn’t sure if it was even possible to do something like this, I wrote a shell script, which provides a good start. I really hope that there is someone which will write a browser (=firefox) plugin which does the same job, but doesn’t require the user to use a terminal.

Before I show you the code, some remarks, requirements and a short explanation how it works:

  • You need a light-weight web server like twistd to serve the files
  • You have to configure your xbmc, that it allows external access via jsonrpc
  • I do not know if this works with another browser than firefox
  • After execution the script, it tells you, that you have to kill the webserver yourself. Currently I do not ask xbmc if the videos have been played and the server can be closed. So be careful, that you do not carry around a running web server.
  • To “send” the files to xbmc the script does the following: It locates the position of the video files and puts a link into a predefined shared folder. A playlist collects all the files, so you can even play several videos. Finally it starts a tiny webserver and announces the address to xbmc via jsonprc.
# Directory which will provide the files
SHARE=~/.flash2xbmc # attention, no quotes since mkdir wont expand ~ in this case.
# How are the files served, i.e. which kind of http sever should be started.
SERVE="/usr/bin/twistd -n web --path=__SHARE__"
# Where will the xbmc server find the files
# Name the list of flash files
# Get the pid of the flash player (firefox only?)
FLASHPID=`ps -A | grep plugin-con | sed 's/^ *//g' | cut -d" " -f 1`
# Get all files
FILES=`ls -l ${FDPATH} | grep "Flash" | cut -d" " -f 9`
# Create directory for sharing
[ -d ${SHARE} ] || mkdir ${SHARE}
# Link all files to the sharing directory and add them to the play list
for f in ${FILES}
ln -sf ${FDPATH}/${f} ${SHARE}/${f} 
echo ${LOCALHOST}${f} >> ${SHARE}/${PLAYLIST}

#start the share command
`${SERVE//"__SHARE__"/${SHARE}}` &
#get PID

# TODO: How to shut down the server after the play back is done?
echo "Server is running with PID $SERVEPID. You have to kill the server by hand after streaming the videos.";

# Serve the file to your XBMC host
curl --data-binary '{ "jsonrpc": "2.0", "method": "Player.Open", "params": { "item": { "file": "'${LOCALHOST}${PLAYLIST}'" } }, "id": 1 }' "${XBMCHOST}/jsonrpc"

Leave a Comment

Your email address will not be published. Required fields are marked *