Kodi Community Forum

Full Version: Automate library export
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi mates,

I viewed this post on automating library export and found it very useful. However, I need to run the command periodically and after much trial and error (I have liitle/no scripting knowledge) I was able to get it running but It prompts for the user to specify "separate files", "thumbs", "overwrite" etc. How can I modify the following scripts, so that XBMC does not prompt, but just executes my commands? ANY advice would be greatly appreciated. Nod

autoexec.py
PHP Code:
import xbmcxbmcgui

xbmc
.executebuiltin('XBMC.AlarmClock( ExportLibrary(video,true,true,true,true), XBMC.RunScript(D:/Users/Tyger/AppData/Roaming/XBMC/scripts/ExportLibrary.py),60,true)'

calls

ExportLibrary.py
PHP Code:
import xbmcxbmcgui
xbmc
.executebuiltin('XBMC.ExportLibrary(video)')
xbmc.executebuiltin('XBMC.AlarmClock( ExportLibrary(video,true,true,true,true), XBMC.RunScript(D:/Users/Tyger/AppData/Roaming/XBMC/scripts/ExportLibrary.py),60,true)'


THANKS IN ADVANCE!
The second line of ExportLibrary.py should be:

Code:
xbmc.executebuiltin('XBMC.ExportLibrary(video,true,true,true,true)')

This sort of code should really be done as a service add-on. I could probably knock some sample code together if you want. Alternatively install the "XBMC Library Auto Update" add-on (from the Programs section) and you can probably tweak that to export your library instead of updating it.
(2012-06-20, 19:02)jhsrennie Wrote: [ -> ]The second line of ExportLibrary.py should be:

Code:
xbmc.executebuiltin('XBMC.ExportLibrary(video,true,true,true,true)')

This sort of code should really be done as a service add-on. I could probably knock some sample code together if you want. Alternatively install the "XBMC Library Auto Update" add-on (from the Programs section) and you can probably tweak that to export your library instead of updating it.


Thank you, that line of code worked perfectly!!!

If you're willing, I would be interested in the sample code you referred to. Unless tweaking "XBMC Library Auto Update" would be a easier/better. I installed it and I'm tinkering with it now, but don't yet see how to have it export my metadata. Can you point me in the right direction?

Again, I truly appreciate your help.
The "XBMC Library Auto Update" code is a lot more complicated than I expected and I'm not surprised you couldn't see how to adapt it. I've written a very simple service add-on to run a task at a set interval. You can grab a copy from here. You can install the service from this zip or unzip it and install it manually.

The service will display a notification ever ten seconds. After installing it you need to edit default.py and change the repeat time and the command to run. Presumably you'll want the command to be "XBMC.ExportLibrary(video,true,true,true,true)"
(2012-06-21, 12:39)jhsrennie Wrote: [ -> ]The "XBMC Library Auto Update" code is a lot more complicated than I expected and I'm not surprised you couldn't see how to adapt it. I've written a very simple service add-on to run a task at a set interval. You can grab a copy from here. You can install the service from this zip or unzip it and install it manually.

The service will display a notification ever ten seconds. After installing it you need to edit default.py and change the repeat time and the command to run. Presumably you'll want the command to be "XBMC.ExportLibrary(video,true,true,true,true)"



This is great, works as promised.

Please pardon me for asking one more question...What would the syntax be to have this script run at a certain time (eg 6:00am) every day? If that's too much, I understand.

Thanks for all your work so far.
If you want the export to happen at a set time of day, an XBMC add-on/schedule isn't the best way to do this. I would do it by scheduling a task using the facilities of your operating system (cron on Linux or the Task Scheduler in Windows).

In Windows (something similar would work in Linux) the following batch file will trigger a library export:

Code:
rem ********************************************************************
rem LibExp.bat
rem ==========
rem Send an "Export library" command to XBMC
rem ********************************************************************

curl http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn(XBMC.ExportLibrary(video,true,true,true,true))

You can download the app curl.exe from http://curl.haxx.se/

Whenever this file is run it will instruct XBMC to export the video library, so just write the batch file, put it somewhere convenient (e.g. in your userdata folder) and configure the Task Scheduler to run it when you want.
You have been most helpful. Your suggestions/solutions have opened a door to many new possibilities for my XBMC setup.

Thank you.
Great Script could be really useful!

I was hoping you might help me put a change into it? My scripting skills are not great. My only problem is that is runs as soon as you start XBMC. My lib is large and it takes a long time to export. I have it set to overwrite NFO files so it updates watched status which I believe probably compounds the issue.

Is it possible to make it run after a period of idleness? I saw this POST and thought it could be of some use. They are talking about running a script after a period of idleness. It uses the operator xbmc.getInfoLabel('system.idletime'). What would be great is if after switching on and watching a 3hr film after leaving the box for say an hour it would do the export.

If that wouldn't work how about just using a "sleep" type command to pause the script before it goes into its loop.

I really wish my skills were better and I could do this on my own :-( Thanks for any help you guys can give me