Folder thumbnail generation enhancement

Features wanted...
TzakShrike
Posts: 5
Joined: 16 Jan 2017 20:31

Folder thumbnail generation enhancement

Post by TzakShrike »

I'd like to propose an enhancement to the way folder thumbnails are generated.

I wish I could designate an ordered list of image names to look for within a folder when generating thumbnail folders. That is, to use filenames other than the default "folder.xxx or, failing that, whatever image I find first", because I use poster.xxx for my video files, cover.xxx for music albums, artist.xxx for music groups, and cover.xxx (or simply 00.xxx or 01.xxx) for manga.

The UI could be as simple as a textbox so I can type in, comma-separated, the filenames I want checked, along with a checkbox/dropdown to decide what to do when nothing is found.

In my specific case, I'd want to define my list of image names as "poster,cover,artist,folder" and select "If none of these are found, use the first image found". Other sensible options might include "If none of these are found, use a generic folder icon".

I hope I've explained it well enough to be understood. Oh, and I assumed it would check for both jpg and png types. What do you reckon? Any chance of this happening?

eil
Posts: 1621
Joined: 13 Jan 2011 19:44

Re: Folder thumbnail generation enhancement

Post by eil »

best solution for you would be to create a script that creates custom thumbnails for you(all commands are already present).
Win 7 SP1 x64 100% 1366x768

highend
Posts: 13316
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Folder thumbnail generation enhancement

Post by highend »

Are we talking about the picture that appears on the icon of a folder (in thumbnail mode)?
Like this:
folderthumb.png
folderthumb.png (22.56 KiB) Viewed 3050 times
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Folder thumbnail generation enhancement

Post by klownboy »

As you know, the use of folder.xxx is actually a Windows thing not an XYplorer thing. Take a look at this ZoomtoFillFolderThumbs script. It randomly selects files to create the picture used for the folder.xxx. It also takes advantage of XY's thumbnail "Zoom to Fill" feature such that your "folder" thumbs fill the entire space or thumb block and not just a portion of it based on aspect ratio (which can look a bit ugly). However, you could adapt it to use the criteria/selection you desire to determine which file(s) you would use as the folder.xxx instead of a random selection.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

TzakShrike
Posts: 5
Joined: 16 Jan 2017 20:31

Re: Folder thumbnail generation enhancement

Post by TzakShrike »

highend wrote:Are we talking about the picture that appears on the icon of a folder (in thumbnail mode)?
Like this:
folderthumb.png
Yes, the Thumbnail that XYPlorer generates. The same thumbnails that appear in thumbnails, tiles and other modes, when enabled.
eil wrote:best solution for you would be to create a script that creates custom thumbnails for you(all commands are already present).
Nope. I'm running Free.
klownboy wrote:As you know, the use of folder.xxx is actually a Windows thing not an XYplorer thing.
I actually hadn't realised this, but thanks for pointing me in the right direction. Is XYPlorer using the shell to generate its folder thumbnails? I thought it wasn't... in any case, the part that I'm actually interested in is the part AFTER the folder.jpg, where it selects the first file it finds to generate an image. This ISN'T standard windows shell behaviour (the shell would generate a thumbnail with 4 images on it), so XYPlorer must be doing something else.
klownboy wrote:Take a look at this [...] script. It randomly selects files to create the picture used for the folder.xxx. [...] However, you could adapt it to use the criteria/selection you desire to determine which file(s) you would use as the folder.xxx instead of a random selection.
No scripts as I'm in free mode, but this isn't an acceptable solution for me anyway, even after editing, because of the duplication of data. This script essentially just copies something to folder.jpg. Those cover and poster files I mentioned before are generated by other applications, mostly, and can be updated as such too. Even if I were to duplicate all of those files, they would still fall out of sync with their originals quickly and need regeneration, which is slightly absurd on folders this big, stored on a network drive. Basically this solution is really inelegant when another one clearly could exist easily.

I don't know how exactly XYPlorer is generating that last image, but it seems to be custom. If that's the case, why can't I just specify which file to use?

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Folder thumbnail generation enhancement

Post by klownboy »

TzakShrike wrote:Basically this solution is really inelegant when another one clearly could exist easily.
"Exist easily", I'm not the programmer, but I'm not so sure about that. Not one single person using XY would have the same criteria. So Don would have to have an open editable selection criteria which would have to be looked at whenever a folder is encountered when building thumbnails.

