xbmc / xbmc

Kodi is an award-winning free and open source home theater/media center software and entertainment hub for digital media. With its beautiful interface and powerful skinning engine, it's available for Android, BSD, Linux, macOS, iOS, tvOS and Windows.
https://kodi.tv/
Other
18.53k stars 6.3k forks source link

Python & JSON: Player.GetProperties never changes the subtitle stream info #20290

Open croneter opened 3 years ago

croneter commented 3 years ago

Bug report

Describe the bug

Here is a clear and concise description of what the problem is:

I need to be able to dectect whether Kodi changed its subtitle stream, say from German to English. I would do this using xbmc.executeJSONRPC with the JSON Method Player.GetProperties, so somethine like this:

class JSON(object):
    def __init__(self):
        self._id = 1

    def current_streams(self, playerid):
        query = {
            'jsonrpc': '2.0',
            'id': self._id,
            'method': 'Player.GetProperties',
            'params': {'playerid': playerid,
                       'properties': ['currentaudiostream',
                                      'currentsubtitle',
                                      'subtitleenabled']}

        }
        self._id += 1
        return json.loads(xbmc.executeJSONRPC(json.dumps(query)))

I'm triggering this using xbmc.Monitor and the notification Player.OnAVChange:

class MyMonitor(xbmc.Monitor):
    def __init__(self, *args, **kwargs):
        self.json = JSON()
        super(MyMonitor, self).__init__(*args, **kwargs)

    def onNotification(self, sender, method, data):
        if method == 'Player.OnAVChange':
            data = loads(data)
            streams = self.json.current_streams(data['player']['playerid'])
            xbmc.log("service.player-onavchange-bug-showcase: "
                     "Player.GetProperties: %s" % streams,
                     level=xbmc.LOGDEBUG)

BUT: neither currentsubtitle nor subtitleenabled ever change even though I switch subtitles for the currently playing video. It DOES work for currentaudiostream, fortunately.

Expected Behavior

Here is a clear and concise description of what was expected to happen:

Kodi's JSON-answer for the method Player.GetProperties for the properties currentsubtitle and subtitleenabled should change if the user changes the currently playing subtitle.

Actual Behavior

currentsubtitle and subtitleenabled NEVER change during a video's playback, no matter what the user does.

Possible Fix

Don't know, sorry

To Reproduce

Steps to reproduce the behavior:

Please find a minimal working example Kodi add-on here: https://github.com/croneter/service.player-onavchange-bug-showcase

  1. Install minimal service add-on that shows the bug. (direct link to the ZIP-file)
  2. Play a video with several subtitles
  3. Switch subtitles. Or turn them on and off
  4. Observe that the minimal service add-on does not report any changed currentsubtitle and subtitleenabled properties

Debuglog

The debuglog can be found here: Relevant excerpt where I changed the subtitle language from German to English to Italien:

service.player-onavchange-bug-showcase: Player.GetProperties: {'id': 1, 'jsonrpc': '2.0', 'result': {'currentaudiostream': {'bitrate': 0, 'channels': 2, 'codec': 'aac', 'index': 0, 'isdefault': True, 'isimpaired': False, 'isoriginal': False, 'language': '', 'name': 'AAC stereo', 'samplerate': 0}, 'currentsubtitle': {'index': 7, 'isdefault': False, 'isforced': False, 'isimpaired': False, 'language': 'ger', 'name': ''}, 'subtitleenabled': True}}
...
service.player-onavchange-bug-showcase: Player.GetProperties: {'id': 2, 'jsonrpc': '2.0', 'result': {'currentaudiostream': {'bitrate': 0, 'channels': 2, 'codec': 'aac', 'index': 0, 'isdefault': True, 'isimpaired': False, 'isoriginal': False, 'language': '', 'name': 'AAC stereo', 'samplerate': 0}, 'currentsubtitle': {'index': 7, 'isdefault': False, 'isforced': False, 'isimpaired': False, 'language': 'ger', 'name': ''}, 'subtitleenabled': True}}
...
service.player-onavchange-bug-showcase: Player.GetProperties: {'id': 3, 'jsonrpc': '2.0', 'result': {'currentaudiostream': {'bitrate': 0, 'channels': 2, 'codec': 'aac', 'index': 0, 'isdefault': True, 'isimpaired': False, 'isoriginal': False, 'language': '', 'name': 'AAC stereo', 'samplerate': 0}, 'currentsubtitle': {'index': 7, 'isdefault': False, 'isforced': False, 'isimpaired': False, 'language': 'ger', 'name': ''}, 'subtitleenabled': True}}

Screenshots

Here are some links or screenshots to help explain the problem:

Additional context or screenshots (if appropriate)

Here is some additional context or explanation that might help:

Your Environment

Used Operating system:

note: Once the issue is made we require you to update it with new information or Kodi versions should that be required. Team Kodi will consider your problem report however, we will not make any promises the problem will be solved.

enen92 commented 3 years ago

Thanks for reporting the issue. I've tried to reproduce this issue in current master and I was not able to do it, or at least I think your issue might be different than the interpretation I can collect from the issue. I tried to play a video file and executed the same json query using this tool: https://forum.kodi.tv/showthread.php?tid=172734 while changing subtitle tracks, disabling subtitles, etc. Here are the results:

Start playback:

http://localhost:8152/jsonrpc?request={"jsonrpc":"2.0","method":"Player.GetProperties","params":{"playerid":1,"properties":["subtitleenabled","currentsubtitle"]},"id":38}
{
    "currentsubtitle": {
        "index": 1,
        "isdefault": false,
        "isforced": false,
        "isimpaired": false,
        "language": "",
        "name": "(External)"
    },
    "subtitleenabled": true
}

Disabled subs:

http://localhost:8152/jsonrpc?request={"jsonrpc":"2.0","method":"Player.GetProperties","params":{"playerid":1,"properties":["subtitleenabled","currentsubtitle"]},"id":38}
{
    "currentsubtitle": {
        "index": 1,
        "isdefault": false,
        "isforced": false,
        "isimpaired": false,
        "language": "",
        "name": "(External)"
    },
    "subtitleenabled": false
}

Note the above response is correct. The current subtitle in the player is still the older one, but the subtitleenabled in now false

Changed to the first subtitle of the file and reenabled subs:

http://localhost:8152/jsonrpc?request={"jsonrpc":"2.0","method":"Player.GetProperties","params":{"playerid":1,"properties":["subtitleenabled","currentsubtitle"]},"id":38}
{
    "currentsubtitle": {
        "index": 0,
        "isdefault": false,
        "isforced": false,
        "isimpaired": false,
        "language": "",
        "name": "(External)"
    },
    "subtitleenabled": true
}

Again, subtitleenabled is now true and the index of the current sub is 0.


Having said that I think you have different expectations on the fired events in your addon and there is nothing wrong with JSON. OnAVChanged is only fired when some stream changes on the player. It should in fact be fired when you select a different subtitle stream (and this is not happening). It should not be fired when subtitles are disabled though!

I think the bugs at hand in my POV here are:

github-actions[bot] commented 3 months ago

This issue is now marked stale because it has been open over a year without activity. Remove the stale label or add a comment to reset the stale state.

croneter commented 3 months ago

Not stale