Support for XBMC2 plugin (formerly XBMCRepeat)

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

Re: Support for XBMC2 plugin (formerly XBMCRepeat)

Post by jonib » Mon Mar 18, 2019 11:56 pm

Z'Hadum wrote:
Mon Mar 18, 2019 7:32 am
Has any one a hint for me how I can get that?
XBMC2->JSONRPC->Player->GetProperties and parameters:

Code: Select all

[1, ["currentaudiostream"]]
Seems to work for the current audio codec.

Then you can use this:

Code: Select all

eg.result["currentaudiostream"]["codec"]
or

Code: Select all

eg.result["currentaudiostream"]["name"]
to get the codec name that you can use in a Python script.
Another question:
to interpret the json-rpc reply, I have to write a small python snipplet in eventghost?
I find a Python script is best but not always necessary.

You can put this in a Python command after the JSORPC action and it will create different events depending on the codec:

Code: Select all

eg.TriggerEvent("audio-%s" % eg.result["currentaudiostream"]["codec"])
That can trigger macros to do what you want depending on the codec.

Hope this helps.

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

Z'Hadum
Posts: 8
Joined: Mon Mar 18, 2019 7:08 am

Re: Support for XBMC2 plugin (formerly XBMCRepeat)

Post by Z'Hadum » Tue Mar 19, 2019 9:33 am

Hello jonib,
many Thx.

I played yesterday evening also a little bit. And found the getinfolabels Method:

Code: Select all

