XBMC KDE Service Menu
#1
Here is my first attempt at a KDE service menu for XBMC - its still a bit rough but cool nonetheless. It will either play or queue files or folders via a right click in Dolphin using json-rpc. If XBMC is not running it will open it, if it is running it will bring it to focus. It needs wmctrl installed (to bring XBMC to focus).

To install unzip the files into the ~/.kde/share/kde4/services/ServiceMenus/ directory and make xbmc-kde-send-to.sh executable. If you use a non standard port for json-rpc (not 8080) or want to send files to a networked PC you need to edit xbmc-kde-send-to.sh. Then right click away!

Issues/todo:
Opening picture folders with any files that are not images causes none of the pictures to display (music folders are ok though).
Adding 'queue and start playing' entry? XBMC controls?
Playing/queueing multiple selected files at once is a bit funky.
Network items - dolphin hides the service menu when browsing network shares.
Script could probably be used to associate content with xbmc, so double clicking media would open it in xbmc - DONE

https://dl.dropboxusercontent.com/u/2241...-0.0.2.zip
Reply
#2
This is great, thx. I'm trying to modify your script so that it just sends to a remote host instead (see below). Any tips getting this to work?


Code:
#!/bin/bash
#script to send content to xbmc via dolphin/kde desktop

IP=10.1.0.144
PORT=8080   #xbmc default
ID=$2


function xbmc_req {
  curl -s -i -X POST --header "Content-Type: application/json" -d "$1" http://$IP:$PORT/jsonrpc >/dev/null
}

if [[ $1 = play ]] ; then
xbmc_req '{"jsonrpc": "2.0", "method": "Playlist.Clear", "params":{"playlistid":1}, "id": 1}';
xbmc_req '{"jsonrpc": "2.0", "method": "Playlist.Add", "params":{"playlistid":1, "item" :{ "file" : "'$ID'"}}, "id" : 1}';
xbmc_req '{"jsonrpc": "2.0", "method": "Player.Open", "params":{"item":{"playlistid":1, "position" : 0}}, "id": 1}';

elif [[ $1 = playdir ]] ; then
xbmc_req '{"jsonrpc": "2.0", "method": "Playlist.Clear", "params":{"playlistid":1}, "id": 1}';
xbmc_req '{"jsonrpc": "2.0", "method": "Playlist.Add", "params":{"playlistid":1, "item" :{ "directory" : "'$ID'"}}, "id" : 1}';
xbmc_req '{"jsonrpc": "2.0", "method": "Player.Open", "params":{"item":{"playlistid":1, "position" : 0}}, "id": 1}';

elif [[ $1 = queue ]] ; then
xbmc_req '{"jsonrpc": "2.0", "method": "Playlist.Add", "params":{"playlistid":1, "item" :{ "file" : "'$ID'"}}, "id" : 1}';

elif [[ $1 = queuedir ]] ; then
xbmc_req '{"jsonrpc": "2.0", "method": "Playlist.Add", "params":{"playlistid":1, "item" :{ "directory" : "'$ID'"}}, "id" : 1}';

fi
Reply
#3
why would you need a port scanner to detect if xbmc is up? just post your json request and check curls return code. Or do a netstat -anlp or whatever.
Reply
#4
Ok, I got it to work. Been wishing I had a feature like this for so long. I can right click on a file in Dolphin and send it to my raspberry pi running raspbmc.

In case anyone else cares to use this, this is setup for using FTP, and you'll need to edit the $FILE and $FTP_FILE variables accordingly.

Code:
#!/bin/bash
#script to send content to xbmc via dolphin/kde desktop

IP=10.1.0.144 #xbmc
PORT=8080   #xbmc default
ID=$2

FTP_IP=10.1.0.5:21
USER=xbmc
PASS=xxx

FILE=$( echo "$ID" | cut -d/ -f 6-99 )
FTP_FILE=ftp://$USER:$PASS@$FTP_IP/Downloads/$FILE

