Protected 86 Posted July 26, 2024 Posted July 26, 2024 There's a "Size" field available for items inside generic folders in mixed content view, but it rarely works. Is there currently any way to get it to work for every item in every folder, no exceptions? Do I need to make a plugin for it? I don't see any reason why it wouldn't always be possible to calculate the size of the contents of a path in the filesystem.
Luke 42077 Posted July 26, 2024 Posted July 26, 2024 Hi there, why do you feel it rarely works? It is currently only for media items, and is not populated for folders.
Protected 86 Posted July 26, 2024 Author Posted July 26, 2024 That's it exactly! I need it to work for folders too. Show the equivalent of `du -sh PATH`. Can I make a plugin that does that? The Size column already displays the size for folders that Emby *assumes* to be media items, such as a folder with a movie inside, so showing it for every folder should be feasible with the same method it's already using, right? (Oof, I'm rate limited!)
Luke 42077 Posted July 26, 2024 Posted July 26, 2024 Quote Can I make a plugin that does that? Hi, in theory yes.
Protected 86 Posted July 28, 2024 Author Posted July 28, 2024 (edited) Spent some time getting acquainted with the project structure today. This is what I've got so far: https://github.com/Protected/EmbyFolderSize/blob/main/FolderSizePostScanTask.cs It works correctly when you trigger a scan of the library. Takes a moment for the update to become available in the UI, that is, in the next request to the items endpoint (possibly due to caching?) No big deal. However, even though I have real time monitoring enabled for the library, adding or removing files will currently not result in an update of the folder sizes - the videos/whatever will appear and disappear, but I need to manually trigger a scan to update the folder sizes. Is there anything I can do about that from a plugin context? Is there anything I could be doing more efficiently? Sorry some of these threads ended up in the wrong forum, please feel free to move to a more appropriate one. Edited July 28, 2024 by Protected
Luke 42077 Posted July 29, 2024 Posted July 29, 2024 I would probably suggest having the class implementing ICustomMetdataProvider<Folder>, IForcedProvider instead. This way it will run individually for every single folder. And yes - having to do all of these database queries is potentially going to be slow, and it's only going to represent the size of what's imported into the Emby database, not the actual file system size. So I guess whether you get the size from that or by using a file system api is up to you.
Protected 86 Posted July 29, 2024 Author Posted July 29, 2024 (edited) I'm OK with the second problem, but we'll see. Why isn't ILibraryPostScanTaskWithDirectoryService available for autodiscovery? That would have helped. ICustomMetdataProvider wasn't in the wiki or examples I used and I haven't run into it yet when exploring Emby directly but I'll check it out soon. Thanks for the tip! Especially if that fixes the add/remove files problem and no longer requires me to double update the database. EDIT: Also, today's code was written to handle every BaseItem gracefully since I wasn't entirely sure what setups might be used throughout the application. I'm happy to know I can rely on every node to be a Folder! Edited July 29, 2024 by Protected 1
Protected 86 Posted August 3, 2024 Author Posted August 3, 2024 Can't seem to get FetchAsync to run in ICustomMetadataProvider, and I don't understand why. The plugin loads, the provider is instantiated and there are no errors... Is any configuration required? What would be a good way to test it?
Luke 42077 Posted August 3, 2024 Posted August 3, 2024 53 minutes ago, Protected said: Can't seem to get FetchAsync to run in ICustomMetadataProvider, and I don't understand why. The plugin loads, the provider is instantiated and there are no errors... Is any configuration required? What would be a good way to test it? Try refreshing the metadata on an item and then it should run.
Protected 86 Posted August 4, 2024 Author Posted August 4, 2024 I was unable to figure out why it wasn't working - possibly some exception that was being caught somewhere - but it's working now. Here's the implementation as a metadata provider: https://github.com/Protected/EmbyFolderSize/blob/main/FolderSizeMetadataProvider.cs This seems to cover every update case. I tried to minimize database updates, but since there are multiple entry points for a metadata refresh I don't think I can reliably know if the update is part of a larger update that involves other items - or in other words, if I need additional items to be (reliably) updated in the database in every case (which I do, since folder sizes depend on children and affect parents), I must update them myself. 1
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now