After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 385965 - Should use inotify watch on Library Folder
Should use inotify watch on Library Folder
Status: RESOLVED FIXED
Product: banshee
Classification: Other
Component: Importing
git master
Other Linux
: High enhancement
: 1.6
Assigned To: Alexander Kojevnikov
Banshee Maintainers
papercut
: 421376 486642 530739 532358 539935 547814 554968 556023 581481 (view as bug list)
Depends on:
Blocks: 583933
 
 
Reported: 2006-12-14 20:02 UTC by Rodney Dawes
Modified: 2010-01-25 00:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
rhythmbox-library_watch.png (37.73 KB, image/png)
2007-09-19 10:04 UTC, Pacho Ramos
  Details
First attempt at LibraryWatcher extension. (16.56 KB, patch)
2008-06-19 03:20 UTC, Alex Hixon
none Details | Review
Second attempt at LibraryWatcher extension (76.07 KB, patch)
2009-05-18 17:02 UTC, martellc
none Details | Review
Second attempt at LibraryWatcher extension (patch without Makefile) (15.77 KB, patch)
2009-05-18 17:09 UTC, martellc
needs-work Details | Review
Library Watcher extension for git repository (20.02 KB, patch)
2009-05-20 09:27 UTC, martellc
needs-work Details | Review
Library Watcher extension for git repository (2) (18.89 KB, patch)
2009-05-21 10:07 UTC, martellc
none Details | Review
Library Watcher extension for git repository (3) (18.89 KB, patch)
2009-05-22 07:56 UTC, martellc
none Details | Review
Patch against last patch fixing style issues (9.46 KB, text/plain)
2009-06-02 16:51 UTC, Gabriel Burt
  Details
Updated patch with style fixes (18.59 KB, patch)
2009-06-02 16:52 UTC, Gabriel Burt
needs-work Details | Review
Updated patch, makes one SourceWatcher per LibrarySource, commented out the SearchFor* methods, for now, still needs a lot of work (20.05 KB, patch)
2009-06-03 17:11 UTC, Gabriel Burt
none Details | Review
Simplify some things and add manualResetEvent (19.18 KB, patch)
2009-07-16 23:02 UTC, olivier dufour
needs-work Details | Review
fix the bug of infinite loop, library which do not exist and improove hql for remove (19.50 KB, patch)
2009-07-19 16:35 UTC, olivier dufour
none Details | Review
fixes (24.28 KB, patch)
2009-09-16 12:18 UTC, Alexander Kojevnikov
none Details | Review
next iteration (74.79 KB, patch)
2009-09-19 09:14 UTC, Alexander Kojevnikov
none Details | Review
Updated to git master (74.80 KB, patch)
2009-10-06 06:18 UTC, Alexander Kojevnikov
committed Details | Review

Description Rodney Dawes 2006-12-14 20:02:46 UTC
Banshee should place a filesystem watch on the Library folder, so that items added there from other sources (eMusic, Sound Juicer, etc...) are automatically added to the library.
Comment 1 Jens Knutson 2007-04-15 01:05:43 UTC
I'm not sure if this helps, but Muine already has inotify support - perhaps some code could be lifted from it?
Comment 2 Matt Wheeler 2007-04-25 14:00:12 UTC
I would also like to see this feature added :-)
Comment 3 Pedro Castro 2007-07-02 12:18:43 UTC
Let me add that IMHO this is a key feature in music players. It's common for people to have a single folder where all the music resides (in their respective folders, of course), and it's great when the music player does all the work of detecting when files are added and deleted. This should be done both on startup and during runtime. I think Muine does this the best, from all GNOME music players.
Comment 4 Pacho Ramos 2007-09-19 10:04:30 UTC
Created attachment 95839 [details]
rhythmbox-library_watch.png

Maybe something like "Watch my library for new files" could be interesting in banshee (already available in rhythmbox)...

