XBMC Library Updater Addon

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
robweber Offline
Posting Freak
Posts: 889
Joined: Sep 2009
Reputation: 27
Post: #46
I just posted a pull request for the main XBMC repo with a few updates - thanks to pkscuot for the basis for a lot of what went into this one.

A few small things that I liked from pskcout's code got merged in some form. Basically the ability to run the update even while the player is running, checking for setting changes during each run so settings can be modified without an XBMC restart, and some better log formatting.

I did like the idea behind making the timers a little more flexible but letting the user kind of build their own timer through the gui seemed kind of painful. Instead I opted for a cron style scheduler. In the 'Advanced' Timer mode you can specify a cron expression that the updater will run on instead of using the basic hourly timer interval. This should be a lot more flexible for people and give them almost endless options for configuring the timers. Cron knowledge is necessary but that can be picked up using Google in about 1 min.

As a side note, it has occurred to me that by using the cron expression timers this addon could be easily modified to not only do updates, but allow a host of XBMC built in functions to run via a cron scheduler. The 'program' function could let a user setup multiple timers for XBMC functions and the 'service' part could execute them accordingly. Probably not something I'll get to anytime soon though.
find quote
pkscout Offline
Posting Freak
Posts: 1,088
Joined: Jan 2011
Reputation: 23
Location: Honolulu, HI
Post: #47
[quote=robweber]I did like the idea behind making the timers a little more flexible but letting the user kind of build their own timer through the gui seemed kind of painful. Instead I opted for a cron style scheduler. In the 'Advanced' Timer mode you can specify a cron expression that the updater will run on instead of using the basic hourly timer interval. This should be a lot more flexible for people and give them almost endless options for configuring the timers.[/QUOTE ]

I'm looking forward to seeing how that got implemented. That's really want I wanted to do, but I couldn't figure out a good way to do it. Did separate timers for each update make it into this update as well? I'm finding that's important for me.

[quote]
As a side note, it has occurred to me that by using the cron expression timers this addon could be easily modified to not only do updates, but allow a host of XBMC built in functions to run via a cron scheduler. The 'program' function could let a user setup multiple timers for XBMC functions and the 'service' part could execute them accordingly. Probably not something I'll get to anytime soon though.[/quote]

Oh good. Another project. I was running out of programming projects anyway. Big Grin
find quote
robweber Offline
Posting Freak
Posts: 889
Joined: Sep 2009
Reputation: 27
Post: #48
pkscuot Wrote:I'm looking forward to seeing how that got implemented. That's really want I wanted to do, but I couldn't figure out a good way to do it. Did separate timers for each update make it into this update as well? I'm finding that's important for me.

You can check the code for more details but I was lucky enough to find a public domain CronExpression python class online. I thought the original author had his name on that class file but I see now it isn't, I'll add that for the next commit so he gets credit. This class parsed a regular cron string and then let you check via a check_trigger() command if it should run or not.

As far as the separate timers I did not include them into this update. To be honest I have mixed opinions on this one and thought maybe some other users might be able to comment. I think the updates run fast enough that running both on the same schedule shouldn't be a problem; on the other hand if enough people really want to run things on different schedules than it is worth offering that flexibility.

Any thoughts from the community on this one?
find quote
pkscout Offline
Posting Freak
Posts: 1,088
Joined: Jan 2011
Reputation: 23
Location: Honolulu, HI
Post: #49
I've got updated code based on 0.5.0 that will allow you to run any command that can be run by xbmc.executebuiltin. You can run as many as you want with separate lines in a cron.txt file. The code as well as a patch file for service.py is available at https://github.com/pkscout/service.libra...update.exp. The readme was updated as well just to add an explanation of what I did.

Basically, service.py now looks for cron.txt in the addon's data folder. If it finds one, it loops through each line and runs it through the same logic as the library update and then runs whatever command you stick at the end.

