[WINDOWS] HOW-TO schedule automatic library updates

  Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
Pr.Sinister Offline
Fan
Posts: 680
Joined: Sep 2007
Reputation: 15
Location: Montreal, Canada
Thumbs Up  [WINDOWS] HOW-TO schedule automatic library updates
Post: #1
Hello Boys and Girls...

Sometimes, something that seems so easy or so obvious to you may not be so
easy for someone else.

I always figured most people had their own special way of automatically updating
their libraries but it seems i was mistaken. There are dozens of ways of doing this
but here i will explain one that will open up so many other possibilities for end-users.

Here we go...

What you need :

- Knowledge of the Windows Task Scheduler
- AutoIt v3
- Wget for Windows (mirror)

If you prefer, you can use FireFox instead of WGet.

So install the full AutoIt Suite and use this code and save it into a file with the .au3 extension

XBMCLibUpdate-wget.au3
Code:
; **********************************************************
; When this script starts it updates the XBMC Video Library
; **********************************************************

; ***********************************************************************
; WGet is available at http://gnuwin32.sourceforge.net/packages/wget.htm
; or http://users.ugent.be/~bpuype/wget/
; ***********************************************************************s

Run("C:\UnixTools\wget.exe http://user:pass@xbmcip/xbmcCmds/xbmcHttp?command=ExecBuiltIn%28UpdateLibrary%28video%29%29", "", "")

; ********************************
; Delete the file created by wget
; ********************************

FileDelete("C:\UnixTools\xbmcHttp@command=ExecBuiltIn%28UpdateLibrary%28video%29%29")

; ***********
; Script end
; ***********

Exit

Once you have edited the code to use your username and password as well as
the correct IP address for your XBMC, save it, right-click on the file in Explorer
and select Compile Script.

This will create the executable file you can use in the Windows Task Scheduler.

Pretty easy no? Smile

Tips :

- Instead of an IP, you can use the hostname of the XBMC machine
- If you are running the script from the XBMC machine, localhost can be used instead of IP
- The wget.exe file is a standalone .exe so you can put it anywhere you want as long as you point to the right one in the script source
- AutoIt comes with an extensive help file (.chm). Each function has examples and there are lots of pre-made scripts to use. Check these out for some fun advanced features to help you automate anything you can think of.

-Pr.

------------------------------------------
[4 XBMC Clients + 3 Norco RPC-4224 Media Servers w/74 TB HDD Space]
If my post helped, thank me by adding to my reputation! :)
(This post was last modified: 2010-01-01 12:51 by Pr.Sinister.)
find quote
Pr.Sinister Offline
Fan
Posts: 680
Joined: Sep 2007
Reputation: 15
Location: Montreal, Canada
Post: #2
If you would prefer using FireFox, here is the code.

Be advised that if FireFox finds updates for your addons or for itself, the script
will fail until you manually update firefox

XBMCLibUpdate-firefox.au3
Code:
; ********************************************************************
; When this script starts it updates the XBMC Video Library w/FireFox
; ********************************************************************

Run("C:\Program Files\Mozilla Firefox\firefox.exe http://user:pass@xbmcip/xbmcCmds/xbmcHttp?command=ExecBuiltIn%28UpdateLibrary%28video%29%29", "", "")

; ***********************************************
; It waits for a window called "Mozilla Firefox"
; ***********************************************

WinWait("Mozilla Firefox")

; ****************
; Sleep 5 Seconds
; ****************

Sleep(5000)

; *******************************************************************
; When the window gets detected the script closes the Firefox window
; *******************************************************************

WinClose("Mozilla Firefox", "")

; ***********
; Script end
; ***********

Exit

------------------------------------------
[4 XBMC Clients + 3 Norco RPC-4224 Media Servers w/74 TB HDD Space]
If my post helped, thank me by adding to my reputation! :)
find quote
Pr.Sinister Offline
Fan
Posts: 680
Joined: Sep 2007
Reputation: 15
Location: Montreal, Canada
Post: #3
Someone asked if it was possible to do more than just the simple update library.

One example was to:

- Close XBMC
- Run AntiVirus Scan
- Run Defrag tool
- Run XBMC
- Update Library

Here is a script that does just that :

XBMCDoLots.au3
Code:
;************
; Close XBMC
;************

ProcessClose("xbmc.exe")

; ****************
; Sleep 5 Seconds
; ****************

Sleep(5000)

; *************************************
; Update Microsoft Security Essentials
; *************************************

RunWait("C:\Program Files\Microsoft Security Essentials\MpCmdRun.exe -SignatureUpdate", "", "")

; ****************************************************************************
; Scan for Malware with Microsoft Security Essentials (-1 = Quick, -2 = Full)
; ****************************************************************************

RunWait("C:\Program Files\Microsoft Security Essentials\MpCmdRun.exe -Scan -2", "", "")

; *********************
; Defrag System Drive
; *********************

RunWait("C:\WINDOWS\system32\defrag.exe c: -v", "", "")

; ********************************************************************************​
; Run XBMC (Portable Mode) - Make sure setting to update library at startup is on
; ********************************************************************************​

