Graphical front panel display

FWIW, the following python script serves to get fetch-able full-sized image URLs. Using Python 3.8.3 with the json-rpc package added, here’s the script. More afterward.

import requests
import json
import urllib.parse


def main():
    base_url  = "http://10.0.0.188:8080"
    rpc_url   = base_url + "/jsonrpc"
    image_url = base_url + "/images"    
    headers = {'content-type': 'application/json'}

    print("Hello, world!")

    # Assemble a simple "ping" payload as a test
    payload = {
        "jsonrpc": "2.0",        
        "method"  : "JSONRPC.Ping",
        "id"      : 2,
    }

    print("\nPing request:")
    print(json.dumps(payload))

    response = requests.post(rpc_url, data=json.dumps(payload), headers=headers).json()
    print("Response: ", json.dumps(response))

    # See if simple InfoLabels can be retrieved
    payload = {
        "jsonrpc": "2.0",        
        "method"  : "XBMC.GetInfoLabels",
        "params"  : {"labels": ["MusicPlayer.Title",
                                "MusicPlayer.Album",
                                "MusicPlayer.Artist",
                                "MusicPlayer.Time"]},
        "id"      : 3,
    }

    print("\nNext request:")
    print(json.dumps(payload))    

    response = requests.post(rpc_url, data=json.dumps(payload), headers=headers).json()
    print("Response: ", json.dumps(response))


    # How about artwork details?
    payload = {
        "jsonrpc": "2.0",        
        "method"  : "XBMC.GetInfoLabels",
        "params"  : {"labels": ["MusicPlayer.offset(0).Cover"]},
        "id"      : 4,
    }    

    print("\nNext request:")
    print(json.dumps(payload))    

    response = requests.post(rpc_url, data=json.dumps(payload), headers=headers).json()
    print("Response: ", json.dumps(response))

    print("\nIsolating returned image:// path")
    image_path = response["result"]["MusicPlayer.offset(0).Cover"]
    print(image_path)

    print("\nExternal URL is nominally:")
    cover_url = image_url + "/" + urllib.parse.quote(image_path,safe='')
    print(cover_url)

    print("\n\n... However, files evidently need to be prepared for download!\n")
    
    # Prepare download
    payload = {
        "jsonrpc": "2.0",        
        "method"  : "Files.PrepareDownload",
        "params"  : {"path": image_path},
        "id"      : 5,
    }        
    print("\nNext request:")
    print(json.dumps(payload))    

    response = requests.post(rpc_url, data=json.dumps(payload), headers=headers).json()
    print("Response: ", json.dumps(response))    

    print("\nTry retrieving the following:")
    print(base_url + "/" + response["result"]["details"]["path"])
    
if __name__ == "__main__":
    main()

Saving the file under the name client.py and invoking it via python client.ph, here’s an example run from my laptop, with Kodi running separately on an Odroid C4.

Hello, world!

Ping request:
{"jsonrpc": "2.0", "method": "JSONRPC.Ping", "id": 2}
Response:  {"id": 2, "jsonrpc": "2.0", "result": "pong"}

Next request:
{"jsonrpc": "2.0", "method": "XBMC.GetInfoLabels", "params": {"labels": ["MusicPlayer.Title", "MusicPlayer.Album", "MusicPlayer.Artist", "MusicPlayer.Time"]}, "id": 3}
Response:  {"id": 3, "jsonrpc": "2.0", "result": {"MusicPlayer.Album": "Abbey Road", "MusicPlayer.Artist": "The Beatles", "MusicPlayer.Time": "00:40", "MusicPlayer.Title": "Maxwell's Silver Hammer"}}

Next request:
{"jsonrpc": "2.0", "method": "XBMC.GetInfoLabels", "params": {"labels": ["MusicPlayer.offset(0).Cover"]}, "id": 4}
Response:  {"id": 4, "jsonrpc": "2.0", "result": {"MusicPlayer.offset(0).Cover": "/var/media/Music/iTunes/The Beatles/Abbey Road/Folder.jpg"}}

Isolating returned image:// path
/var/media/Music/iTunes/The Beatles/Abbey Road/Folder.jpg

External URL is nominally:
http://10.0.0.188:8080images/%2Fvar%2Fmedia%2FMusic%2FiTunes%2FThe%20Beatles%2FAbbey%20Road%2FFolder.jpg


... However, files evidently need to be prepared for download!


Next request:
{"jsonrpc": "2.0", "method": "Files.PrepareDownload", "params": {"path": "/var/media/Music/iTunes/The Beatles/Abbey Road/Folder.jpg"}, "id": 5}
Response:  {"id": 5, "jsonrpc": "2.0", "result": {"details": {"path": "vfs/%2fvar%2fmedia%2fMusic%2fiTunes%2fThe%20Beatles%2fAbbey%20Road%2fFolder.jpg"}, "mode": "redirect", "protocol": "http"}}

Try retrieving the following:
http://10.0.0.188:8080/vfs/%2fvar%2fmedia%2fMusic%2fiTunes%2fThe%20Beatles%2fAbbey%20Road%2fFolder.jpg

Cutting and pasting the URL at the bottom into a web browser gets me the fullsize cover! I’ve not played yet with getting just a thumbnail image.

Reading through this Kodi-encoded URL text from the wiki, I was at first expecting fetches to the image/ path to “just work”. Somewhere along the way, though, a Files.PrepareDownload step got added.

I hope the above is useful to someone. You would have to replace the IP address targeted, of course.

If anyone with more experience using Kodi’s JSON-RPC interface wants to suggest any improvements, I’m all ears.

UPDATE: One can just use the MusicPlayer.Cover InfoLabel, rather than what I used above. Parsing of the response would have to be adjusted to matched.

Cheers!