Here's the cron.txt I have right now:
Code:
45 6 * * * RunPlugin(plugin://plugin.video.hulu/?mode='QueueLibrary')
30 6 * * * UpdateLibrary(music)
15 * * * * UpdateLibrary(video)
That runs the Hulu queue update at 6:45am, a music library update at 6:30am, and video library updates 15 minutes after every hour.

This is set as an easter egg right now. There is no setting to enable or disable it, and no way to set a different path for the cron.txt file. That could certainly be done, but for now enabling advanced timers gets you the extra functionality.

I'm pretty sure I could get this to run any command, but given the number of platform specific ways to run native commands, I wasn't sure it was worth it.

I also included some code to create the addon datadir if it doesn't exist. This might not matter if you install the plugin through the XBMC repo (or a zip file), but when I created the plugin directory by hand and put the code in, it generated an error that the datadir wasn't there until I went into the settings. Lastly, I truncated the last_run seconds down to the minute. By doing that, the updates run at the top of the minute rather than sometime during that minute. That's an ADD thing with me. I'll live if that doesn't get incorporated into an actual release. Big Grin
(This post was last modified: 2012-02-11 21:18 by pkscout.)
find quote
rflores2323 Offline
Posting Freak
Posts: 1,920
Joined: Jan 2009
Reputation: 2
Post: #50
Does this work with an atv2 on eden beta3? Also is it possible to update a different profile when in another profile? I have a master profile and then a kids profile. I would like to update both profile libraries (at different times).

Thanks.

ATV1 with crystalbuntu (12.2 frodo) as main theater. Theater remote URC MX-810, droidx with xbmc remote, or transformer tf101 with YATSE. 3 x ATV2 (V12.2 frodo).

find quote
robweber Offline
Posting Freak
Posts: 889
Joined: Sep 2009
Reputation: 27
Post: #51
pkscuot Wrote:I've got updated code based on 0.5.0 that will allow you to run any command that can be run by xbmc.executebuiltin. You can run as many as you want with separate lines in a cron.txt file. The code as well as a patch file for service.py is available at https://github.com/pkscout/service.libra...update.exp. The readme was updated as well just to add an explanation of what I did.

Basically, service.py now looks for cron.txt in the addon's data folder. If it finds one, it loops through each line and runs it through the same logic as the library update and then runs whatever command you stick at the end.

Here's the cron.txt I have right now:
Code:
45 6 * * * RunPlugin(plugin://plugin.video.hulu/?mode='QueueLibrary')
30 6 * * * UpdateLibrary(music)
15 * * * * UpdateLibrary(video)
That runs the Hulu queue update at 6:45am, a music library update at 6:30am, and video library updates 15 minutes after every hour.

This is set as an easter egg right now. There is no setting to enable or disable it, and no way to set a different path for the cron.txt file. That could certainly be done, but for now enabling advanced timers gets you the extra functionality.

I'm pretty sure I could get this to run any command, but given the number of platform specific ways to run native commands, I wasn't sure it was worth it.

I also included some code to create the addon datadir if it doesn't exist. This might not matter if you install the plugin through the XBMC repo (or a zip file), but when I created the plugin directory by hand and put the code in, it generated an error that the datadir wasn't there until I went into the settings. Lastly, I truncated the last_run seconds down to the minute. By doing that, the updates run at the top of the minute rather than sometime during that minute. That's an ADD thing with me. I'll live if that doesn't get incorporated into an actual release. Big Grin

Thanks for the work on this. I actually did a clean install from the repo in XBMC and noticed the addon directory does not get created unless you modify the settings so that piece of code is something that needs to be added for sure. I'll merge most of this into the main release when I get a spare minute (maybe tonight or tomorrow). I like the reading in of the cron.txt file but I think I might just spin that off into a new addon. I'm thinking of some type of GUI interface via the programs area to create the commands - maybe even pre-populate a drop down of xbmc commands.

rflores2323 Wrote:Does this work with an atv2 on eden beta3? Also is it possible to update a different profile when in another profile? I have a master profile and then a kids profile. I would like to update both profile libraries (at different times).

Thanks.

As far as I know this should work like any other addon for the atv2 - it doesn't rely on any additional libraries or anything. I'm using it on Eden Beta 3 as well with no issues. As far as the multiple profile thing I really don't know. I think the UpdateLibrary() built in command will run for whatever user is logged in at the time it runs, but I'll have to check on that one. I read through the wiki quick and couldn't see any additional parameters to specify which profile to run the update for. I'll see what else I can find.

Any devs have any insight into this?
find quote
Martijn Offline
Team Kodi
Posts: 11,444
Joined: Jul 2011
Reputation: 165
Location: Dawn of time
Post: #52
Filled in the basics from the readme on the wiki page for your addon:
http://wiki.xbmc.org/index.php?title=Add...uto_Update

Always read the XBMC online-manual, FAQ and search the forums before posting.
Do NOT e-mail Team-XBMC members asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting, make sure you read this first

For your mediacenter artwork go to
[Image: fanarttv.png]
find quote
robweber Offline
Posting Freak
Posts: 889
Joined: Sep 2009
Reputation: 27
Post: #53
Martijn Wrote:Filled in the basics from the readme on the wiki page for your addon:
http://wiki.xbmc.org/index.php?title=Add...uto_Update

Awesome! Thanks. I'll make a note to update this if anything major changes in way of configuration for the future.
find quote
pacific88 Offline
Junior Member
Posts: 10
Joined: Mar 2010
Reputation: 0
Post: #54
hi Rob,

can you tell me how to edit Library Auto Update to edit/increase the frequency options. I'm running it on appletv so no cron option as far as I know.
find quote
pkscout Offline
Posting Freak
Posts: 1,088
Joined: Jan 2011
Reputation: 23
Location: Honolulu, HI
Post: #55
pacific88 Wrote:hi Rob,

can you tell me how to edit Library Auto Update to edit/increase the frequency options. I'm running it on appletv so no cron option as far as I know.

You don't need cron on the actual device. The plugin just uses a cron expression to determine the update schedule. You can run this every minute if you really wanted to by using:

* * * * *

Check out the readme and do a search for cron to see all the different ways you can setup a schedule.
find quote
pacific88 Offline
Junior Member
Posts: 10
Joined: Mar 2010
Reputation: 0
Post: #56
thanks, pkscuot...

i still couldn't get a cron solution to work so i ended up using this:

http://forum.xbmc.org/showthread.php?p=6...post617324 - a scheduled batch file running on a windows box
find quote
robweber Offline
Posting Freak
Posts: 889
Joined: Sep 2009
Reputation: 27
Post: #57
pacific88 Wrote:thanks, pkscuot...

i still couldn't get a cron solution to work so i ended up using this:

http://forum.xbmc.org/showthread.php?p=6...post617324 - a scheduled batch file running on a windows box

What part of it couldn't you get to work - did the addon simply not use your cron expression?

Having to do crazy hacks, like schedule tasks on another machine, is exactly why this addon exists so getting it to work within XBMC would be a more ideal solution. If you wouldn't mind explaining a little more what you tried; or better yet posting a debug log that would be great. If you do post a log please change the correct settings (ie, switch to 'Advanced' in the timer settings and create your cron expression) then wait for it to run at least 2 cycles before posting the log that would be a big help.

Thanks.
find quote
pkscout Offline
Posting Freak
Posts: 1,088
Joined: Jan 2011
Reputation: 23
Location: Honolulu, HI
Post: #58
Um, I think there is a missing import in the plugin that just got pushed out. After I updated it and restarted I got a script error. Checking the log, it was complaining that the global variable os didn't exist (where you check for the addon data directory's existence). Once I added "import os" to the top of the script the problem went away.
find quote
robweber Offline
Posting Freak
Posts: 889
Joined: Sep 2009
Reputation: 27
Post: #59
pkscuot Wrote:Um, I think there is a missing import in the plugin that just got pushed out. After I updated it and restarted I got a script error. Checking the log, it was complaining that the global variable os didn't exist (where you check for the addon data directory's existence). Once I added "import os" to the top of the script the problem went away.

I noticed that too. I was all pumped to see the addon update and then I saw the error and was ticked that it snuck through like that. I sent a request to the repo for an update so hopefully it gets pushed out soon.

Thanks.
find quote
stevenD Offline
Junior Member
Posts: 35
Joined: Apr 2010
Reputation: 0
Post: #60
I can't get it working either. I get this error in the log:
Code:
20:12:13 T:94728192   ERROR: Error Contents: global name 'timer_amounts' is not defined
20:12:13 T:94728192   ERROR: Traceback (most recent call last):
                                              File "/var/mobile/Library/Preferences/XBMC/addons/service.libraryautoupdate/default.py", line 6, in <module>
                                                AutoUpdater().runProgram()
                                              File "/var/mobile/Library/Preferences/XBMC/addons/service.libraryautoupdate/service.py", line 31, in runProgram
                                                if(time.time() >= self.last_run + (timer_amounts[self.Addon.getSetting('timer_amount')] * 60 * 60)):
                                            NameError: global name 'timer_amounts' is not defined
find quote
Post Reply