Thanks :-)
Comment 5 phoenix0down 2008-01-07 08:36:17 UTC
I would like to see this feature added as well. Rhythmbox monitors the assigned music folder very well, but I would much prefer to use Banshee over Rhythmbox...
Comment 6 Pavel Šefránek 2008-01-13 11:40:03 UTC
By the way, older versions of Banshee support this feature via FAM plugin but newer don't. Why? Please add an inotify support!
Comment 7 André Klapper 2008-01-17 15:04:16 UTC
*** Bug 486642 has been marked as a duplicate of this bug. ***
Comment 8 Simone Tolotti 2008-04-19 13:01:48 UTC
Subscribed!
Comment 9 Jakub 'Livio' Rusinek 2008-04-19 13:24:30 UTC
Simone, you can subscribe without saying anything :) .
Just check the option and click "submit".
Comment 10 Gabriel Burt 2008-04-30 15:53:37 UTC
*** Bug 530739 has been marked as a duplicate of this bug. ***
Comment 11 Alexander van Loon 2008-05-01 13:02:06 UTC
Before I filed my bug which was just marked as a duplicate, I searched for an already existing bug report. I didn't find this one because I was looking for bugs in versions 0.98.x and SVN trunk. So could this bug's version please be changed to SVN trunk, because this feature request has yet to be implemented?
Comment 12 Gabriel Burt 2008-05-09 16:57:46 UTC
*** Bug 532358 has been marked as a duplicate of this bug. ***
Comment 13 Gabriel Burt 2008-05-27 21:47:32 UTC
I hear that tangerine and muine had this implemented pretty nicely.   Should probably at least look at their code and see if we can mimick it.
Comment 14 Alex Hixon 2008-05-28 07:46:31 UTC
Thanks Gabriel. I'll have a check of their code.
I do already have an idea on how I'll implement it, though. :)
Comment 15 Mohamed Bana 2008-06-06 23:33:29 UTC
Honestly banshee would be perfect if it could watch folders and also update the metadata, it's really frustrating that it doesn't even update the metadata when i re-import the folder (without deleting the contents of the library, that is).  From the top of my head 3 well known players already support this feature, rhythmbox,exaile and amarok.

PLEASE have this up by the next release.
Comment 16 Mohamed Bana 2008-06-06 23:35:33 UTC
(In reply to comment #3)
> Let me add that IMHO this is a key feature in music players. It's common for
> people to have a single folder where all the music resides (in their respective
> folders, of course), and it's great when the music player does all the work of
> detecting when files are added and deleted. This should be done both on startup
> and during runtime. I think Muine does this the best, from all GNOME music
> players.
> 

I echo the same words.  "Let me add that IMHO this is a key feature in music players."
Comment 17 Alex Hixon 2008-06-07 04:43:52 UTC
Mohamed, as defined by the target milestone for this bug, we're targetting 1.x. This extension will more than likey ship in 1.1 (1.0 has already been branched, tarballs generated, and packaged by most maintainers).

It will be added when we feel it is ready and relatively stable.
Expect a patch soon from me, though. It works nicely, though, it's still missing metadata refresh if the file is modified from an external application.

Gabriel, code review next week (after we ship)? :)
Comment 18 Jakub 'Livio' Rusinek 2008-06-07 07:26:20 UTC
it seems that banshee 1.0.0 was released - packages for openSUSE 10.3 and 11.0 are ready in banshee (not banshee:preview anymore) repository.
Comment 19 David Joaquim 2008-06-15 13:58:05 UTC
It may be interresting to use tracker or beagle as backend, as they are designed to provide such features.  
Comment 20 Alex Hixon 2008-06-19 03:20:57 UTC
Created attachment 113019 [details] [review]
First attempt at LibraryWatcher extension.

Attached is my version of the LibraryWatcher extension (and small patch to some of the Banshee DatabaseTrackInfo stuff). It imports and removes files from both music and video libraries in realtime.

At the moment, the only unimplemented feature is refreshing track metadata if it's edited from an external application (tag editors, another music player, etc).
Comment 21 Bertrand Lorentz 2008-06-24 19:09:36 UTC
*** Bug 539935 has been marked as a duplicate of this bug. ***
Comment 22 Andrew Conkling 2008-07-10 19:35:28 UTC
*** Bug 421376 has been marked as a duplicate of this bug. ***
Comment 23 roberth.sjonoy 2008-08-12 15:58:11 UTC
Whats the progress of this enchancement?
Comment 24 Mohamed Bana 2008-08-12 16:13:38 UTC
Does this patch updata metadata aswell?
Comment 25 roberth.sjonoy 2008-08-12 18:03:04 UTC
This patch is outdated.
Comment 26 Alex Hixon 2008-08-12 21:45:27 UTC
Mohamed: Yes, if you edit metadata externally it should update.