{"jsonrpc":"2.0","method":"XBMC.GetInfoLabels","id":1,"params":{"labels":["VideoPlayer.AudioCodec"]}}
With this I get the audiocodec as Kodi it sees, but this is not what I need :(
Because: Kodi can not detect an Atmos soundtrack, it is always TrueHD :evil:

I will test your suggestions today evening. Thank you!

But one Question in advance:
Get I the codec info as it is stored in the database or as the Playerengine of Kodi detects it?
And if second: How can I get only the codecinfo from the currentstream as it is stored in the database(!)?? Is there any way you know?

(Another solution, with more python scripting, will be to get the audiolanguage (or index, if there is any) from the playerengine.
With the language-info it should be possible to select the correct audiostream from the streamdetails, that are based on the database information.... :shock:

Background:
In the database I've the correct information about the codecs, because I created that Info with tinymediamanager.
Tinymediamanager gets the information with the help of mediainfo. Mediainfo is capable of detecting 3D-audio codecs....ffmpeg in Kodi is not.

Z'Hadum
Posts: 8
Joined: Mon Mar 18, 2019 7:08 am

Re: Support for XBMC2 plugin (formerly XBMCRepeat)

Post by Z'Hadum » Wed Mar 20, 2019 11:56 am

Ok,
I tested it yesterday evening:

Code: Select all

[1, ["currentaudiostream"]]
works, but gives me also only the codec as kodi it detects.
And kodi can't detect atmos and dts-x. :(

I only see two solutions for me, with

Code: Select all

eg.result["currentaudiostream"]["name"]
I get the stream name, sopmetimes it has a hint to the atmos codec in it.
In this case I should rename Atmos audio streams....not the best solution

The other possible way I see is to try to connect the output from currentaudiostream with the streamdetails output,
which shows me the DB information. (where the atmos codec information is stored in my case ...)
This will need some python code I guess..

Best would be to have a property like currentaudiostream, which gives the DB details of the currentaudiostream....it seems that such a property does not exist....

If I get a working solution, I will post it here...

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

Re: Support for XBMC2 plugin (formerly XBMCRepeat)

Post by jonib » Fri Mar 22, 2019 2:27 pm

Unfortunately I haven't done much with the audio stuff in Kodi as I have a very basic 5.1 speaker setup.
Z'Hadum wrote:
Wed Mar 20, 2019 11:56 am
The other possible way I see is to try to connect the output from currentaudiostream with the streamdetails output,
which shows me the DB information. (where the atmos codec information is stored in my case ...)
This will need some python code I guess..
Try this code (in a Python script action) it checks the currently active audio and then gets the "streamdetails" with Player.GetItem.

Code: Select all

player = eg.plugins.XBMC2.JSONRPC(u'Player.GetActivePlayers', u'', False, True)[0]["playerid"]
result = eg.plugins.XBMC2.JSONRPC(u'Player.GetProperties', u'[{}, ["currentaudiostream", "audiostreams"]]'.format(player), False, True)
current = result["currentaudiostream"]["index"]
details = eg.plugins.XBMC2.JSONRPC(u'Player.GetItem', u'[{}, ["streamdetails"]]'.format(player), False, True)["item"]["streamdetails"]["audio"][current]
print(details["codec"])
eg.result = details["codec"]
Best would be to have a property like currentaudiostream, which gives the DB details of the currentaudiostream....it seems that such a property does not exist....
If the above code don't help, you need to ask in the Kodi JSON-RPC forum as they should know better and can add any missing features.

Background:
In the database I've the correct information about the codecs, because I created that Info with tinymediamanager.
Tinymediamanager gets the information with the help of mediainfo. Mediainfo is capable of detecting 3D-audio codecs....ffmpeg in Kodi is not.
Where is this information stored?


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

Z'Hadum
Posts: 8
Joined: Mon Mar 18, 2019 7:08 am

Re: Support for XBMC2 plugin (formerly XBMCRepeat)

Post by Z'Hadum » Thu Apr 04, 2019 9:23 am

Hello jonib,
sorry for my late response.

I had no time in the last weeks for this....but I will continue 8)

Many thx for your code snipplet, I think this should help a lot.
jonib wrote:
Fri Mar 22, 2019 2:27 pm
Background:
In the database I've the correct information about the codecs, because I created that Info with tinymediamanager.
Tinymediamanager gets the information with the help of mediainfo. Mediainfo is capable of detecting 3D-audio codecs....ffmpeg in Kodi is not.
Where is this information stored?
It is stored in the KODI database.

My steps to include movies into the KODI database are:
I scrap them with tinymediamanager (it uses mediainfo). tinymedaimanager writes the NFO file.
Also the Mediainfo details are in the NFO file like used codec, resolution etc

If KODI detects a new file and if a NFO file is present, it uses this information to fill the KODI database.
On this way the correct audiocedec from mediainfo finds its way into the KODI database :wink:

Here two example outputs from eventghost:

Code: Select all

eg.plugins.XBMC2.JSONRPC(u'Player.GetItem', u'{"playerid": 1, "properties": ["streamdetails"]}', True)
I get this output:

Code: Select all

XBMC2: JSONRPC - get-Streamdetails
   Result:
   {
     "item": {
       "id": 221, 
       "label": "Some-Title", 
       "streamdetails": {
         "audio": [
           {
             "channels": 8, 
             "codec": "atmos", 
             "language": "deu"
           }, 
           {
             "channels": 8, 
             "codec": "atmos", 
             "language": "eng"
           }
         ], 
         "subtitle": [
           {
             "language": "deu"
           }, 
           {
             "language": "eng"
           }, 
           {
             "language": "deu"
           }, 
           {
             "language": "eng"
           }
         ], 
         "video": [
           {
             "aspect": 1.7799999713897705, 
             "codec": "hevc", 
             "duration": 8244, 
             "height": 2160, 
             "language": "", 
             "stereomode": "", 
             "width": 3840
           }
         ]
       }, 
       "type": "movie"
     }
   }

And with this

Code: Select all

eg.plugins.XBMC2.JSONRPC(u'Player.GetProperties', u'[1, ["currentaudiostream"]]', True)
I get this output:

Code: Select all

XBMC2: JSONRPC - get-Streamdetails
   Result:
   {
     "currentaudiostream": {
       "bitrate": 24, 
       "channels": 8, 
       "codec": "TrueHD", 
       "index": 1, 
       "language": "Englisch (Vereinigte Staaten)", 
       "name": "Englisch (Vereinigte Staaten) - (TrueHD, 48000 Hz, 8 Channels)"
     }
   }
The first output are the data as it is stored in the KODI database,
the second output is the view of the KODI Player engine.

Z'Hadum
Posts: 8
Joined: Mon Mar 18, 2019 7:08 am

Re: Support for XBMC2 plugin (formerly XBMCRepeat)

Post by Z'Hadum » Fri Apr 05, 2019 10:42 am

Hello Jonib,
jonib wrote:
Fri Mar 22, 2019 2:27 pm

Code: Select all

player = eg.plugins.XBMC2.JSONRPC(u'Player.GetActivePlayers', u'', False, True)[0]["playerid"]
result = eg.plugins.XBMC2.JSONRPC(u'Player.GetProperties', u'[{}, ["currentaudiostream", "audiostreams"]]'.format(player), False, True)
current = result["currentaudiostream"]["index"]
details = eg.plugins.XBMC2.JSONRPC(u'Player.GetItem', u'[{}, ["streamdetails"]]'.format(player), False, True)["item"]["streamdetails"]["audio"][current]
print(details["codec"])
eg.result = details["codec"]
One thing I did not understand at your code:
Why do you try to get the playerid?
It did not worked for me, so I deleted this part.
It seems to be everytime 1, so it can be hardcoded? Or better not?

I think, I got it working.... Because your code didn't worked in my eventghost, I got exceptions,
I modified it a little bit:

Code: Select all

result = eg.plugins.XBMC2.JSONRPC(u'Player.GetProperties', u'[1, ["currentaudiostream"]]', True)
current = result["currentaudiostream"]["index"]
details = eg.plugins.XBMC2.JSONRPC(u'Player.GetItem', u'{"playerid": 1, "properties": ["streamdetails"]}', True)["item"]["streamdetails"]["audio"][current]
print("Codec is:")
print(details["codec"])
eg.result = details["codec"]
the last result has the "atmos" codec inside, as I need it :D
Many Thx ....

best regards

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

Re: Support for XBMC2 plugin (formerly XBMCRepeat)

Post by jonib » Fri Apr 05, 2019 2:30 pm

Z'Hadum wrote:
Fri Apr 05, 2019 10:42 am
Why do you try to get the playerid?
It seems to be everytime 1, so it can be hardcoded? Or better not?
The playerid is needed so the command knows which player is to be controlled (There can be more then one at the time like music and pictures), for video it is "1" for now but it might be changed or become dynamic in later Kodi versions so should not be hardcoded.

What error did you get?
I think, I got it working.... Because your code didn't worked in my eventghost, I got exceptions,
Are you using an older EventGhost or XBMC2 plugin? That might explain why my code example didn't work unmodified.
the last result has the "atmos" codec inside, as I need it :D
So you got it working like you want?

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

Z'Hadum
Posts: 8
Joined: Mon Mar 18, 2019 7:08 am

Re: Support for XBMC2 plugin (formerly XBMCRepeat)

Post by Z'Hadum » Sat Apr 06, 2019 2:52 pm

jonib wrote:
Fri Apr 05, 2019 2:30 pm
Z'Hadum wrote:
Fri Apr 05, 2019 10:42 am
Why do you try to get the playerid?
It seems to be everytime 1, so it can be hardcoded? Or better not?
The playerid is needed so the command knows which player is to be controlled (There can be more then one at the time like music and pictures), for video it is "1" for now but it might be changed or become dynamic in later Kodi versions so should not be hardcoded.
Ok, I understand. Then it's ok for me to hardcode it for now....
In the future it can easily be changed, if needed
jonib wrote:
Fri Apr 05, 2019 2:30 pm
What error did you get?
It seems that you are using one more paramater?
I get this if I copy & paste your code into a python script command in Eventghost:

Code: Select all

   Traceback (most recent call last):
     Python script "11", line 1, in <module>
       player = eg.plugins.XBMC2.JSONRPC(u'Player.GetActivePlayers', u'', False, True)[0]["playerid"]
   TypeError: __call__() takes at most 4 arguments (5 given)
jonib wrote:
Fri Apr 05, 2019 2:30 pm
I think, I got it working.... Because your code didn't worked in my eventghost, I got exceptions,
Are you using an older EventGhost or XBMC2 plugin? That might explain why my code example didn't work unmodified.
Eventghost Version is 0.4.1.r1722
Where can I see the XBMC2 Plugin Version?
jonib wrote:
Fri Apr 05, 2019 2:30 pm
the last result has the "atmos" codec inside, as I need it :D
So you got it working like you want?
Yes, many thx to you! :D
(I had only to add a little if/else command that triggers the needed Makros in Eventghost....)

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

Re: Support for XBMC2 plugin (formerly XBMCRepeat)

Post by jonib » Sat Apr 06, 2019 4:39 pm

Z'Hadum wrote:
Sat Apr 06, 2019 2:52 pm
Ok, I understand. Then it's ok for me to hardcode it for now....
In the future it can easily be changed, if needed
Sure, I usually hardcode it too first but try to make it more robust after I get stuff to work.

Code: Select all

   Traceback (most recent call last):
     Python script "11", line 1, in <module>
       player = eg.plugins.XBMC2.JSONRPC(u'Player.GetActivePlayers', u'', False, True)[0]["playerid"]
   TypeError: __call__() takes at most 4 arguments (5 given)
Old version of the plugin.
Eventghost Version is 0.4.1.r1722
The builtin version of the plugin is very old, get the latest version (First post in this thread should point to the latest one) here, from Github use the "raw" button to download it. Replace the __init__.py file in "(Install path)\EventGhost\Plugins\XBMCRepeat" directory. Shut down EventGhost first.

EventGhost 0.5.* releases have the latest so don't need to be manually updated.
Yes, many thx to you! :D
(I had only to add a little if/else command that triggers the needed Makros in Eventghost....)
Great, you will need some exception handling to make it foolproof, to handle when there is no media playing and the like.

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

Z'Hadum
Posts: 8
Joined: Mon Mar 18, 2019 7:08 am

Re: Support for XBMC2 plugin (formerly XBMCRepeat)

Post by Z'Hadum » Sun Apr 07, 2019 1:48 pm

You are right,
I had Version 0.6.19 of your plugin ....I updated it to 0.6.35 from github.

My modified code still works, good. :lol:

Your code is still not working, may be there is a little syntax problem?
Added only some print statements for debugging:

Code: Select all

player = eg.plugins.XBMC2.JSONRPC(u'Player.GetActivePlayers', u'', False, True)[0]["playerid"]
print("Player Number:")
print(player)
result = eg.plugins.XBMC2.JSONRPC(u'Player.GetProperties', u'[{}, ["currentaudiostream", "audiostreams"]]'.format(player), False, True)
print(result)
current = result["currentaudiostream"]["index"]
details = eg.plugins.XBMC2.JSONRPC(u'Player.GetItem', u'[{}, ["streamdetails"]]'.format(player), False, True)["item"]["streamdetails"]["audio"][current]
print(details["codec"])
eg.result = details["codec"]
I get...

Code: Select all

   Player Number:
   1
   Traceback (most recent call last):
     Python script "33", line 4, in <module>
       result = eg.plugins.XBMC2.JSONRPC(u'Player.GetProperties', u'[{}, ["currentaudiostream", "audiostreams"]]'.format(player), False, True)
   ValueError: zero length field name in format
I understand, that the {} should be replaced by the player number...
I have not enough python knowledge to see what would be the correct syntax for this.
If I replace the {} with a hardcoded 1, the code works.
Great, you will need some exception handling to make it foolproof, to handle when there is no media playing and the like.
You are right, there should be some exception handling, but I think for my purpose the exception handling by eventghost is enough :lol: :mrgreen:
...in worst case it does not trigger the soundmode change of my AVR :wink:

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

Re: Support for XBMC2 plugin (formerly XBMCRepeat)

Post by jonib » Sun Apr 07, 2019 2:52 pm

Z'Hadum wrote:
Sun Apr 07, 2019 1:48 pm
My modified code still works, good. :lol:
Nice
I understand, that the {} should be replaced by the player number...
I have not enough python knowledge to see what would be the correct syntax for this.
If I replace the {} with a hardcoded 1, the code works.
EventGhost 0.4 uses a very old Python version 2.6, that does not support the empty curly brace syntax, if you put a zero in like this "{0}" it should work example here.

Code: Select all

player = eg.plugins.XBMC2.JSONRPC(u'Player.GetActivePlayers', u'', False, True)[0]["playerid"]
print("Player Number:")
print(player)
result = eg.plugins.XBMC2.JSONRPC(u'Player.GetProperties', u'[{0}, ["currentaudiostream", "audiostreams"]]'.format(player), False, True)
print(result)
current = result["currentaudiostream"]["index"]
details = eg.plugins.XBMC2.JSONRPC(u'Player.GetItem', u'[{0}, ["streamdetails"]]'.format(player), False, True)["item"]["streamdetails"]["audio"][current]
print(details["codec"])
eg.result = details["codec"]
I totally forgot that limitation in old EventGhost, sorry about that. :oops:
You are right, there should be some exception handling, but I think for my purpose the exception handling by eventghost is enough :lol: :mrgreen:
...in worst case it does not trigger the soundmode change of my AVR :wink:
Just ask if you want help with that. :D

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

Z'Hadum
Posts: 8
Joined: Mon Mar 18, 2019 7:08 am

Re: Support for XBMC2 plugin (formerly XBMCRepeat)

Post by Z'Hadum » Sat Apr 13, 2019 9:20 am

jonib wrote:
Sun Apr 07, 2019 2:52 pm
Z'Hadum wrote:
Sun Apr 07, 2019 1:48 pm
You are right, there should be some exception handling, but I think for my purpose the exception handling by eventghost is enough :lol: :mrgreen:
...in worst case it does not trigger the soundmode change of my AVR :wink:
Just ask if you want help with that. :D

jonib
You offered it: :D (THX!)

Here what I did so far: It works...but could be smarter, I know.

First Python Script, based on yours: (ok I can delete the print debug statements ;-)
(Named "Detect Audiocodec from Player&DB Python Skript - New Version" in the Picture below)

Code: Select all

player = eg.plugins.XBMC2.JSONRPC(u'Player.GetActivePlayers', u'', False, True)[0]["playerid"]
print("Player Number:")
print(player)
result = eg.plugins.XBMC2.JSONRPC(u'Player.GetProperties', u'[{0}, ["currentaudiostream", "audiostreams"]]'.format(player), False, True)
print(result)
current = result["currentaudiostream"]["index"]
details = eg.plugins.XBMC2.JSONRPC(u'Player.GetItem', u'[{0}, ["streamdetails"]]'.format(player), False, True)["item"]["streamdetails"]["audio"][current]
print(details["codec"])
eg.result = details["codec"]
Genereated (example) Output in the Log

Code: Select all

   Player Number:
   1
   {u'currentaudiostream': {u'index': 0, u'name': u'Deutsch (Deutschland) - (DTS, 48000 Hz, 6 Channels)', u'language': u'Deutsch (Deutschland)', u'channels': 6, u'codec': u'DTS', u'bitrate': 32}, u'audiostreams': [{u'index': 0, u'name': u'Deutsch (Deutschland) - (DTS, 48000 Hz, 6 Channels)', u'language': u'Deutsch (Deutschland)', u'channels': 6, u'codec': u'DTS', u'bitrate': 32}]}
   dts
To switch between the two settings on the AV-Receiver
(I know this could be placed in the first script.
for testing, I put this in a second one.....)
(Named "Result Succesfull if atmos" in the Picture below)

Code: Select all

try: data = eg.result
except: eg.result = None
else:
        if data in ["atmos", "Atmos", "ATMOS"]: eg.TriggerEvent("Denon Network Control: Set Dolby Surround/Atmos")
        else: eg.TriggerEvent("Denon Network Control: Set Auro3D")
Here an Picture, how I set up the if/else logic in Eventghost, triggered by the second script
Eventghost-Audiocodec.png
What would you suggest to make the logic smarter?

regards,
Z'Hadum

Post Reply