Support for XBMC2 plugin (formerly XBMCRepeat)

Questions and comments specific to a particular plugin should go here.
jonib
Plugin Developer
Posts: 1298
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Re: XBMCRepeat XBMC plugin based on the official plugin

Post by jonib » Sun Oct 10, 2010 6:03 pm

badubo wrote:I find your pluggin really useful.
:D
I tested some JSOn commands and it works pretty well. But I have a question, how can we use the result (return) of the commands?
Oops :oops: , I was supposed to post some examples how to use the results.

So for example with Player.GetActivePlayer you get this in the log: which is the json fomated output

Code: Select all

Result:
{
  "audio": false, 
  "picture": false, 
  "video": true
}
And if you use the normal way to show a result ({eg.result}) in for example ShowOSD you get this: which is of Python Dict format

Code: Select all

{u'picture': False, u'audio': False, u'video': True}
So if you want to get the video player status use {eg.result['video']}

I'll post some other examples later(hopefully I remember :| ). Just ask if you need more.

jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image

supertusse
Posts: 8
Joined: Sat Nov 20, 2010 10:12 am

Re: XBMCRepeat XBMC plugin based on the official plugin

Post by supertusse » Sat Nov 20, 2010 10:16 am

Hello!

Been playing with the new beta. Seems it isn't too Windows 7 friendly:

Traceback (most recent call last):
File "C:\Program Files (x86)\EventGhost\plugins\XBMCRepeat\__init__.py", line 686, in OnUpdate
UpdateCommands()
File "C:\Program Files (x86)\EventGhost\plugins\XBMCRepeat\__init__.py", line 745, in UpdateCommands
with open(os.path.join(os.path.abspath(os.path.split(__file__)[0]), 'httpapi.dat'), 'wb') as f:
IOError: [Errno 13] Permission denied: 'C:\\Program Files (x86)\\EventGhost\\plugins\\XBMCRepeat\\httpapi.dat'

I suppose you should store the dats in the application data folder instead?

-Tusse

jonib
Plugin Developer
Posts: 1298
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Re: XBMCRepeat XBMC plugin based on the official plugin

Post by jonib » Sat Nov 20, 2010 10:36 am

Cool, some feedback 8)
supertusse wrote:I suppose you should store the dats in the application data folder instead?
Jupp, I hadn't tested in Win7 (partly why it's not an official release), I will probably need to store the dats in Application data directory. Thanks for testing and reporting.

Hopefully soon I'll make a new release.(win7 friendly)

jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image

supertusse
Posts: 8
Joined: Sat Nov 20, 2010 10:12 am

Re: XBMCRepeat XBMC plugin based on the official plugin

Post by supertusse » Sat Nov 20, 2010 2:00 pm

Heh, that was quick :-)

I solved the above by copying the .dat files from a computer running XP, btw. But that's not really a fix :-)

I have a couple more questions for you.

Is it possible to call your plugin from a PythonScript action? I would like to use your plugin for communication with xbmc (speficially, ExecBuiltIn via the httpapi action I suppose), but currently I'm stuck doing it myself inside the script action. Which is a bit messy imo, when there's a plugin for this stuff :-)

Also, how can I use values from eg.globals.* ? E.g, I tried passing a variable to the SendNotification action, but that only caused the variable name to show up in the notification, not the value :-)

jonib
Plugin Developer
Posts: 1298
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Re: XBMCRepeat XBMC plugin based on the official plugin

Post by jonib » Sat Nov 20, 2010 2:57 pm

supertusse wrote:I solved the above by copying the .dat files from a computer running XP, btw. But that's not really a fix :-)
Glad you found a workaround. :oops:
Is it possible to call your plugin from a PythonScript action?
Seems your in luck. :D I did a quick test with a Python Command action using these commands

Code: Select all

eg.plugins.XBMC.plugin.HTTP_API.send(method='Pause', params='')
eg.plugins.XBMC.plugin.JSON_RPC.send(method='VideoPlayer.PlayPause', params='')
Hopefully you can figure out how to use other methods, if not, ask. :lol:
I have not run any plugin methods from code so don't know if this is the right way, but seems to work.
Also, how can I use values from eg.globals.* ? E.g, I tried passing a variable to the SendNotification action, but that only caused the variable name to show up in the notification, not the value :-)
Just putting the variable name(or Python code) between curly braces should work.