I haven't updated this patch to work against trunk because apparently Aaron is working on a similar plugin (according to Gabriel), and, well, it's been about two months without a code review. I don't particularly feel like updating a patch every 2 weeks for something that isn't going to get applied. :)

If somebody wants to fix it up, feel free! It shouldn't be too difficult, I don't think.
Comment 27 Alex Hixon 2008-08-12 21:46:28 UTC
Also, could someone poke Aaron about the status of his version of this extension?
Comment 28 Mohamed Bana 2008-08-12 22:27:33 UTC
(In reply to comment #26)
> Mohamed: Yes, if you edit metadata externally it should update.
> 
> I haven't updated this patch to work against trunk because apparently Aaron is
> working on a similar plugin (according to Gabriel), and, well, it's been about
> two months without a code review. I don't particularly feel like updating a
> patch every 2 weeks for something that isn't going to get applied. :)
> 
> If somebody wants to fix it up, feel free! It shouldn't be too difficult, I
> don't think.
> 

Just for confirmation assume I've got song.mp3 with artist="banshee", that has been added to the library.  If I change the artist name (or any tag for that matter) externally to say,artist="gnome", banshee will detect it right?  I'm asking because i've heard else where that the updating the metadata will be handled in a different patch.

Thanks
Comment 29 Scott Peterson 2008-08-13 00:19:34 UTC
Aaron offloaded a patch to me about this. I've been really busy of late and haven't had time to finished it. I'll try to do this before the weekend, but if I don't get around to it, maybe someone else should take the torch.
Comment 30 roberth.sjonoy 2008-08-13 00:53:41 UTC
AFAIK, this si a very much wanted enchancement, so I think a lot of people would be happy if some took the torch and decided to finish it so it can appear in 1.4.
Comment 31 Alex Hixon 2008-08-13 06:27:09 UTC
(In reply to comment #28)
> (In reply to comment #26)
> > Mohamed: Yes, if you edit metadata externally it should update.
> > 
> > [snip]
> 
> Just for confirmation assume I've got song.mp3 with artist="banshee", that has
> been added to the library.  If I change the artist name (or any tag for that
> matter) externally to say,artist="gnome", banshee will detect it right?  I'm
> asking because i've heard else where that the updating the metadata will be
> handled in a different patch.
> 
> Thanks
> 

Erk, my bad. Looking at the code, I don't appear to have implemented this. Shouldn't be too difficult either.

Scott, any chance you could post the patch somewhere public anyhoo? More eyeballs; plus, it means less work for you. :)
Comment 32 Andrew Conkling 2008-08-14 23:17:58 UTC
*** Bug 547814 has been marked as a duplicate of this bug. ***
Comment 33 Andrew Conkling 2008-08-14 23:21:28 UTC
As implied in bug 547814, care should definitely be taken for moved files and their metadata (especially ratings and play count, as those cannot be written back to the file).

That's a current limitation of Rhythmbox's library monitoring (if you rename a file, you reset your play count and lose your rating). It would be nice to address this somehow.
Comment 34 Gabriel Burt 2008-08-14 23:28:59 UTC
As of today there is a MetadataHash column in the database (and atm protected property on DatabaseTrackInfo) that could be useful in identifying a track even if it's moved.  It's a MD5 hash of the title/artist/album/genre/duration/year.  I plan on using it for device syncing, but might be useful for this too.
Comment 35 Alex Hixon 2008-08-14 23:49:47 UTC
Andrew, Gabriel; at the moment, the current logic for dealing with moved files is to simply update the path column in the database. This means all the other data relating to that file is left the same.
Comment 36 roberth.sjonoy 2008-09-03 18:00:58 UTC
Any update?
Comment 37 Pavel Šefránek 2008-09-03 18:13:27 UTC
Only zilions of new CCs
Comment 38 Alex Hixon 2008-09-08 06:32:46 UTC
Could Aaron or Gabriel please give us a status update? :)
Optionally, some sort of mention in the next PPP roundup. I'd like to get some progress moving on this bug; I personally don't care whose code we end up using, as long as we're actively moving forwards. I'm happy to cleanup my patch and commit if that's what we want.
Comment 39 Andrés G. Aragoneses (IRC: knocte) 2008-09-13 16:58:25 UTC
I guess this bug [1] is also blocking this feature.
[1] https://bugzilla.novell.com/show_bug.cgi?id=425468
Comment 40 Greg Auger 2008-09-13 17:03:23 UTC
This is in the recently released Banshee 1.3.0 development release: http://download.banshee-project.org/banshee/banshee-1-1.3.0.news
Comment 41 Gabriel Burt 2008-09-13 19:07:41 UTC
(In reply to comment #40)
> This is in the recently released Banshee 1.3.0 development release:
> http://download.banshee-project.org/banshee/banshee-1-1.3.0.news
 
Only partially.  What's in the release is a way to manually trigger a rescan (see Tools->Rescan).  Having it triggered by inotify is still TODO.
Comment 42 Andrew Conkling 2008-10-04 12:34:12 UTC
*** Bug 554968 has been marked as a duplicate of this bug. ***
Comment 43 Gabriel Burt 2008-10-12 15:47:26 UTC
*** Bug 556023 has been marked as a duplicate of this bug. ***
Comment 44 ntetreau 2008-10-21 06:59:39 UTC
Any news on this MUCH needed feature?  Freeze is coming and the 1.4 release seems only a few weeks away... can I just reiterate that this feature is really important for the adoption of Banshee in the wider community.  In my experience, this is the missing feature which is the used the most when arguing against the use of Banshee (as default in Ubuntu for example).

Keep up the good work
Comment 45 Simone Tolotti 2009-02-13 18:56:34 UTC
Two years and two moths later... new version released (1.4.2) but still missing this feature.
It's the only (but the biggest) thing stopping me to leave Rhythmbox.
Comment 46 Andrew Conkling 2009-03-30 14:23:42 UTC
Bumping the target; 1.2 has come and gone.
For what it's worth, the benefit of Banshee's functionality is that Rhythmbox, when updating on startup, can take a lot of time and CPU/disk activity, so you can't always play your music right away.
I'd love to see this feature too, but it's not without its own consequences.
Alex, should this still be assigned to you? Looks like you were awaiting feedback from Aaron and Gabriel in comment 38?
Comment 47 Jean-Francois Lepage 2009-03-30 14:33:49 UTC
+1
this is a must feature!! :)
Comment 48 Jean-Francois Lepage 2009-04-04 02:46:44 UTC
> For what it's worth, the benefit of Banshee's functionality is that Rhythmbox,
> when updating on startup, can take a lot of time and CPU/disk activity, so you
> can't always play your music right away.
 
What's waiting 10s if you can get all your added songs! :)

Also, I am refering to a realtime feature! Like when you drag/drop a song in WMP (yeah yeah...buggy...bla..bla...bla lol)! :)
Comment 49 Alex Hixon 2009-04-04 02:55:10 UTC
I should probably mention the only overhead that'd be caused by this is the time to register the inotify watch. From memory, Rhythmbox actually rescans all the files in its library at startup to see if they're all still there (and update it's metadata?), then does the inotify stuff. So, yes, that's why it takes a bit longer.

Andrew, yes, still awaiting feedback.
Comment 50 Nuno Khan 2009-04-12 16:41:27 UTC
yeah i started using banshee but without this feature im afraid ill have to go back to rythmbox
Comment 51 Andrew Conkling 2009-04-15 15:14:58 UTC
(In reply to comment #48)
> > For what it's worth, the benefit of Banshee's functionality is that Rhythmbox,
> > when updating on startup, can take a lot of time and CPU/disk activity, so you
> > can't always play your music right away.
> 
> What's waiting 10s if you can get all your added songs! :)

I don't know; the Rescan action as currently implemented in Banshee takes a lot longer than 10s for me.... :)

Also, with the job scheduler being implemented in Banshee (http://gburt.blogspot.com/2009/04/putting-banshee-to-work.html) this could theoretically be implemented with less impact on the UI while it runs. I'm not sure about that, as it'd still be a big design decision, but perhaps that would make it more likely to be implemented.
Comment 52 Jean-Francois Lepage 2009-04-15 15:31:31 UTC
well, it's too bad but I removed Banshee and now use Rhythmbox, which can play a song that you just downloaded without having to close it or rescan! ;)
Comment 53 martellc 2009-04-20 16:40:51 UTC
I restart working on the banshee library watcher, a plugin to auto-update music & video library using Inotify.

Take a look at http://code.google.com/p/bansheelibrarywatcher/ or download it from svn: 
svn checkout http://bansheelibrarywatcher.googlecode.com/svn/trunk/ bansheelibrarywatcher-read-only  

The plugin is yet a bit slow and I'm working to speed it up. Test/bug reports/suggestions are welcome. (contact me at christian.martellini@gmail.com)

Cheers
Comment 54 Alex Hixon 2009-04-21 08:35:29 UTC
martellc: in my honest opinion, it'd probably be faster and easier just to clean up the last patch I posted, instead of duplicating effort. But whatever you feel is easier. :)
Comment 55 martellc 2009-04-21 10:27:38 UTC
Alexander:I saw your patch marked as obsolete so I thought it didn't worth to work on it. My mistake.
I wouldn't discuss of duplicating effort, I think that clean my old plugin or clean your patch are both easier the same..Anyway I will take a look at your patch :)
Thanks for your prompt answer.
Comment 56 Gabriel Burt 2009-05-05 16:11:46 UTC
*** Bug 581481 has been marked as a duplicate of this bug. ***
Comment 57 Mike Rooney 2009-05-07 08:02:20 UTC
While implementing this it would be great to try to get right a thing or two that competitors such as rhythmbox don't. The main issue rb has is that if you start a music torrent, most of the files won't get picked up until a restart since parts of them (particularly the first I imagine) are invalid. In cases where a new file appears but isn't valid, it might be good to store in memory when this happened, and if the file is later modified after this, give it another shot (with some minimum timeout before a second try).

Ubuntu is considering adopting Banshee as the default media player but I suspect this issue will be one of the main points of contention, as others have suggested, as users are already used to having this functionality and would as such consider this a major regression.

Anyway, keep up the great work!
Comment 58 martellc 2009-05-18 17:02:41 UTC
Created attachment 134881 [details] [review]
Second attempt at LibraryWatcher extension

This is a second attempt to a LibraryWatcher extension for banshee. I merged the old code from Alex Hixon first attempt with my Banshee Watcher plugin.. I think It's a good results... It works good with both 1.4.3 and 1.5.0 version.
If you don't like patchs you can download it from svn:
svn checkout http://bansheelibrarywatcher.googlecode.com/svn/trunk/ bansheelibrarywatcher-read-only

Cheers,
Christian
Comment 59 martellc 2009-05-18 17:09:00 UTC
Created attachment 134882 [details] [review]
Second attempt at LibraryWatcher extension (patch without Makefile)
Comment 60 Gabriel Burt 2009-05-18 18:59:33 UTC
Thanks for your work, guys, I appreciate it.  Here are a bunch of nitpicks:

Put a comma between your names in the addin.xml

Consistently use 4 spaces for tabs.

There are lines like this -
"private   bool   forceUpdate;"
- please use just a single space instead of multiple spaces between keywords/etc.

Please put a single space between a method name and its arg list, eg this () not this().  See HACKING for the full style guide.

Please put copyright headers at the top of all .cs files.

Instead of doing a thread Abort () to stop the watcher, it would probably be better to just exit the watcher() method loop.  Also, rename the watcher method to Watcher.

Please update to work against 1.5/git master only - we no longer use relative URIs at all in CoreTracks, so I don't think it's possible or at least reasonable to try to support both.

"Lybrary Watcher Plugin" => typo

Thanks!
Comment 61 martellc 2009-05-20 09:27:40 UTC
Created attachment 135006 [details] [review]
Library Watcher extension for git repository

- Updated library watcher extension to work with banshee git revision and to be compliant with banshee style guide.
Comment 62 Bertrand Lorentz 2009-05-20 21:58:40 UTC
Thanks for updating the patch !

Another round of nitpicks : ;)
- Don't include Banshee.LibraryWatcher.pidb in the patch, it causes an error and applying the patch fails.

- There are a couple of tabs left, in the beginning of the LibraryWatcherService class, and other places.

- In the build system files, try to add lines in the proper place when things are sorted alphabetically : configure.ac, build.environment.mk, src/Extensions/Makefile.am

- The "Lybrary Watcher Plugin" typo is still there

- Remove the "using Banshee;" lines, they're useless

- Remove the "Log.Debug ..." call in IExtensionService.Initialize, the extension startup is logged by the ServiceManager.

- Same thing for the try/catch in IExtensionService.Initialize : the ServiceManager catches and logs any exception from it.

- Maybe this extension could be a IDelayedInitializeService, like PodcastService ? This would prevent any increase in the visible startup time of banshee.

- I'm not sure about OnServiceStarted : it adds an event handler each time it's called, and I think OnSourceAdded ends up being called several times for each SourceAdded event.
Comment 63 martellc 2009-05-21 10:07:37 UTC
Created attachment 135077 [details] [review]
Library Watcher extension for git repository (2)

- Removed the pidb file
- Added tabs where missed
- lines added in the proper place inside the system files
- Changed "Library Watcher Plugin" in "LibraryWatcherService"
- Removed the "using Banshee;" lines
- Removed "Log.Debug ..." and try/catch
- Implemented the Library Watcher as a delayed service

Ready for round 3 :P
Comment 64 Mike Rooney 2009-05-21 16:10:41 UTC
Good to see the patch being updated, but isn't "Lybrary" still a typo?
Comment 65 Wouter Bolsterlee (uws) 2009-05-21 22:27:08 UTC
(In reply to comment #60)
> "Lybrary Watcher Plugin" => typo

(In reply to comment #62)
> - The "Lybrary Watcher Plugin" typo is still there

(In reply to comment #64)
> Good to see the patch being updated, but isn't "Lybrary" still a typo?


(/me puts i18n hat on)

Guys, instead of repeatedly stating that there is a misspelling it would probably make much more sense to point out the correct spelling instead of repeating the same over and over again ("it's still wrong!"). Please keep in mind many contributors do not speak English as their first language, which implies that obvious mistakes may not be obvious at all for some of us. It can be quite demotivating to only point out mistakes people do not immediately see themselves; it's much more productive to be constructive and tell them how the mistake should be corrected. That said...

martellc: it should read "Library", not "Lybrary". Thanks for your work!
Comment 66 martellc 2009-05-22 07:56:35 UTC
Created attachment 135161 [details] [review]
Library Watcher extension for git repository (3)

I'm sorry , I thought I Corrected the typo, but I did it again... :(
The last patch really fix it.
Comment 67 Gabriel Burt 2009-06-02 16:51:19 UTC
Created attachment 135828 [details]
Patch against last patch fixing style issues
Comment 68 Gabriel Burt 2009-06-02 16:52:11 UTC
Created attachment 135829 [details] [review]
Updated patch with style fixes
Comment 69 Gabriel Burt 2009-06-02 17:04:00 UTC
There are some other changes that need to happen before I'll be happy with this solution:

1) Now that each LibrarySource has its own BaseDirectory, we should create a watcher for each.  This also means we don't have to know or care if there is a music library etc - we can just watch all LibrarySources (which will include Podcasts).  We can still have one watch_thread, but we'll have multiple FileSystemWatchers.

2) I'm not keen on the

SearchForDeletedSongs ();
SearchForNewSongs ();

that are triggered every time there is a file rename, and on startup.  This is a very expensive operation.  And, if we're going to do it at all, we should reuse or merge this with the Rescan functionality.  And, for renames, can't we avoid this rescan entirely?  Keep in mind our 'Update file and folder names' option; it can trigger many many renames.

3) Instead of polling every 400ms to see if there are changes, we should use a ManualResetEvent or similar to sleep until there is something to do.

4) I believe calling "import_manager.KeepUserJobHidden = true;" will prevent the UserJob for regular importing from appearing too, which obviously isn't ok.
Comment 70 Gabriel Burt 2009-06-03 17:11:08 UTC
Created attachment 135891 [details] [review]
Updated patch, makes one SourceWatcher per LibrarySource, commented out the SearchFor* methods, for now, still needs a lot of work
Comment 71 Mohamed Bana 2009-07-04 18:50:24 UTC
this is the only thing holding me from switching completely from Rhythmbox.
Comment 72 olivier dufour 2009-07-16 23:02:30 UTC
Created attachment 138564 [details] [review]
Simplify some things and add manualResetEvent

I have change the system to a ManualResetEvent and some work to simplify code and avoid full reload!
Comment 73 Bertrand Lorentz 2009-07-18 16:59:11 UTC
Here's a problem I found while testing the latest patch :
After adding or deleting a file in my library folder (with cp or rm), banshee started using about 50% CPU until I quit it. Here the relevant part of my log output :

[Debug 18:49:16.447] Delayed Initializating Banshee.LibraryWatcher.LibraryWatcherService
relative = Music/Library/
[Debug 18:49:16.453] Started LibraryWatcher for Music (/home/lorentz/Music/Library/)
relative = Videos/
[Debug 18:49:16.454] Started LibraryWatcher for Videos (/home/lorentz/Videos/)
relative = Music/Podcasts/
[Debug 18:49:16.455] Started LibraryWatcher for Podcasts (/home/lorentz/Music/Podcasts/)
[Debug 18:49:16.465] Delayed Initializating Banshee.MediaEngine.PlayerEngineService
[Debug 18:49:16.511] (libbanshee:player) Using system (gst-plugins-good) equalizer element
[Debug 18:49:16.621] Player state change: NotReady -> Ready
[Debug 18:49:16.636] Enabling equalizer preset: New Preset
[Debug 18:49:16.642] Player state change: Ready -> Idle
[Debug 18:49:16.644] (libbanshee:player) Enabled ReplayGain
[Debug 18:49:16.660] (libbanshee:player) scaled volume: 1.000000 (ReplayGain) * 0.790000 (User) = 0.790000
[Debug 18:49:17.376] Starting - Downloading Cover Art
[Debug 18:49:17.378] Finished - Downloading Cover Art
[Debug 18:49:24.634] Starting - Saving Metadata to File
[Debug 18:49:24.640] Finished - Saving Metadata to File
OnDeleted /home/lorentz/Music/Library/06  Madonna - She's Not Me.mp3
[Debug 18:49:54.144] Starting - Downloading Cover Art
[Debug 18:49:54.146] Finished - Downloading Cover Art
[Debug 18:49:54.151] Starting - Saving Metadata to File
[Debug 18:49:54.157] Finished - Saving Metadata to File
[Debug 18:49:54.886] Starting - Downloading Cover Art
[Debug 18:49:54.896] Finished - Downloading Cover Art
[Debug 18:49:54.902] Starting - Saving Metadata to File
[Debug 18:49:54.908] Finished - Saving Metadata to File
[Debug 18:49:55.670] Starting - Downloading Cover Art
[Debug 18:49:55.671] Finished - Downloading Cover Art
[Debug 18:49:55.676] Starting - Saving Metadata to File
[Debug 18:49:55.681] Finished - Saving Metadata to File
[Debug 18:49:56.498] Starting - Downloading Cover Art
[Debug 18:49:56.505] Finished - Downloading Cover Art
[Debug 18:49:56.510] Starting - Saving Metadata to File
[Debug 18:49:56.516] Finished - Saving Metadata to File

The last 4 lines are repeated several times per second until I quit banshee.
I guess banshee somehow gets stuck in a loop.
Comment 74 olivier dufour 2009-07-19 16:35:36 UTC
Created attachment 138742 [details] [review]
fix the bug of infinite loop,  library which do not exist and improove hql for remove

fix the bug of infinite loop,  library which do not exist and improove hql for remove
Comment 75 Alexander Kojevnikov 2009-09-16 12:18:54 UTC
Created attachment 143267 [details] [review]
fixes

Still work in progress.

Apparently a major bug in Mono breaks the watcher in some scenarios, see bnc#322330 [1]. In particular, moving files within the library and renaming folders don't work at all.

I will try to find a workaround...

[1] https://bugzilla.novell.com/show_bug.cgi?id=322330
Comment 76 olivier dufour 2009-09-18 08:11:51 UTC
I read your patch and think to 2 things to improove it:

- the system to remove special char from query to DB must be centralize in an util function as DbEscape (string str) {...}. (Maybe there is ever a such function somewhere?)

- Why add a timer of 2 sec? file have handle on it?
if yes, I am not sure it will be ok for a big file. Maybe there is a solution by trying action and if not work requeue...

else good patch (readonly on param OK / remove 3 List and add queue is great)
Comment 77 Alexander Kojevnikov 2009-09-18 08:56:55 UTC
(In reply to comment #76)
> - the system to remove special char from query to DB must be centralize in an
> util function as DbEscape (string str) {...}. (Maybe there is ever a such
> function somewhere?)

Good idea. StringQueryValue is doing the same escaping, I will move to StringUtil.


> - Why add a timer of 2 sec? file have handle on it?
> if yes, I am not sure it will be ok for a big file. Maybe there is a solution
> by trying action and if not work requeue...

No, it's not because of locking. The events are actually triggered after successful file operations.

When the automatic file rename option is set and the track metadata is changed, the SaveTrackMetadataService first renames the file and then updates the database record with the new Uri. The queue delay ensures there's no conflict between the watcher and the metadata service.

I also checked the source code of Beagle and they use a delay to improve the tracking performance. It's only 50ms in their case, but it doesn't really matter as queue processing and event handling are in different threads.

Finally, the FileSystemWatcher never triggers OnRename event if a file/folder was moved to another folder. It's by design, if you check the RenamedEventArgs source code, you will see that it has a base path, and two file names. I'm currently not combining delete+create events as a single rename event, but I plan to, and the delay allows us to do it.

On a side note, I nearly finished fixing bnc#322330, I will keep you all updated on the progress.
Comment 78 Alexander Kojevnikov 2009-09-19 09:14:51 UTC
Created attachment 143479 [details] [review]
next iteration

I managed to fix bnc#322330 [1], at least in my unscientific tests.

Now I'm not sure what to do with the fix. Even if it works well and gets committed soon, it will take at least a few months before it's in the next stable version of Mono, and several months before we can make it the minimum required version.

In this patch I bundled the patched version of InotifyWatcher and its dependencies and use is instead of the Mono version (but only under Linux). I know it's an ugly hack, but it works and allows to further test the extension. I'm open for suggestions on how to handle this elegantly.

That aside, the watcher works for the following scenarios:

 * Adding, deleting, renaming, and moving files and folders within the watched libraries will update the database. When moving/renaming the metadata such as ratings and scores should be preserved.
 * If the 'update file and folder names' option is on, the names are updated back to the defined schema.
 * Changing metadata using an external editor updates the database.
 * Moving tracks out of the watched folders will delete them from the database.

I'm 100% sure I missed some ways in which the library folder can be abused, so I encourage everyone to give the patch a try and report back.

Be sure to backup your media files and the database before you do!

[1] https://bugzilla.novell.com/show_bug.cgi?id=322330
Comment 79 Alexander Kojevnikov 2009-10-06 06:18:33 UTC
Created attachment 144873 [details] [review]
Updated to git master

Just a quick note that the fix to bnc#322330 has been committed to the trunk and to the 2.4.x and 2.6.x branches. The bundled version of the InotifyWatcher can be removed as soon as Banshee has Mono 2.4.3+ as a dependency.
Comment 80 Gabriel Burt 2009-10-27 20:16:35 UTC
Bulk changing the assignee to banshee-maint@gnome.bugs to make it easier for people to get updated on all banshee bugs by following that address.  It's usually quite apparent who is working on a given bug by the comments and/or patches attached.
Comment 81 Alexander Kojevnikov 2009-11-16 23:43:13 UTC
Review of attachment 144873 [details] [review]:

I pushed the patch to the 'watcher' branch.
Comment 82 Alexander Kojevnikov 2009-11-16 23:43:19 UTC
Review of attachment 144873 [details] [review]:

I pushed the patch to the 'watcher' branch.
Comment 83 Alexander Kojevnikov 2009-11-16 23:43:20 UTC
Review of attachment 144873 [details] [review]:

I pushed the patch to the 'watcher' branch.
Comment 84 Alexander Kojevnikov 2009-11-16 23:43:24 UTC
Review of attachment 144873 [details] [review]:

I pushed the patch to the 'watcher' branch.
Comment 85 Gabriel Burt 2010-01-20 20:10:40 UTC
I've merged the watcher branch into git master.  I disabled the extension by default until we get some wider testing and polish.  Thanks so much Alexander, everybody who helped!