Auto Rescan Library at Regular Interval?

  Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
joshua.lyon Offline
Donor
Posts: 68
Joined: Dec 2009
Reputation: 0
Location: North Texas
Post: #11
For other people looking for details on how to have your library automatically update on a regular interval, I've posted a step-by-step how-to on my blog. Check it out and post back here (or in the comments) if you have questions.
find quote
MDPauley Offline
Senior Member
Posts: 264
Joined: Mar 2004
Reputation: 0
Location: Centreville, Va
Post: #12
autoexec.py
Code:
import xbmc, xbmcgui

xbmc.executebuiltin('XBMC.AlarmClock( VideoLibraryUpdater, XBMC.RunScript(special://home/scripts/VideoLibraryUpdater.py),45,true)')

VideoLibraryUpdater.py
Code:
import xbmc, xbmcgui
xbmc.executebuiltin('XBMC.UpdateLibrary(video)')
xbmc.executebuiltin('XBMC.AlarmClock( VideoLibraryUpdater, XBMC.RunScript(special://home/scripts/VideoLibraryUpdater.py),45,true)')

Put both scripts in your special://home/scripts directory. These 2 scripts will create a timed event that will update the library every 45 minutes...
(This post was last modified: 2010-01-05 07:28 by MDPauley.)
find quote
altern8 Offline
Junior Member
Posts: 44
Joined: May 2007
Reputation: 0
Post: #13
MDPauley Wrote:autoexec.py
Code:
import xbmc, xbmcgui

xbmc.executebuiltin('XBMC.AlarmClock( VideoLibraryUpdater, XBMC.RunScript(special://home/scripts/VideoLibraryUpdater.py),45,true)')

VideoLibraryUpdater.py
Code:
import xbmc, xbmcgui
xbmc.executebuiltin('XBMC.UpdateLibrary(video)')
xbmc.executebuiltin('XBMC.AlarmClock( VideoLibraryUpdater, XBMC.RunScript(special://home/scripts/VideoLibraryUpdater.py),45,true)')

Put both scripts in your special://home/scripts directory. These 2 scripts will create a timed event that will update the library every 45 minutes...

thanks for the code, sorry for the noobie question but where exactly is "special://home/scripts" located? i couldnt find it logging in as root or xbmc
find quote
MDPauley Offline
Senior Member
Posts: 264
Joined: Mar 2004
Reputation: 0
Location: Centreville, Va
Post: #14
Windows: %appdata%\xbmc\scripts\
Linux: ~/.xbmc/scripts/
OSX: not sure...
find quote
tstack77 Offline
Member
Posts: 59
Joined: Oct 2008
Reputation: 0
Post: #15
MDPauley, your scripts worked great! I even modified one to clean the library twice a day as well (simple I know, but I am a complete noob with scripting).

I made it by creating a CleanVideoLibrary.py and adding the job to autoexec.py

CleanVideoLibrary.py
Code:
import xbmc, xbmcgui
xbmc.executebuiltin('XBMC.CleanLibrary(video)')
xbmc.executebuiltin('XBMC.AlarmClock( CleanVideoLibrary, XBMC.RunScript(special://home/scripts/CleanVideoLibrary.py),720,true)')

autoexec.py
Code:
import xbmc, xbmcgui

xbmc.executebuiltin('XBMC.AlarmClock( VideoLibraryUpdater, XBMC.RunScript(special://home/scripts/VideoLibraryUpdater.py),45,true)')
xbmc.executebuiltin('XBMC.AlarmClock( CleanVideoLibrary, XBMC.RunScript(special://home/scripts/CleanVideoLibrary.py),720,true)')

I do have one quick question though that 20 minutes on google couldn't help me with. How do I set an exact time of day to run the script instead of every 12 hours? I tried changing the minutes to xx:yy format (18:15), but that wasn't the answer.

Thanks for all the help Smile
find quote
MDPauley Offline
Senior Member
Posts: 264
Joined: Mar 2004
Reputation: 0
Location: Centreville, Va
Post: #16
Change the 06 (6 AM) and 18 (6 PM) to the times you want to clean you library. I would do this in both autoexec.py and CleanVideoLibrary.py.