Run("C:\Program Files\XBMC\XBMC.exe -p", "", "")

; *********************************************
; Set Focus to XBMC Window - Not Always Needed
; *********************************************

WinActivate("XBMC", "")

; ***********
; Script end
; ***********

Exit

The script is commented so you can understand what's going on. Use the AutoIt Help File for anything you don't understand or if you want to add extra stuff.

HAPPY NEW YEAR!

-Pr.

------------------------------------------
[4 XBMC Clients + 3 Norco RPC-4224 Media Servers w/74 TB HDD Space]
If my post helped, thank me by adding to my reputation! :)
find quote
DurhamDev Offline
Fan
Posts: 350
Joined: Nov 2009
Reputation: 11
Location: Ajax, Ontario, Canada
Post: #4
That's awesome, Pr. Thanks so much. I've implemented the final script, albeit with a few changes for different defrag and antivirus programs, but it runs like a dream!

One question: if I wanted to run the other scripts, and considering I'm using 'localhost', I do have to configure the 'internet access' component within XBMC, correct? (I haven't done it previously, so any help would also be appreciated!) I'm also going to look into some of the other commands that can be sent to the XBMC, and see if I can find others such as "clean the database".

Thanks again! That's awesome!
find quote
Pr.Sinister Offline
Fan
Posts: 680
Joined: Sep 2007
Reputation: 15
Location: Montreal, Canada
Post: #5
DurhamDev Wrote:One question: if I wanted to run the other scripts, and considering I'm using 'localhost', I do have to configure the 'internet access' component within XBMC, correct? (I haven't done it previously, so any help would also be appreciated!) I'm also going to look into some of the other commands that can be sent to the XBMC, and see if I can find others such as "clean the database".

If you are going to use localhost, do this :

In your XBMC Settings, under Network, you would need to enable :

- Allow control of XBMC via HTTP
- Port 80
- Username
- Password
- Allow programs on this system to control XBMC

This is under Settings | Network | System in Aeon. Not Internet Access.

There are a bunch of things that can be done via the Web Server HTTP API
but to do the clean library, i suggest you just enable the Clean Library on
update instead.

Just create a file called advancedsettings.xml and under the videolibrary tag,
add <cleanonupdate>true</cleanonupdate>. That file then goes into your
userdata directory.

Problem solved. Big Grin

Here is what my advancedsettings.xml looks like

Code:
<advancedsettings>
    <videolibrary>
        <hideallitems>true</hideallitems>
        <recentlyaddeditems>50</recentlyaddeditems>
        <backgroundupdate>true</backgroundupdate>
        <cleanonupdate>true</cleanonupdate>
    </videolibrary>
</advancedsettings>

DurhamDev Wrote:Thanks again! That's awesome!

You're very welcome buddy!

-Pr.

------------------------------------------
[4 XBMC Clients + 3 Norco RPC-4224 Media Servers w/74 TB HDD Space]
If my post helped, thank me by adding to my reputation! :)
find quote
DurhamDev Offline
Fan
Posts: 350
Joined: Nov 2009
Reputation: 11
Location: Ajax, Ontario, Canada
Post: #6
Pr.Sinister Wrote:
Code:
<advancedsettings>
    <videolibrary>
        <hideallitems>true</hideallitems>
        <recentlyaddeditems>50</recentlyaddeditems>
        <backgroundupdate>true</backgroundupdate>
        <cleanonupdate>true</cleanonupdate>
    </videolibrary>
</advancedsettings>

This is great. Of course, once again, I have more questions. I checked the Wiki on advancedsettings.xml, and it had some similar settings for both the video and music libraries, however, it doesn't explain a few things. For example, the "hideallitems" arguments. Is this effectively 'removing' all items from the library, and rescraping them from scratch, or something different? Secondly, what does the "recentlyaddeditems" argument do?

(Is there a better Wiki or place to look at?)

Thanks, in advance!
find quote
Pr.Sinister Offline
Fan
Posts: 680
Joined: Sep 2007
Reputation: 15
Location: Montreal, Canada
Post: #7
DurhamDev Wrote:For example, the "hideallitems" arguments. Is this effectively 'removing' all items from the library, and rescraping them from scratch, or something different?

In TV Shows, say you have all seasons of the show 24. When selecting the show,
you can choose Season 1, Season 2, Season 3, etc... and ALL SEASONS.

That setting only hides that "ALL SEASONS" listing. It doesn't remove anything
from the library.

DurhamDev Wrote:Secondly, what does the "recentlyaddeditems" argument do?

Thanks, in advance!

That determines the amount of items that are displayed when choosing

"Recently Added Movies" or "Recently Added TV Shows" from the video library.

For Example, if you use Aeon Hitched as your skin, in the main menu, highlight
Movies and press down. Choose Recent. It will display the movies newly added
to your library. By default, it is 25 but i prefer 50 for TV episodes.

-Pr.