function xbmc_req {
  curl -s -i -X POST --header "Content-Type: application/json" -d "$1" http://$IP:$PORT/jsonrpc >/dev/null
}

if [[ $1 = play ]] ; then
xbmc_req '{"jsonrpc": "2.0", "method": "Playlist.Clear", "params":{"playlistid":1}, "id": 1}';
xbmc_req '{"jsonrpc": "2.0", "method": "Playlist.Add", "params":{"playlistid":1, "item" :{ "file" : "'"$FTP_FILE"'"}}, "id" : 1}';
xbmc_req '{"jsonrpc": "2.0", "method": "Player.Open", "params":{"item":{"playlistid":1, "position" : 0}}, "id": 1}';

elif [[ $1 = playdir ]] ; then
xbmc_req '{"jsonrpc": "2.0", "method": "Playlist.Clear", "params":{"playlistid":1}, "id": 1}';
xbmc_req '{"jsonrpc": "2.0", "method": "Playlist.Add", "params":{"playlistid":1, "item" :{ "directory" : "'$FTP_FILE'"}}, "id" : 1}';
xbmc_req '{"jsonrpc": "2.0", "method": "Player.Open", "params":{"item":{"playlistid":1, "position" : 0}}, "id": 1}';

elif [[ $1 = queue ]] ; then
xbmc_req '{"jsonrpc": "2.0", "method": "Playlist.Add", "params":{"playlistid":1, "item" :{ "file" : "'$FTP_FILE'"}}, "id" : 1}';

elif [[ $1 = queuedir ]] ; then
xbmc_req '{"jsonrpc": "2.0", "method": "Playlist.Add", "params":{"playlistid":1, "item" :{ "directory" : "'$FTP_FILE'"}}, "id" : 1}';

fi
Reply
#5
@slo_rider thnks for sharing, using a function cleans it up a bit.

@wsnipex yeah true, Ive changed to pinging json-rpc. I just used that because I had it from before and knew it worked.
Reply
#6
New version in first post:

Removes need for nmap and uses json-rpc ping instead.
Cleans up script file using functions, as in slo_riders version.
Added open argument - this is to use the script to double click to open files (I'll start a thread for this because it should work on DE's other that KDE)
Reply
#7
Has this ever been updated?

I see a few enhancements that it deserves.

First, hardware to run kodi is cheap. Get a raspberry pi 2 and boom you are good to go. Setting this up to run on the same machine defeats its' own purpose. What I mean is that why not just open Kodi on the other computer and play the content. It can't be that many more steps.

What I think should happen with this product if it were to progress further is that there's a service for KDE that allows you to right click on a song or video and have that information sent to Kodi. As Kodi is mostly a dedicated system (it is up all the time and not windowed) it makes sense to not be put in a position where the kodi program has to be running on the same device.

Second, it doesn't really need all the checks to determine if Kodi is running or to bring it forward so the script can be simplified, as well as the dependencies. The API that allows apps like Yatse to work could be leveraged to give it all that is needed to be fully functional.

Finally, this is a nice idea it's just that it doesn't appear to have been maintained and it doesn't appear to have been enhanced to provide this type of functionality.

I'd love to be going through my list of music and videos, see a video, and right click in dolphin and have that then give me a choice to play it on the media center running on my other computer.
Reply
#8
To send it to a remote instance of kodi just change the IP/port that the curl command in the script sends to. For this scenario the wmctrl/json ping sections are redundant and can be removed.
Reply
#9
(2015-05-13, 01:12)Jimbo99 Wrote: I'd love to be going through my list of music and videos, see a video, and right click in dolphin and have that then give me a choice to play it on the media center running on my other computer.

That's exactly what my script does. I've made two different service menus in Dolphin, one for each of my instances of Kodi I have running in other rooms. I can right click a file and play or queue it. I'm not a coder and my script is not perfect, so it would need some modifications to the cut line when deriving the file path if others were to use it. It has to translate the local absolute path to one that's accessible by the ftp user.
Reply

Logout Mark Read Team Forum Stats Members Help
XBMC KDE Service Menu0