The main purpose of the script I referred to was to have a folder thumbnail which takes up the full allotted space for the thumbnail so we're not looking at so much yellow space. The criteria on what image file is selected to generate the folder thumbnail is something one could change with scripting (with a Pro version).

XY will first look to see if desktop.ini file is present in the folder, and if within that file, it specifies a logo image file.

Code: Select all

[ViewState]
Mode=
Vid=
FolderType=Pictures
Logo=D:\Multimedia\Photos\Moscow\DSC_4030.JPG
If that image exist, it will use that for the folder thumbnail. If not, it will determine if folder.XXX exists and use that. As a last resort it will select the first qualifying image in the folder. If Don doesn't agree with the wish, you could investigate providing/modifying the "logo" entry in desktop.ini based on the criteria you specify using DOS or Powershell. Just a thought...
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

TzakShrike
Posts: 5
Joined: 16 Jan 2017 20:31

Re: Folder thumbnail generation enhancement

Post by TzakShrike »

klownboy wrote:If Don doesn't agree with the wish, you could investigate providing/modifying the "logo" entry in desktop.ini based on the criteria you specify using DOS or Powershell. Just a thought...
This is actually a great idea, like, a freakin' amazing idea. I'm totally going to do this for some of them, but the network resource I'm working from is intended to be platform independent, and I've specifically prevented platform specific types from cluttering the folders (I don't want desktop.ini files, which annoy OSX users, any more than I want .DS_Store files, which annoy Windows users). I may have to reconsider that policy for this case alone though, because this at least doesn't result in duplication, and will still be pointing to the correct files and will regenerate properly when they update.
klownboy wrote:So Don would have to have an open editable selection criteria which would have to be looked at whenever a folder is encountered when building thumbnails
TzakShrike wrote:The UI could be as simple as a textbox so I can type in, comma-separated, the filenames I want checked
Yes, that's the idea.
Build an array from the comma separated list, then iterate over it.
I dunno what XYPlorer is programmed in but something like (Python):

Code: Select all

userDefinedListOfFilesToSearchFor = "poster,cover,artist,album,folder" //pull from Config
userThumbnailFilenames = [a.strip() for a in userDefinedListOfFilesToSearchFor.split(',')]
thumbnailFiletypes = ['.png','.jpg','.gif','.bmp']
thumbnailFilenames = [a + b for a,b in itertools.product(userThumbnailFilenames, thumbnailFiletypes) if a]
for thumbnailFilename in thumbnailFilenames:
  if exists(thumbnailFilename): //assuming pwd is inside the directory we're generating for
    generateThumbnail(for=".", from=thumbnailFilename)
    break
else: //For loop didn't break ie. none of the files were found
  generateDefaultThumbnail() //This could potentially be many things depending on settings.
Want it in something other than Python? I'll do that, too! :)
klownboy wrote:As a last resort it will select the first qualifying image in the folder.
Yep. Changing how this "qualifying image" is determined is the part I'm wishing for.
klownboy wrote:The main purpose of the script I referred to was to have a folder thumbnail which takes up the full allotted space for the thumbnail so we're not looking at so much yellow space.
You know that "Zoom to Fill" is one of the options for thumbnail generation, right? Does that not work for folders? It's not something I use so I don't know. Either way, maybe this should be split into two options too. "Zoom to Fill for files" and "Zoom to Fill for folders"...

Hell, if you're worried about looking at so much yellow space, maybe we should ask Don to add border colours around thumbnails while we're at it :P

Now to start putting Logo entries everywhere... thanks for the tip!! :)

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Folder thumbnail generation enhancement

Post by klownboy »

I'm not sure which is the worst of 2 evils, having the folder.XXX files or having the desktop.ini in each sub folder. You can have XY hide the desktop.ini files by using the Ghost filter which is nice. The folder.XXX will take up more disk space but we're not as concerned about space now-a-days and it just shows up as another picture when viewing the contents of the folder in thumbnail view. Granted, it's a smaller copy of a picture already in that folder.

I'd be very interested if you come up with a automated way to modify the desktop.ini files based on a user definable criteria.

I don't normally have the Zoom to Fill option enabled. You don't need it for the images themselves unless you want it. I only use it in the script to generate the "folder" thumbnails to make them utilize the full allotted space regardless of aspect ratio (of the image used for the folder thumb) as shown in that link above.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

highend
Posts: 13316
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Folder thumbnail generation enhancement

Post by highend »