Code: Select all

{eg.globals.myglobalvariablename}
jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image

supertusse
Posts: 8
Joined: Sat Nov 20, 2010 10:12 am

Re: XBMCRepeat XBMC plugin based on the official plugin

Post by supertusse » Sat Nov 20, 2010 5:27 pm

Thanks - I'll try this.

However, I have two xbmc's to control, so there are two XBMCRepeat instances in my tree. How do I control which one is called? I'll have to experiment :-)

Edit: spleling

jonib
Plugin Developer
Posts: 1298
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Re: XBMCRepeat XBMC plugin based on the official plugin

Post by jonib » Sat Nov 20, 2010 5:43 pm

supertusse wrote:However, I have two xbmc's to control, so there are two XBMCRepeat instances in my tree. How do I control which one is called? I'll have to experiment :-)
The first one should be called XBMC, and the second one should be XBMC1 or XBMC2, for me it's XBMC2.

To find out you can copy a XBMC action from your EventGhost config and paste it in Notepad, then you should see what the plugin is named internally.

jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image

supertusse
Posts: 8
Joined: Sat Nov 20, 2010 10:12 am

Re: XBMCRepeat XBMC plugin based on the official plugin

Post by supertusse » Sun Nov 21, 2010 10:51 am

Thanks! That helped a lot. I will post more later, but in case anyone else would like a working example of how you can access these plugins from code, I'll do a little snippet.

Short explanation:

Prior to this script I have another script that picks up fresh episode downloads and moves them into the right place in my tv library + writes a small log file with some details about this process. Then there's this script here below, that is started by a directory watcher when a new .log file is created. The purpose of the script is to start XBMC library updates for the show that just got a new episode + send a popup notification to the xbmc, so it will show on screen that there is a new episode available. I have (at the moment) two xbmc's to update, and wanted it to be easy to extend to more xbmcs in the future.

The 'trick' is how to associate an XBMCRepeater instance with a certain xbmc, which is done by storing a reference to the httpapi function for each xbmc instance in a dictionary, as shown below. When I add more xbmc's, I just add another entry in the xbmcs dict.

I'm just starting to get a hang of this Python thing, so any suggestions for improvements are most welcome :-)

Code: Select all

import sys
import os
import re

FileName = ''.join(eg.event.payload)
BaseName = ''.join(os.path.basename(FileName))

#Ignore files not ending with .log and files starting with _
if BaseName[-4:] != '.log' or BaseName[0] == '_':
    sys.exit()

# Reference to XBMCRepeater plugins linked to the xbmc's you want to update and notify + path to tv series in XBMC's library
xbmcs = {'Kontoret' : {'function' : eg.plugins.XBMC2.HTTPAPI, 'libpath' : 'Z:\\Video\\TV\\Series\\'},
         'Stuegris' : {'function' : eg.plugins.XBMC3.HTTPAPI, 'libpath' : 'Z:\\Video\\TV\\Series\\'}    }

LogContents = []
LogDict = {}

LogFile = open(FileName, 'r')

for LogLine in LogFile:
    LogContents.append(LogLine)
    
    LineTuple = LogLine.split(':',1)
    if LineTuple[0] <> '':
        LogDict[LineTuple[0].lstrip().rstrip()] = LineTuple[1].lstrip().rstrip()
    
LogFile.close()

for xbmc in xbmcs:

    ScanPath = xbmcs[xbmc]['libpath'] + LogDict['Series name'] + '\\'
    NotificationMsg = 'New Episode' + ',' + '{0} {1}x{2}'.format(LogDict['Series name'], LogDict['Season number'],LogDict['Episode number'])

    try:
        xbmcs[xbmc]['function']('ExecBuiltin', 'XBMC.updatelibrary(video, %s)' % (ScanPath), 5, False)
        xbmcs[xbmc]['function']('ExecBuiltin', 'Notification(%s)' % (NotificationMsg), 5, False)
    except Exception:
        sys.exc_clear()
