Kodi Community Forum

Full Version: Library Auto Updater - Version 1.1.0
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
I did some source code reading to make myself a little more familiar with this. I found a few interesting things. In the Music Scanning area of the code here is the basic order of operations. Keep in mind I'm summarizing multiple C++ classes in a real general form here.

1) Your sources are loaded folder structure enumerated
2) XBMC creates a hash of each folder based on the contents, then compares this to a hash in the DB.
3) If the hashes don't match it decides to scan (or rescan) this folder for new content
4) All songs in this path are removed from the music DB
5) Tag information for all files in the path are scanned into the DB
6) Once all directories are complete artist info, and album info is both cleaned and updated based on the changes

As you can see removing all songs from the DB is part of the scan process. I'm guessing this was done to ensure that any files that were modified, moved, or deleted are captured in the scan. This is inherintly different than video scanning because Album, Artist, Track, etc type information is actually held in the file via the Tag. If all the songs weren't removed each one would have to be hashed and re-checked for changes anyway, this would add more overhead than what is really needed. I guess the prevailing logic here is "if we have to scan the tag on each individual file anyway why have extra DB queries to see if it already exists, then remove it, then add it. why not just remove them all and scan". A good example of why this is important would be track order on an album. If I suddenly realize that track 10 is really track 12 and change the info in the tag, xbmc needs to be able to detect that change and add it to the music db.

Compared to the video library where the basic steps are more like this:

1) Your sources are loaded folder structure enumerated
2) XBMC creates a hash of each folder based on the contents, then compares this to a hash in the DB.
3) If the hashes don't match it decides to scan (or rescan) this folder for new content
4) Each file is checked to see if it is in the DB, if not video info is scraped
5) at the end clean operations are done, if the advanced setting value is enabled

Also, one interesting snippet I found is the following comment. It appears in the video scanner class when sources do not exist

Code:
Note that this will skip clean (if m_bClean is enabled) if the directory really doesn't exist rather than a NAS being switched off.  A manual clean from settings will still pick up and remove it though.

the m_bClean variable is the one set in your advancedsettings.xml file. It appears that if you are doing a clean on update via the advanced settings, and sources do not exist, they are excluded from the clean operation. This is different than an manual clean where nonexistant sources would just be deleted. It is basically the same as the "verify paths" option that exists in this addon. I know it didn't always work this way so this must have been added at some point. Very cool.
Thanks for the information, so that is probably why it simply will never change, is there any work around for this though other then manually updating your library?

I tried that watchdog program on here, but cpu usage doubled, which is not ideal. Also manually doing updates and having to ensure the music hard drive is not asleep every time is also not really ideal, especially with a family that use it.

I dont know if there is anything you would consider such as the verify path before update idea, but its about all I can think of.

At this point i think some of us are left with trying to find solutions around this issue as from your information it was designed that way for a reason.
One other thing I would like to ask, the cron expression for cleaning my library, i changed it, and i dont think its right.

I want it to clean at 10am for video and 10:02 am for music.

So i put 00 10 * * *
and

02 10 * * *

with those spaces....? Im guessing that is not right
1) You updated your ATV2

Just to be clear, I updated XBMC from Eden to Frodo, I never changed any settings within XMBC, it was a straight update. I was already at 5.1.1

2) You have the library update addon set to "clean library after update"

Correct.

3) It ran an automated scan and erased your TV shows and Movies

Over a few nights, repeatedly, re-scanned and removed the library again until i disabled the addon.

4) It appears that your SMB share cannot be accessed via the scanner

It appears so, whats odd is that I can access the share no problem from setting my library paths, but not as you say via the scanner.

If this is correct - did you also have verify sources checked in the clean library settings? If the share can't be found and this is checked it should abort the clean library call. If you didn't have this checked its going to call clean library no matter what, so if xbmc can't see the share for some reason your library is going to be blown away. Also, please confirm you don't have any advanced settings in place that would trigger a library clean anyway.

If I'm honest I don't recall, and I will err on the side of caution and say no it wasn't set, but It does beg the question that why was it working fine previously on Eden with the settings unchanged, but the erasure only came to fruition after the update to Frodo. I have cleaned my libraries in the past with blatant lack of access to the NAS share, never had it erase the complete library.

No advanced settings are configured.
(2013-02-09, 11:29)Ghostdivision Wrote: [ -> ]One other thing I would like to ask, the cron expression for cleaning my library, i changed it, and i dont think its right.

I want it to clean at 10am for video and 10:02 am for music.

So i put 00 10 * * *
and

02 10 * * *

with those spaces....? Im guessing that is not right

Your expressions look correct. Try using one zero instead of two the minutes. So for the music one try 0 10 * * *. Two minutes apart might also be a little tight for times. The clean operation won't run if there is another one running, it will just end up delaying it.