d be very interested if you come up with a automated way to modify the desktop.ini files based on a user definable criteria
Fully automated? That would require hooking the inotify events. On demand? Easy.

The XY way:

Code: Select all

    end exists(<curitem>) != 2, "The current item is not a folder, aborted!";
    $notes = <<<>>>
The first existing image type from the list will be used
If none is found, the first existing image is used
If no image at all is present, a generic icon will be used
>>>;
    $order = replace(input("Enter the order to be used...", "$notes", "poster,cover,artist,folder"), ",", "|");
    $images = quicksearch("*.jpg;*.png /n", "<curitem>", "|");
    $result = formatlist($images, "f", , regexreplace($order, "(\||$)", ".*|"), "f");

    $image = "";
    foreach($item, $order, , "e") {
        $match = regexmatches($result, "$item\..*?(?=(\||$))");
        if ($match) { break; }
    }
    if ($match) { $image = "<curitem>\$match"; }
    elseif ($images) { $image = gettoken($images, 1, "|"); }

    $iniFile = "<curitem>\desktop.ini";
    if (exists($iniFile)) { setkey $image, "Logo", "ViewState", $iniFile; }
    else {
        $iniContent = <<<>>>
[ViewState]
Mode=
Vid=
FolderType=Pictures
Logo=$image
>>>;
        writefile($iniFile, $iniContent, , "UTF-8");
        attrstamp("hs", , $iniFile);
    }
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Folder thumbnail generation enhancement

Post by klownboy »

Hi highend. That worked for me at least for a specific folder. It was quite simple as it turned out and it was nice that you hid the desktop.ini files so there was no need for the Ghost filter. At this time I do not have or use any criteria as TzakShrike discussed.

I believe the idea though at least for me would be to run this on demand script on a main folder for example, "Photos" and have it reiterate through all the subfolders under it. So as another example, I'd be in folder, "Wallpaper" and it would run through each of the subfolders, like Canada, Japan, Ireland creating the desktop ini file in each folder. I suppose that would be just a matter of another foreach loop through the listing of all the subfolders under it and determining initially if you are not only in a folder but that subfolders under it contain pictures.

Thanks and wow you're fast!
Ken
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

highend
Posts: 13316
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Folder thumbnail generation enhancement

Post by highend »

I suppose that would be just a matter of another foreach loop
Hi Ken. Could be done that way but I'll probably would take a different route (getting all image files first, reduce the folder list to those that contain images and loop only over them...). More efficient if it's a large folder structure and not all folders contain image(s)
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Folder thumbnail generation enhancement

Post by klownboy »

I see what you mean, but I probably mislead you a bit. In my case anyway, all those subfolders would most probably contain images since that's what they are images folders. :) If they didn't, they would probably be void of any files of any type. Knowing that, would that change the approach?
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

highend
Posts: 13316
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Folder thumbnail generation enhancement

Post by highend »

Not for me :) Each folder structure is different, this approach does only what's really necessary regardless of the folder structure. Narrowing down what needs to be processed is fast as well so... But ofc you can catch everything with one global foreach loop (and a few variable changes) :tup:
One of my scripts helped you out? Please donate via Paypal

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Folder thumbnail generation enhancement

Post by klownboy »

OK, I'm still a little unclear about your statement, "get all the image files first". I'm a bit rusty. Are you talking about using SC quicksearch or regex to accomplish that? I figured I'd get a quick list of all folders using SC quicksearch or listfolders() (with the no files just folders flag), under the main folder.

Code: Select all

  $ImageFolders = quicksearch("*.jpg;*.png /p", "<curitem>", "|");
This seems to work fine when the current item is the main folder, but it also returns the mainfolder which I don't want even if it contains qualifying images (e.g., I want everthing under Wallpaper but not Wallpaper itself). Is there a way to eliminate the current folder from the search? I read about the Maxdepth and excl switches but they don't seem to apply. Thanks.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

highend
Posts: 13316
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Folder thumbnail generation enhancement

Post by highend »

I'm unsure in which directory you are but in general there are several ways to filter out the current folder (when it contains images as well):
formatlist() with a negated filter (and the new "F" flag) like:

Code: Select all

text formatlist(quicksearch("*.jpg;*.png /p", <curpath>), "F", <crlf>, "!<curpath>");
or you could count the result entries (gettoken() with count) and a second gettoken
that gets everything from 1 to count-1 by using the flags=1 param
One of my scripts helped you out? Please donate via Paypal

Post Reply