Now, one more question: What is the "5" for, in the HTTPAPI function call? I glanced at the source code for the plugin, and can see that the parameter is called 'category', but it doesn't seem to be used for anything inside the actual function?

-Tusse

Edit: Added try/except around HTTPAPI calls, to prevent the script from exiting if one of the xbmc's are turnet off.
Last edited by supertusse on Mon Nov 22, 2010 9:00 am, edited 1 time in total.

jonib
Plugin Developer
Posts: 1298
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Re: XBMCRepeat XBMC plugin based on the official plugin

Post by jonib » Sun Nov 21, 2010 11:05 am

supertusse wrote:Short explanation:
Cool, I really need to do something like this, now the only partly automatic in my system is using TVRename to rename any TV episodes and move them to where I want them.
code
I'll check this out later.
Now, one more question: What is the "5" for, in the HTTPAPI function call?
It's just used to show the right category in the HTTPAPIs configure dialog, and not used for anything else. So you don't need to use it in your code.

jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image

jonib
Plugin Developer
Posts: 1298
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Re: XBMCRepeat XBMC plugin based on the official plugin

Post by jonib » Mon Dec 13, 2010 12:06 pm

viald wrote:I still have a small issue with OSD video and music.
I want to display with the same remote button the OSD video or music in full screen mode.

When playing music, pushing the guide button gives me the right OSD music window.
But when playing video, pushing the guide button gives me both OSD music and OSD video. I have to exit twice to remove OSD windows.

It seems to be a contextual issue with OSD music.
Only the actions in XBMCRepeat\Buttons folder is context based, so for the OSD you need to use Remote\Menu macro.

jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image

viald
Posts: 9
Joined: Sun Dec 12, 2010 12:07 pm

Re: XBMCRepeat XBMC plugin based on the official plugin

Post by viald » Mon Dec 13, 2010 3:58 pm

jonib wrote:Only the actions in XBMCRepeat\Buttons folder is context based, so for the OSD you need to use Remote\Menu macro.jonib
Sorry Jonib, I don't understand what you mean.And I don't understand what exactly are the action commands for remote and gamepad. :?
Eventghost 0.3.7.r1462 / XBMC Dharma RC2 / Windows Seven 64bits

kricker
Experienced User
Posts: 147
Joined: Thu Oct 12, 2006 5:49 am
Contact:

Re: XBMCRepeat XBMC plugin based on the official plugin

Post by kricker » Mon Dec 13, 2010 4:07 pm

I think he means this:
Image

Uploaded with ImageShack.us

viald
Posts: 9
Joined: Sun Dec 12, 2010 12:07 pm

Re: XBMCRepeat XBMC plugin based on the official plugin

Post by viald » Mon Dec 13, 2010 5:44 pm

kricker wrote:I think he means this:
Image

Uploaded with ImageShack.us
Yes I know where are the action commands, but I don't understand how to use them in such case.
Eventghost 0.3.7.r1462 / XBMC Dharma RC2 / Windows Seven 64bits

kricker
Experienced User
Posts: 147
Joined: Thu Oct 12, 2006 5:49 am
Contact:

Re: XBMCRepeat XBMC plugin based on the official plugin

Post by kricker » Mon Dec 13, 2010 5:58 pm

Look in your \XBMC\system\keymaps folder. Each of these keymaps specify what to do when a button is pressed, either keyboard, remote, joystick etc. There is a section in each xml file for each XBMC screen or OSD. These specify what to do on that OSD or screen when a certain button is pressed. In order to use these context sensitive type button presses you need to use either remote or gamepad inputs from jonibs plugin. Most of the other actions are direct commands and are not context sensitive.

viald
Posts: 9
Joined: Sun Dec 12, 2010 12:07 pm

Re: XBMCRepeat XBMC plugin based on the official plugin

Post by viald » Tue Dec 14, 2010 5:19 pm

Understood ! :D
Thank you Kricker. Now my setting is full functional.
Eventghost 0.3.7.r1462 / XBMC Dharma RC2 / Windows Seven 64bits

Post Reply