2007-02-26, 21:36
Hi there,
I've implemented a small feature to enable the use of wildcards in thumbnail names. It's currently running on my own Xbox for testing, but I'd like to submit the patch. Before I do so I'd like to solicit opinions on the feature, and ask an API question.
The itch I'm trying to scratch with this feature relates to a "now playing" type of folder: somewhere that holds current episodes of shows for a few days before I watch them and delete them. The contents are therefore fairly dynamic and the individual files require different thumbnails. Adding a new thumbnail for each new file is onerous, and since my computer is here to do things I can't be bothered to do, I want XBMC to work out which thumbnail is appropriate for me.
I have a subfolder (alongside the video files themselves) called "wildcards.tbn". (This is the magic directory that enables the behaviour.) It contains tbn files which may have wildcard characters (I use ~, the tilde) in their names. A tilde means "0 or more characters here", and therefore "Consolevania~.tbn" would be expected to match against, say, "Consolevania 208 twoLate.avi". (A run of N+1 tildes means "N or more characters here"; that's as complex as I've let it get.)
I've modified 'FileItem::GetTBNFile'. After trying the usual thumbnail names, if the fallback "VideoFileName.tbn" doesn't exist we now look for "wildcards.tbn". If that subfolder isn't there, we do nothing more -- users without the magic folder are unaffected by this change beyond that first test. If the folder is there, we consider the contents and try to match each tbn pattern against the target file. I thought about using a regular expression for this but it's really overkill (to escape and transform each filename, then run the regex) when a custom algorithm based on a simple string split does just as well.
Questions:
1. (An API question.) Is 'CDirectory::GetDirectory' guaranteed to give me a listing sorted by name? It's helpful if that's the case, as tbn files starting with the wildcard will therefore appear last, and if "~.tbn" exists as a custom fallback (or "~.avi.tbn" and "~.mpg.tbn" for type-specific fallbacks) it won't be prioritised over a more specific pattern which matches the start of the name.
2. Any suggestions for a better magic folder name? I wanted to use ".wildcards.tbn" (with a leading dot), but Windows Explorer doesn't like letting me create such a name. I can do it at a command prompt of course, but creation of the magic folder should be easy for everyone. I chose to use the tbn extension for consistency with thumbnail fails, and to reduce the likelihood that anybody would have a real folder with this name.
3. Can the magic folder be hidden if it exists? I don't know how to do that... presumably there's a point where 'GetDirectory' is called with a list of appropriate file extensions, and it would have to be removed after that point. (being a folder, the extensions mask presumably doesn't apply). Can somebody tell me where to look? _Should_ the folder be hidden? The only reason I can think of not to is that it might legitimately be a folder containing media -- hence my earlier question about a good name. If the user has created it with the intention of using this feature, he surely doesn't need to see it through the xbmc interface.
4. Am I able to post the patch here for review? (Can I attach it to this post? Is there a bbcode tag for quoting code which doesn't throw bits away?) I haven't coded C in a few years (I had to type the algorithm out in Python and translate it line by line while my brain got used to translating thought into C code) so I may be doing something sub-optimal, or using a poor coding style. (At least I know that the code works!) I'd really appreciate feedback and advice!
A note on performance: as you'd expect, this is slower than the usual thumbnail code. That's one of the reasons that it's "opt-in", by way of the magic subfolder. (Another reason for the subfolder is ease of thumbnail management: they're all in one place and don't get in the way of the actual media files when using a PC to browse.) Without the magic folder, this shouldn't slow anybody down. With the behaviour enabled for the first time, there's a brief pause as all of the thumbnails are found. Re-visiting a folder is much quicker since each thumbnail has now been cached. Thumbnails still have to be found (but just once, of course) when new media is added. For day-to-day use, the biggest impact will probably be made by those media files which aren't matched by a wildcard thumbnail, since we'll check all the thumbnails for them every time. This can be mitigated by either using a catch-all default ("~.tbn" to match anything) which will be cached, or by maintaining an up-to-date set of thumbnails for all the series likely to be passing through the folder.
Does anybody have any comments, suggestions or objections?
Thanks,
Steve
I've implemented a small feature to enable the use of wildcards in thumbnail names. It's currently running on my own Xbox for testing, but I'd like to submit the patch. Before I do so I'd like to solicit opinions on the feature, and ask an API question.
The itch I'm trying to scratch with this feature relates to a "now playing" type of folder: somewhere that holds current episodes of shows for a few days before I watch them and delete them. The contents are therefore fairly dynamic and the individual files require different thumbnails. Adding a new thumbnail for each new file is onerous, and since my computer is here to do things I can't be bothered to do, I want XBMC to work out which thumbnail is appropriate for me.
I have a subfolder (alongside the video files themselves) called "wildcards.tbn". (This is the magic directory that enables the behaviour.) It contains tbn files which may have wildcard characters (I use ~, the tilde) in their names. A tilde means "0 or more characters here", and therefore "Consolevania~.tbn" would be expected to match against, say, "Consolevania 208 twoLate.avi". (A run of N+1 tildes means "N or more characters here"; that's as complex as I've let it get.)
I've modified 'FileItem::GetTBNFile'. After trying the usual thumbnail names, if the fallback "VideoFileName.tbn" doesn't exist we now look for "wildcards.tbn". If that subfolder isn't there, we do nothing more -- users without the magic folder are unaffected by this change beyond that first test. If the folder is there, we consider the contents and try to match each tbn pattern against the target file. I thought about using a regular expression for this but it's really overkill (to escape and transform each filename, then run the regex) when a custom algorithm based on a simple string split does just as well.
Questions:
1. (An API question.) Is 'CDirectory::GetDirectory' guaranteed to give me a listing sorted by name? It's helpful if that's the case, as tbn files starting with the wildcard will therefore appear last, and if "~.tbn" exists as a custom fallback (or "~.avi.tbn" and "~.mpg.tbn" for type-specific fallbacks) it won't be prioritised over a more specific pattern which matches the start of the name.
2. Any suggestions for a better magic folder name? I wanted to use ".wildcards.tbn" (with a leading dot), but Windows Explorer doesn't like letting me create such a name. I can do it at a command prompt of course, but creation of the magic folder should be easy for everyone. I chose to use the tbn extension for consistency with thumbnail fails, and to reduce the likelihood that anybody would have a real folder with this name.
3. Can the magic folder be hidden if it exists? I don't know how to do that... presumably there's a point where 'GetDirectory' is called with a list of appropriate file extensions, and it would have to be removed after that point. (being a folder, the extensions mask presumably doesn't apply). Can somebody tell me where to look? _Should_ the folder be hidden? The only reason I can think of not to is that it might legitimately be a folder containing media -- hence my earlier question about a good name. If the user has created it with the intention of using this feature, he surely doesn't need to see it through the xbmc interface.
4. Am I able to post the patch here for review? (Can I attach it to this post? Is there a bbcode tag for quoting code which doesn't throw bits away?) I haven't coded C in a few years (I had to type the algorithm out in Python and translate it line by line while my brain got used to translating thought into C code) so I may be doing something sub-optimal, or using a poor coding style. (At least I know that the code works!) I'd really appreciate feedback and advice!
A note on performance: as you'd expect, this is slower than the usual thumbnail code. That's one of the reasons that it's "opt-in", by way of the magic subfolder. (Another reason for the subfolder is ease of thumbnail management: they're all in one place and don't get in the way of the actual media files when using a PC to browse.) Without the magic folder, this shouldn't slow anybody down. With the behaviour enabled for the first time, there's a brief pause as all of the thumbnails are found. Re-visiting a folder is much quicker since each thumbnail has now been cached. Thumbnails still have to be found (but just once, of course) when new media is added. For day-to-day use, the biggest impact will probably be made by those media files which aren't matched by a wildcard thumbnail, since we'll check all the thumbnails for them every time. This can be mitigated by either using a catch-all default ("~.tbn" to match anything) which will be cached, or by maintaining an up-to-date set of thumbnails for all the series likely to be passing through the folder.
Does anybody have any comments, suggestions or objections?
Thanks,
Steve