Wait for "executebuiltin" completion?
#1
Question 
I'm trying to automate some repetitive tasks and therefor trying to learn some Python basics.
I found some examples to play around with (that works just fine).

But I can't find any (simple) way to 'pause' she script while a built in command is executed like in example below:

How can I (easily?) pause the script from continuing while first command is executed??

Code:
xbmc.executebuiltin("UpdateLibrary(video)")
xbmc.executebuiltin("CleanLibrary(video)")
 

Thankful for all help to a complete novice!
Reply
#2
You can use "xbmc.executeJSONRPC(jsonrpccommand)" with commands:
https://codedocs.xyz/xbmc/xbmc/group__py...9ed84ed846
https://kodi.wiki/view/JSON-RPC_API/v6#V...brary.Scan
https://kodi.wiki/view/JSON-RPC_API/v6#A...brary.Scan
My addons: Gismeteo
Reply
#3
Using jsonrpc won't solve the OP.

You'll need to setup a monitor class, to detect when a scan or clean cycle is complete.
https://codedocs.xyz/xbmc/xbmc/group__py...c073e2e1b9
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#4
@Lunatixz  & @vl_maksime 
Thanks both for help.

Unfortunately that was way more complicated that I ever expected to accomplish... Confused
And my knowledge of Python scripts is none.

All I wanted to do was to stop/pause until step1 ("UpdateLibrary") was complete and thereafter execute step2 ("CleanLibrary").
Thought it was as easy as just use simple 'while' statement...

Just as a first useful learning project.
Didn't find anything understandable even after quite intense Googling...
*CRAP*

Anyway, thanks guys!
Reply
#5
Have you tried Library Auto Update add-on to update the library?
My addons: Gismeteo
Reply
#6
(2018-05-24, 13:57)JockeSve Wrote: Unfortunately that was way more complicated that I ever expected to accomplish... Confused
And my knowledge of Python scripts is none.

All I wanted to do was to stop/pause until step1 ("UpdateLibrary") was complete and thereafter execute step2 ("CleanLibrary").
I'm probably in a similar position to you - ie little python knowledge but muddling through - so this may not work, but I'd try making a loop and use something like
Code:
if xbmc.getCondVisibility(Library.IsScanningVideo) == false
to break it.
From https://kodi.wiki/view/List_of_boolean_conditions
Reply
#7
That would work, however it's a sloppy solution... The monitor class eliminates the need for while loops.

All depends on the ops goal, if they want to learn python for Kodi its worth doing it right first time. If op only wants a single solution for a quick script the while loop will work.. but be warned you could end up with code that hangs Kodi...
Image Lunatixz - Kodi / Beta repository
Image PseudoTV - Forum | Website | Youtube | Help?
Reply
#8
(2018-05-24, 20:55)vl_maksime Wrote: Have you tried Library Auto Update add-on to update the library?
 Yes, for years.
But as my mediaplayers (X86 based running LibreELEC) are going to standby after 30 mins of inactivity all scanning starts every time player wakes up from standby/sleep. 
I think I tried every single setting to mace scan manually controlled.
That's quite annoying to see...

So I thought that i could "easily" create a script to run full scan and cleanup with one buttonpress (well, a icon-click then). 
Too bad that Python structure isn't that easy to learn/understand and this far I haven't found an example that is close enough to my needs that I could play with (with my very limited skills...).
Reply
#9
Hi,
so in general development terms what you want to look for is an observer pattern. It is a common thing in almost all the languages I've ever touched. So instead of continuously asking what a state is, you tell your info provider to call a listener when a specific state is reached. https://en.m.wikipedia.org/wiki/Observer_pattern
In kodi the listener is the monitor class. You got to extend the monitor and override a on<some action> method. This method will be called by kodi once a specific action is done. You can have a look here in this thread where roman also provides an example.
https://forum.kodi.tv/showthread.php?tid=327173

It's really not that hard and worth wrapping your head around the observer pattern idea since it is really a common thing in development.

So what you roughly would do is this.
Extend monitor and override the onscanfinished function and put the clean library call in this function. And than start the library scan.
Reply

Logout Mark Read Team Forum Stats Members Help
Wait for "executebuiltin" completion?0