Linux Polling Kodi for Running Processes
#1
Question 
Kodi Media Center 20.3 (20.3.0) Git:20.3-Nexus on LibreELEC (official): 11.0.6 (RPi4.arm), running on a Raspberry Pi 4 8gb.

I asked this on the LibreElec forums and it was suggested that I ask it here. The process I started is a result of a jsonrpc call so I hope I picked the right area.

I have finally been able to control Kodi from remote on my home LAN using Python scripts on WSL2 (Debian Ubuntu), and when I do a VideoLibrary.Scan, I do get the expected "OK" back via JSON, but is there a way to poll Kodi or look at processes to see when that scan is completed?
I am using this method, and VideoLibrary.Clean from a VB.NET Windows Forms application to interact with the Kodi database (ready only) to search for specific media assets, etc. When I make changes to my NAS resources as a result of this app, I want to periodically (on-demand) clean, then update Kodi's database, then pull it locally to update what my app sees. But I do not want to pull it's user database until the scan is complete. I am pulling the database locally because it is faster for my app to access and I wanted that barrier in case I somehow change the database, and I do not want to corrupt it on my LibreElec install of Kodi. I would rather let Kodi make the database updates based on what it sees on my multiple NAS resources.
I apologize if this has been asked before. I did extensive google searches and a few forums and did not get any hits.
Thanks for your time!
Reply
#2
(2024-02-27, 22:05)HopWorks Wrote: is there a way to poll Kodi or look at processes to see when that scan is completed?

if you use a socket connection you will receive JSON events, among those you will receive OnScanFinished

here's a script i wrote that uses that logic, feel free to use it however you would like to https://paste.kodi.tv/laguzeriwi

-----

the existing implementation is to update an array of predefined folders, defined in the variable 'folders'
Reply
#3
(2024-02-27, 22:16)izprtxqkft Wrote:
(2024-02-27, 22:05)HopWorks Wrote: is there a way to poll Kodi or look at processes to see when that scan is completed?

if you use a socket connection you will receive JSON events, among those you will receive OnScanFinished

here's a script i wrote that uses that logic, feel free to use it however you would like to https://paste.kodi.tv/laguzeriwi

-----

the existing implementation is to update an array of predefined folders, defined in the variable 'folders'

I have not tried it yet and I will when I get home, but I did read through it and it looks to be well written and understandable. Thank you!!!
One question, for the host IP, would I follow the same username:[email protected] format? I had to do that with the 'little' script I wrote, that is nowhere near as functional as yours.
Reply
#4
(2024-02-27, 22:36)HopWorks Wrote: One question, for the host IP, would I follow the same username:[email protected] format?

as i recall there is no authentication for socket connections
only requirement is turning on "Allow remote control from applications on other systems" in settings -> services -> control
Reply
#5
izprtxqkft, That code works perfect, and not only did it solve my need, it opened up a few doors of understanding for me. Thank you!
So for another question, about the 'folders' variable... I am assuming you are running this locally on the Kodi client, so I do not understand the 'plugin://plugin.video.integrate/movies/'. To be honest, I did notice the directories parameter of VideoLibrary.Scan but I do not fully understand what path to provide. And it did not occur to me that I could just scan a resource path instead of my entire library. This is awesome though because if I make changes in only one or a few folders, I can just scan those folders and not have to scan the whole thing.

What I am struggling with though is what path to supply (or include) in that folders variable. What format does Kodi expect for that? In 'c22' of the movie table (user database) I see a path for a media asset as 'smb://192.168.0.x/g/- movies/A Movie.mp4' but not sure how that translates to a useable path for the VideoLibrary.Scan method. I noticed yours has 'plugin://plugin....' but this is not a plugin I am writing.

Sorry for the continuing string of questions. And I want to thank you again for placing the vital pieces of the puzzle for me!! What you shared with me is exactly what I wanted for a very long time!

Thanks!

EDIT: Never mind sir. I'm an idiot!! My path was constructed incorrectly and I just realized that even if the path is incorrect, the method will return an 'OK' but of course, almost immediately because there is no place to scan. Once I fixed my immediate path to scan, it took a bit longer before returning 'complete.' So the path I supplied was adequate, and I cannot be more happy!! Thanks again!!
Reply
#6
(2024-02-28, 01:00)HopWorks Wrote: I am assuming you are running this locally on the Kodi client

actually i run it from my PC to my Android device on the same network
 
(2024-02-28, 01:00)HopWorks Wrote: so I do not understand the 'plugin://plugin.video.integrate/movies/'

you can completely ignore this plugin bit, it's just a plugin i wrote and use which the script updates ... no need to get into detail it will just confuse the issue at hand
folders would be an array of folders, the folders are the ones you have configured in your sources

ex:

folders=['smb://path/on/NAS/shows','smb://path/on/NAS/shows2','smb://path/on/NAS/movies','smb://path/on/NAS/movies2']

whatever "sources" you wanted updated, it iterates the array waiting for onfinish for each one until it's completed the entire array
 
(2024-02-28, 01:00)HopWorks Wrote: Sorry for the continuing string of questions. And I want to thank you again for placing the vital pieces of the puzzle for me!! What you shared with me is exactly what I wanted for a very long time!

all good, happy someone is able to make use of it
 
(2024-02-28, 01:00)HopWorks Wrote: That code works perfect, and not only did it solve my need, it opened up a few doors of understanding for me.

learning new things is always a good thing, glad you got something out of it
Reply
#7
Quote:learning new things is always a good thing, glad you got something out of itEsep
Especially when I have been searching for this info so for very long, which is why I am so thankful and happy today. The search results from my queries eluded me because I did not use the correct terminology in my search inquiries. A common problem for me. Controlling Kodi from CLI on a remote machine for me was like the Holy Grail to Indiana Jones. And I nearly gave up because the documentation is so sparse and somewhat out of date.

Wow, wrote your own plugin? I need to look into that. Not for the world, but certainly to improve my Kodi experience on my home network. And another thing I need to look into is how to customize the Chorus web interface to include data I want to include. I guess that falls under creating my own plugin.

Anyway, as I explore all that, you will probably be seeing my cries for help pop up here in the future. Thanks again sir!
Reply
#8
(2024-02-28, 01:39)HopWorks Wrote: Especially when I have been searching for this info so for very long, which is why I am so thankful and happy today. The search results from my queries eluded me because I did not use the correct terminology in my search inquiries. A common problem for me. Controlling Kodi from CLI on a remote machine for me was like the Holy Grail to Indiana Jones. And I nearly gave up because the documentation is so sparse and somewhat out of date.

Wow, wrote your own plugin? I need to look into that. Not for the world, but certainly to improve my Kodi experience on my home network. And another thing I need to look into is how to customize the Chorus web interface to include data I want to include. I guess that falls under creating my own plugin.

Anyway, as I explore all that, you will probably be seeing my cries for help pop up here in the future. Thanks again sir!

writing plugins is mostly easy, just python code with xbmc calls, not much different than learning how to use the sys module or socket or anything else you would import

just saw your edit, good to see you got there

you're very welcome
any time you have questions feel free there are knowledgeable people here that can help
Reply

Logout Mark Read Team Forum Stats Members Help
Polling Kodi for Running Processes0