------------------------------------------
[4 XBMC Clients + 3 Norco RPC-4224 Media Servers w/74 TB HDD Space]
If my post helped, thank me by adding to my reputation! :)
find quote
IsleOfMan Offline
Senior Member
Posts: 190
Joined: Nov 2009
Reputation: 1
Post: #8
Not sure if anyone is still reading here, but when I try the Firefox method, I get the following confirmation box that requires action before the script will continue:

Quote:You are about to log in to the site "192.168.2.2" with the username "xbmc".

OK

Cancel

I'm running Firefox 3.6 and can't find a way to disable this particular popup. Any help?

Thanks!
find quote
queeup Offline
Posting Freak
Posts: 762
Joined: Feb 2009
Reputation: 16
Post: #9
I prefer built-in schedule function for this.
http://trac.xbmc.org/ticket/9056
find quote
hermy65 Offline
Senior Member
Posts: 110
Joined: May 2009
Reputation: 0
Post: #10
my path for wget is different then yous so im curious if this is the correct configuration then.

Run("C:\Program Files\GnuWin32\binwget.exe http://username:password@localhost/xbmcCmds/xbmcHttp?command=ExecBuiltIn%28UpdateLibrary%28video%29%29", "", "")

; ********************************
; Delete the file created by wget
; ********************************

FileDelete("C:\Program Files\GnuWin32\xbmcHttp@command=ExecBuiltIn%28UpdateLibrary%28video%29%29")
find quote
Pr.Sinister Offline
Fan
Posts: 680
Joined: Sep 2007
Reputation: 15
Location: Montreal, Canada
Post: #11
IsleOfMan Wrote:Not sure if anyone is still reading here, but when I try the Firefox method, I get the following confirmation box that requires action before the script will continue:



I'm running Firefox 3.6 and can't find a way to disable this particular popup. Any help?

Thanks!

Try using the command

Code:
Send("{ENTER}")

If that doesn't work, then make sure to activate the Firefox Window first like

Code:
WinActivate("Mozilla Firefox", "")
Send("{ENTER}")

The title of the Firefox window may different than that... Use the AutoIt Window Info tool to get the exact title.

-Pr.

------------------------------------------
[4 XBMC Clients + 3 Norco RPC-4224 Media Servers w/74 TB HDD Space]
If my post helped, thank me by adding to my reputation! :)
find quote
Pr.Sinister Offline
Fan
Posts: 680
Joined: Sep 2007
Reputation: 15
Location: Montreal, Canada
Post: #12
queeup Wrote:I prefer built-in schedule function for this.
http://trac.xbmc.org/ticket/9056

Obviously that would be better but in the meantime, this works fine for me Big Grin

------------------------------------------
[4 XBMC Clients + 3 Norco RPC-4224 Media Servers w/74 TB HDD Space]
If my post helped, thank me by adding to my reputation! :)
find quote
Pr.Sinister Offline
Fan
Posts: 680
Joined: Sep 2007
Reputation: 15
Location: Montreal, Canada
Post: #13
hermy65 Wrote:my path for wget is different then yous so im curious if this is the correct configuration then.

Run("C:\Program Files\GnuWin32\binwget.exe http://username:password@localhost/xbmcCmds/xbmcHttp?command=ExecBuiltIn%28UpdateLibrary%28video%29%29", "", "")

; ********************************
; Delete the file created by wget
; ********************************

FileDelete("C:\Program Files\GnuWin32\xbmcHttp@command=ExecBuiltIn%28UpdateLibrary%28video%29%29")

Yes. You just need to figure out where wget saves the file. By default, it usually saves it where it resides so changing C:\Unixtools to C:\Program Files\GnuWin32 should work just fine.

-Pr.

------------------------------------------
[4 XBMC Clients + 3 Norco RPC-4224 Media Servers w/74 TB HDD Space]
If my post helped, thank me by adding to my reputation! :)
find quote
RhysG Offline
Junior Member
Posts: 13
Joined: Jun 2010
Reputation: 0
Post: #14
Using WGet, AutoIt and Task Scheduler didn't work for me on Windows 7 x86 or x84. Do you have to set certain permissions? How can I test to see if the XBMC HTTP interface is available? I didn't use port 80 as that is already in use by something else, instead I mapped another port. Would that be a problem?
find quote
Pr.Sinister Offline
Fan
Posts: 680
Joined: Sep 2007
Reputation: 15
Location: Montreal, Canada
Post: #15
RhysG Wrote:Using WGet, AutoIt and Task Scheduler didn't work for me on Windows 7 x86 or x84. Do you have to set certain permissions? How can I test to see if the XBMC HTTP interface is available? I didn't use port 80 as that is already in use by something else, instead I mapped another port. Would that be a problem?

Well since using Sick Beard, i have discontinued using my auto-update hack but i just noticed yesterday in the XBMC add-ons directory something called XBMC Library Auto-Update. It seems to be a very easy way to do what you need.

-Pr.

------------------------------------------
[4 XBMC Clients + 3 Norco RPC-4224 Media Servers w/74 TB HDD Space]
If my post helped, thank me by adding to my reputation! :)
find quote
Post Reply