best way update "recently added" ?
#1
is this the best way to listen for update to the video database? and update a bunch of kodi instance that might be running? bit of kludge I think espcially going to settings and coming back to home. also this only does it if the user is on the home screen, if he isn't navigating back to home should trigger a refresh

any ideas are welcome.


Code:
#!/usr/bin/python


import websocket
import thread
import threading
import time
import json
from xbmcjson import XBMC, PLAYER_VIDEO
import logging
import logging.handlers
import sys


logger = logging.getLogger('MyLogger')
logger.setLevel(logging.INFO)
handler = logging.handlers.SysLogHandler(address = '/dev/log')
logger.addHandler(handler)

logging.basicConfig()

hosts = ['host1:8080','host2:8080','host3:8080']



def xbmcnotify_thread(host):
        try:
                xbmc = XBMC("http://" + host + "/jsonrpc")
                myjson = xbmc.Player.GetActivePlayers()
                window = xbmc.GUI.GetProperties({"properties":["currentwindow"]})
                if (not myjson['result']) and (window['result']['currentwindow']['id'] == 10000):
                        xbmc.GUI.ActivateWindow({"window":"video"})
                        xbmc.GUI.ActivateWindow({"window":"home"})
        except urllib2.URLError as e :
                if not e.reason.startswith('[Errno 113]'):
                        logger.critical("failed to notify kodi due to %s" % (e.reason))
        finally:
                xbmc = None
                sys.exit(0)

def on_message(ws, message):
        json_string = json.loads(message)
        #print json_string['method']
        if json_string['method'] == 'VideoLibrary.OnUpdate':
                for host in hosts:
                        logging.debug("Updating %s" % host)
                        threading.Thread(target=xbmcnotify_thread,args=[host]).start()


def on_error(ws, error):
    print error

def on_close(ws):
    logging.info("Stopped watching KODI")

def on_open(ws):
    def run(*args):
        logging.info("Looking for VideoLibrary.onUpdate on local KODI")
    thread.start_new_thread(run, ())




if __name__ == "__main__":
    websocket.enableTrace(False)
    ws = websocket.WebSocketApp("ws://127.0.0.1:9090/jsonrpc",
                              on_message = on_message,
                              on_error = on_error,
                              on_close = on_close)
    ws.on_open = on_open
    ws.run_forever()
Reply
#2
What exactly are you trying to do? The recently added widget on the home screen should automatically be updated whenever a new item has been added to the library.
Always read the online manual (wiki), FAQ (wiki) and search the forum before posting.
Do not e-mail Team Kodi members directly asking for support. Read/follow the forum rules (wiki).
Please read the pages on troubleshooting (wiki) and bug reporting (wiki) before reporting issues.
Reply
#3
(2015-02-11, 09:07)Montellese Wrote: What exactly are you trying to do? The recently added widget on the home screen should automatically be updated whenever a new item has been added to the library.

That is right they are updated automatically on the kodi instance that did the Update Library, other KODI's are unaware of the change.

Well here is the problem. I have a headless server that listens for media addition to the library using sickbeard or couchporato, the headless server then updates the db.

Now I have 3 KODI clients running on TV's some of which wont be used every day. Some of them are suspended (Zotac based) others are always on (appletv1 based). I want to make sure that when start to use my KODI on say my appletv that its screen is upto date and I can start watching the movie/show right from the home screen.

For the cases that kodi is suspended I can hack up a script to update the home screen by doing two ActiviateWindows() on resume from suspend state. So this solves the case for kodi instances that are always running sharing the same db but aren't aware of any changes.

is there a better way to refresh the reccentlyadded list than by doing
Code:
xbmc.GUI.ActivateWindow({"window":"video"})
xbmc.GUI.ActivateWindow({"window":"home"})
Reply
#4
Is there a better way to do this? I have headless kodi server that is being updated by sources that add media to the library. I need to clients to update themselves, I have a script that watches the kodi db on the headless server that can send RPC commands to the couple of clients I have. This used to work in 16.x, but now the home screen only updates the recently added when I navigate into a movie and stop again and come back to the home, is there a way reload the home screen remotely?



(2015-02-11, 16:57)vajonam Wrote:
Code:
xbmc.GUI.ActivateWindow({"window":"video"})
xbmc.GUI.ActivateWindow({"window":"home"})
Reply
#5
(2017-02-19, 00:48)vajonam Wrote: Is there a better way to do this? I have headless kodi server that is being updated by sources that add media to the library. I need to clients to update themselves, I have a script that watches the kodi db on the headless server that can send RPC commands to the couple of clients I have. This used to work in 16.x, but now the home screen only updates the recently added when I navigate into a movie and stop again and come back to the home, is there a way reload the home screen remotely?



(2015-02-11, 16:57)vajonam Wrote:
Code:
xbmc.GUI.ActivateWindow({"window":"video"})
xbmc.GUI.ActivateWindow({"window":"home"})


What I ended up doing was to create an addon that executes a builtin function, ReloadSkin(). that re-executes all the queries from the home screen. I can then execute this addon from a JSON RPC call. Seems a bit convoluted, when 1 kodi updates the db, point of shared db is diminished if I have to some gymnastics to refresh the screens on the other kodi's that are sharing that db
Reply

Logout Mark Read Team Forum Stats Members Help
best way update "recently added" ?0