Code:
import time
import datetime
from datetime import date
import xbmc, xbmcgui

dt = datetime.datetime.now()

timeNow = time.time()
timeAM  = time.mktime( (dt.year, dt.month, dt.day, 06, 00, 00, dt.weekday(), 0, -1) )
timePM  = time.mktime( (dt.year, dt.month, dt.day, 18, 00, 00, dt.weekday(), 0, -1) )

if (timeNow < timeAM ):
    print "Set AM time"
    minutesToUpdate = round(abs(timeAM - timeNow))

if (timeNow > timeAM ):
    print "Set PM time"
    minutesToUpdate = round(abs(timePM - timeNow))

    
xbmc.executebuiltin('XBMC.AlarmClock( CleanVideoLibrary, XBMC.RunScript(special://home/scripts/CleanVideoLibrary.py), ' + str(minutesToUpdate) + ',true)')
(This post was last modified: 2010-01-12 21:03 by MDPauley.)
find quote
tstack77 Offline
Member
Posts: 59
Joined: Oct 2008
Reputation: 0
Post: #17
Awesome. That is a lot more complicated than I expected, and I had zero chance of making that on my own.

Thank you
find quote
marcus2004 Offline
Junior Member
Posts: 1
Joined: Dec 2009
Reputation: 0
Post: #18
joshua.lyon Wrote:For other people looking for details on how to have your library automatically update on a regular interval, I've posted a step-by-step how-to on my blog. Check it out and post back here (or in the comments) if you have questions.

Joshua I have used the info on your blog to do this before, but for whatever reason I don't think that the script is exiting properly after or something as after a day or two my machine slows down. As soon as I remove the cron items for the update it is fine. I had it set to 30 min updates and once a day cleaning.
I am trying try this python scripts to see if it is better.
find quote
jfgi Offline
Junior Member
Posts: 24
Joined: Jan 2010
Reputation: 0
Post: #19
tstack77 Wrote:MDPauley, your scripts worked great! I even modified one to clean the library twice a day as well (simple I know, but I am a complete noob with scripting).

I made it by creating a CleanVideoLibrary.py and adding the job to autoexec.py

CleanVideoLibrary.py
Code:
import xbmc, xbmcgui
xbmc.executebuiltin('XBMC.CleanLibrary(video)')
xbmc.executebuiltin('XBMC.AlarmClock( CleanVideoLibrary, XBMC.RunScript(special://home/scripts/CleanVideoLibrary.py),720,true)')

autoexec.py
Code:
import xbmc, xbmcgui

xbmc.executebuiltin('XBMC.AlarmClock( VideoLibraryUpdater, XBMC.RunScript(special://home/scripts/VideoLibraryUpdater.py),45,true)')
xbmc.executebuiltin('XBMC.AlarmClock( CleanVideoLibrary, XBMC.RunScript(special://home/scripts/CleanVideoLibrary.py),720,true)')

I do have one quick question though that 20 minutes on google couldn't help me with. How do I set an exact time of day to run the script instead of every 12 hours? I tried changing the minutes to xx:yy format (18:15), but that wasn't the answer.

Thanks for all the help Smile

Clean just makes XBMC (Windows, v9.11 and r28256) freeze for me. There's no issue when i run it from the menu, but everytime i run it from a script, it freezes.
find quote
tetodbs Offline
Junior Member
Posts: 46
Joined: Jan 2010
Reputation: 0
Post: #20
MDPauley Wrote:autoexec.py
Code:
import xbmc, xbmcgui

xbmc.executebuiltin('XBMC.AlarmClock( VideoLibraryUpdater, XBMC.RunScript(special://home/scripts/VideoLibraryUpdater.py),45,true)')

VideoLibraryUpdater.py
Code:
import xbmc, xbmcgui
xbmc.executebuiltin('XBMC.UpdateLibrary(video)')
xbmc.executebuiltin('XBMC.AlarmClock( VideoLibraryUpdater, XBMC.RunScript(special://home/scripts/VideoLibraryUpdater.py),45,true)')

Put both scripts in your special://home/scripts directory. These 2 scripts will create a timed event that will update the library every 45 minutes...

How to make it work for latest svn with addon system?

Thanks
find quote