(2013-02-10, 01:51)Exos Wrote: [ -> ]If I'm honest I don't recall, and I will err on the side of caution and say no it wasn't set, but It does beg the question that why was it working fine previously on Eden with the settings unchanged, but the erasure only came to fruition after the update to Frodo. I have cleaned my libraries in the past with blatant lack of access to the NAS share, never had it erase the complete library.

It sounds like something definitely changed between Eden and Frodo in how the clean process is interacting with your shares. I would recommend turning the "verify sources" option on if you want to have this addon automatically clean your library. A good test would be to manually trigger a clean after a clean boot of xbmc and see if your library gets erased then. I know others have seen interesting behavior with the clean operations depending on how they are scheduled. For instance, if a clean runs during a time when xbmc hasn't been used in a while, it could be that your NAS doesn't respond promptly (ie hard drives sleeping) and the shares return has nonexistent. Honestly there are a lot of things that can cause issues with the clean process - it is really a dangerous item to be running unless you're sure stuff is available.

A debug log from a clean boot through a few updates/cleans would be the next step if you want to look into this further.


nvm.
Rob,
Are you planning to put in an option to clean/update based on a folder watchdog? The Watchdog addon does this, seems like a logical feature for your code?
Just to make sure we are on the same page here. By folder watchdog do you mean when specific folders are scanned? In this addon these would be called custom folders under the video menu.

If this is the case then you should already be able to clean the library when these are updated. If you enable clean after video update it will trigger a clean after the folder scan.

Let me know if this is what you were thinking.
A "Watchdog" (aka Watchdog Timer) is a common programming term that refers to any process that watches something then takes action. In this case that something is a folder - thus when the folder changes, the watchdog would see it and trigger a rescans and clean of the library. Thus the trigger is based on an time based event - yes the "timer" part of the name is a bit confusing in this case but it has nothing to do with time.

this is what the Library Watchdog addon does... http://forum.xbmc.org/showthread.php?tid=128896
OK, I kind of figured that is what you meant but wanted to make sure you weren't just applying terms to existing features this addon already has.

I'm familiar with the Watchdog addon and check the official thread for it periodically just to contrast/compare with my own addon. takoi has done a great job with it, and the watchdog functionality is something a lot of people seem to have wanted out of xbmc for quite a long time. As far as I'm concerned our two addons have two completely different goals. The Watchdog addon does just as you've described, and will watch your xbmc folders for changes and trigger the xbmc scanner based on that. This addon works purely off a timer basis and does not poll your sources for information, it simply executes a timer.

I have a few reasons for not having any interest in adding the watchdog type functionality. The first is easy - takoi has already done it with the Watchdog addon. I don't care to create a competing addon. A second would be that I don't personally think it is necessary for an addon to take up I/O doing this type of scanning. The xbmc scanner uses hashes of your folder structure to determine if something has changed on them. When you launch a library scan it will compare these hashes to new ones as it scans the folder, if the hashes match the folder is skipped. Hence, if there is nothing new, the xbmc scanner should only run for a second or two and then go away. Using the cron timer on this addon you can schedule checks pretty much whenever you want (down to a minute interval); so programming a watchdog service to continually poll these folders when the xbmc scanner is pretty efficient at it seems a little redundant to me.
I cant see this addon at service.
Using frodo final
(2013-02-17, 15:07)fernandovg Wrote: [ -> ]I cant see this addon at service.
Using frodo final

Do you mean it isn't under Services in the addons area? It is a service but it shows up under Programs. This is so you can run it manually.
Thanks
(2012-12-31, 20:41)robweber Wrote: [ -> ]
(2012-12-31, 02:09)bigwillch Wrote: [ -> ]Many thanks for the reply. I'll work on getting some logs for you this week (will want to backup first etc.)

My system is a pi running raspbmc (using Quartz Reloaded skin in case that makes any difference). My sources are set up as one 'movies' source with 2 paths, and one 'TV' source with 2 paths.

Sorry the verify sources function is such a pain for you Smile It's incredibly useful though and is much appreciated.

I had a feeling the multipath was an issue. I did some digging and found the source for Multipathed directories in the xbmc source code. When checking if they "exist" it returns true if at least one of the set is available. I can see how this is a valid assumption for viewing purposes but when verifying for a clean operation it doesn't work as expected.

What I did to combat this problem is insert a catch for multipathed sources. It will split the paths and check each one individually. This should take care of the behavior you are seeing. I tested it on my system by creating some multipath sources and then removing them and it worked for me. Changes are in the git repo now, but I'm going to wait until after the New Year for a pull request.

Taken me ages to be able to give this new functionality a go (I had to do a new install to the latest version of xbmc to be able to download the latest versions of addons from the repo). Just wanted to say thanks loads for including it, it works great.
I have a problem that if I enable Update Library on Startup and then try to play a video whilst it it doing the UpdateLibrary() command the video is very choppy. I haven't determined if this is CPU or Network (NFS) bound.

Given that your plugin will delay a library update until 1min after a video has finished will it also cancel/pause an UpdateLibrary command if media is started whilst it is running?
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32