Custom Columns › Type+ (Media Type Groups) [v0.9]

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
FluxTorpedoe
Posts: 906
Joined: 05 Oct 2011 13:15

Custom Columns › Type+ (Media Type Groups) [v0.9]

Post by FluxTorpedoe »

=========================
Custom Columns › Type+ v0.9
=========================
- Updated 2014-04-27 -
* Stronger detection, and type of files w/o extension is left blank
:arrow: Permanent variable must be updated — either with data below (1.) or next post
:arrow: Column definition must be recreated/updated — either via snippet data below (2.) or with this single line:
return gettoken(gettoken($CC_MEDIATYPELIST, 2, "|<cc_ext>|"), 2, "=");

---------------------------

Hi'

This is an attempt at replacing the original "Type" column with a more useful one which can group files by media type (Audio, Video, Document,...).
CC_MediaType.png
To achieve maximum performance, the types are stored in a permanent variable (cf. dev notes in the third post for those interested).

---------

### INSTALLATION v0.9 (XYplorer >= 13.90.0116) ###

:arrow: 1. Add the list of media types to a permanent variable. Either:
- Copy the following line into the AddressBar and press enter[/color]

Code: Select all

::perm $CC_MEDIATYPELIST; $CC_MEDIATYPELIST = "|arw|bmp|cr2|crw|dng|emf|gif|jpeg|jpg|ico|mrw|nef|orf|pef|png|psd|raf|rw2|srf|tga|tif|tiff|wmf|x3f|=Image=|aac|aiff|ape|asx|au|flac|gsm|la|m3u|m4a|mid|midi|mod|mp2|mp3|mpc|ogg|pac|pls|ra|ram|rm|wav|wma|=Audio=|3gp|aaf|asf|avchd|avi|divx|flv|ifo|m1v|m2v|m4v|mjp|mjpg|mkv|mov|mp4|mpe|mpeg|mpg|mts|ogm|rmv|rmvb|vob|wmv|=Video=|chm|diz|djvu|doc|docx|epub|hlp|mobi|nfo|odt|pdf|rtf|srt|txt|xps|=Document=|7z|arc|arj|bin|cab|cue|gz|iso|mds|nrg|rar|tar|tgz|zip|=Archive=|bat|com|exe|lnk|msi|swf|=Application=|dll|inf|reg|sys|=System=|cfg|dat|ini|xml|=Config=|js|jsx|vbs|xys|=Code=|css|htm|html|mht|url|=Web"; msg "Variable CC_MEDIATYPELIST successfully set";
[/size] - or see next post, which contains a script where you can easily edit your own media type list

:arrow: 2. Define the Type+ custom column:
- Copy the following content, then type "::snippet;" into the AddressBar, enter, then paste into the snippet window and press enter

Code: Select all

Snip: CustomColumn 1
  XYplorer 13.90.0116, 27/04/2014 17:14:00
Action
  ConfigureColumn
Caption
  Type+
Type
  3
Definition
    return gettoken(gettoken($CC_MEDIATYPELIST, 2, "|<cc_ext>|"), 2, "=");
Format
  0
Trigger
  0
Item Type
  0
Item Filter
  
[/size]
:arrow: 3. Add Type+ to the visible columns. In Details view of a regular folder:
- CTRL+RightClick on a column header > "New Column"
- RightClick on a the header of the new column "New" > "Select Custom Column..." > Double-Click on line "Type+, Script (*.*)"

That's it!

---------

Don't forget to have a look at the next post if you want to configure your own list.
And don't hesitate to post any comment!

Enjoy, 8)
Flux
To see the attached files, you need to log into the forum.
Last edited by FluxTorpedoe on 27 Apr 2014 09:56, edited 6 times in total.

FluxTorpedoe
Posts: 906
Joined: 05 Oct 2011 13:15

Re: Custom Columns › Type+ (Media Type Groups) [v0.8]

Post by FluxTorpedoe »

### Media Type List Configuration ###
Updated to v0.9

Use the script below to edit the list to your taste, then run it to add or update the permanent variable "$CC_MEDIATYPELIST" necessary for the Type+ custom column.
• Add or remove extensions to existing categories of MediaTypes (separated by "|")
• Edit or add categories of MediaTypes

Note: extensions are listed alphabetically for easier maintenance — order doesn't really matter (see dev notes in next post).

Code: Select all

"Media Type List Configuration"

// Edit or add extensions and categories below
  $l_Medias = <<<#>>>

Image = arw|bmp|cr2|crw|dng|emf|gif|jpeg|jpg|ico|mrw|nef|orf|pef|png|psd|raf|rw2|srf|tga|tif|tiff|wmf|x3f
Audio = aac|aiff|ape|asx|au|flac|gsm|la|m3u|m4a|mid|midi|mod|mp2|mp3|mpc|ogg|pac|pls|ra|ram|rm|wav|wma
Video = 3gp|aaf|asf|avchd|avi|divx|flv|ifo|m1v|m2v|m4v|mjp|mjpg|mkv|mov|mp4|mpe|mpeg|mpg|mts|ogm|rmv|rmvb|vob|wmv
Document = chm|diz|djvu|doc|docx|epub|hlp|mobi|nfo|odt|pdf|rtf|srt|txt|xps
Archive = 7z|arc|arj|bin|cab|cue|gz|iso|mds|nrg|rar|tar|tgz|zip
Application = bat|com|exe|lnk|msi|swf
System = dll|inf|reg|sys
Config = cfg|dat|ini|xml
Code = js|jsx|vbs|xys
Web = css|htm|html|mht|url

#>>>;

  perm $CC_MEDIATYPELIST;
  $CC_MEDIATYPELIST = trim(regexreplace($l_Medias, "^(.+?) *= *(.+?)\r\n", "|$2|=$1="), "<crlf>=");

  status "Permanent variable CC_MEDIATYPELIST successfully set";
[/size]
Last edited by FluxTorpedoe on 27 Apr 2014 09:48, edited 7 times in total.

FluxTorpedoe
Posts: 906
Joined: 05 Oct 2011 13:15

Re: Custom Columns › Type+ (Media Type Groups) [v0.8]

Post by FluxTorpedoe »

### Development Notes ###

Though the "Configuration" script is not optimized at all, I must say that the seemingly simple script used by the Type+ CC has definitely been!

Code: Select all

  $Ext = getpathcomponent(<cc_item>, "ext");
  return gettoken(gettoken($CC_MEDIATYPELIST, 2, "$Ext="), 1, "|");
Since a live column usefulness is only as good as its responsiveness, I've devised more than a dozen completely different approaches to gather media types from a big list. I then embedded those various scripts in a "speed optimization" script, and ran simulations based on multiple runs on multiple extensions, in order to output a statistically significant "average time" needed to compute one CC cell.

• So to sum things up, here are a few results, in case they may help other CC devs:
- including a list in the CC definition or an external file is too slow, hence the use of a permanent variable
- the less operations —even "harmless" ones—, the better (faster to use one-lines than set variables to be used in the next line)
- one-liners beat loops/conditionals — is that a sentence? :kidding:
- regex(replace|matches) are efficient, but not as much as the gettoken combination
Edits:
- it's much slower to first use a small list of most-frequently-used extensions before reverting to the remaining full list if not found (cf the "one-liner" paradigm)
- as weird as it may seem (or not), reordering the list to place most-used extensions on top doesn't yield statistically significant faster results. At all!


:idea: Based on that, I'm pretty sure things could be much faster if the first line could be removed...
...thanks to a new <cc_ext> variable! :biggrin:

:idea: I presume things could also be faster by using a "live" INI file, i.e. being able to use getkey() with a variable, and not only a real file.

Well, hoping this may help...
As always, don't hesitate to comment!

Have a nice day, 8)
Flux
Last edited by FluxTorpedoe on 26 Apr 2014 12:32, edited 2 times in total.

admin
Site Admin
Posts: 66359
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Custom Columns › Type+ (Media Type Groups) [v0.8]

Post by admin »

Very nice!

(I will add the <cc_ext> variable :biggrin: )


FluxTorpedoe
Posts: 906
Joined: 05 Oct 2011 13:15

Re: Custom Columns › Type+ (Media Type Groups) [v0.8]

Post by FluxTorpedoe »

Woops,
Current <cc_ext> are valid but empty...

Code: Select all

  return "-".<cc_ext>."-"; // Returns: --

admin
Site Admin
Posts: 66359
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Custom Columns › Type+ (Media Type Groups) [v0.8]

Post by admin »

Argh, logical black out... wait a minute... :blackstorm:

FluxTorpedoe
Posts: 906
Joined: 05 Oct 2011 13:15

Re: Custom Columns › Type+ (Media Type Groups) [v0.8]

Post by FluxTorpedoe »

And once again,
Peace returned to the realm... :om:
8)

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Custom Columns › Type+ (Media Type Groups) [v0.8]

Post by bdeshi »

Ah, I can finally have a static-width no cutoff* Type col...
:D Thanks!
Feature request: want to add capability of having one ext in multiple categories? And displayed as, say, for ext=html, Type+=web/document
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

FluxTorpedoe
Posts: 906
Joined: 05 Oct 2011 13:15

Re: Custom Columns › Type+ (Media Type Groups) [v0.8]

Post by FluxTorpedoe »

:biggrin:
SammaySarkar wrote:add capability of having one ext in multiple categories
Well, I started thinking about how to do it in code, but remembered that introducing even a simple "if" would add several tens of milliseconds — for each cell!...
So in fact, unless you've got a powerful computer with an SSD, the simplest solution is the fastest: just add new categories!

e.g. replace the last category with those:

Code: Select all

Web = css|url
Web/Document = htm|html|mht
Note to all: The script will always use the first matching extension, so if you want to put an extension into another category, remember to remove it from its current one.

Happy browsing! 8)
Flux

bdeshi
Posts: 4256
Joined: 12 Mar 2014 17:27
Location: Asteroid B-612
Contact:

Re: Custom Columns › Type+ (Media Type Groups) [v0.8]

Post by bdeshi »

CC is still new (to me), tend to forget speed is at a premium here... :whistle:
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47
Location: XY64 Latest Beta , Win 11, 96dpi, 100%

Re: Custom Columns › Type+ (Media Type Groups) [v0.8]

Post by nerdweed »

:appl: :appl:
I modified this a bit because I didn't like the repetitive category names in the PV. Haven't done stress test, it still does with two gettokens.

Script

Code: Select all

"Media Type List Configuration"
  // Edit or add extensions and categories below
  $l_Medias = <<<#>>>
Image=arw|bmp|cr2|crw|dng|emf|gif|jpeg|jpg|ico|mrw|nef|orf|pef|png|psd|raf|rw2|srf|tga|tif|tiff|wmf|x3f|
Audio=aac|aiff|ape|asx|au|flac|gsm|la|m3u|m4a|mid|midi|mod|mp2|mp3|mpc|ogg|pac|pls|ra|ram|rm|wav|wma|
Video=3gp|aaf|asf|avchd|avi|divx|flv|ifo|m1v|m2v|m4v|mjp|mjpg|mkv|mov|mp4|mpe|mpeg|mpg|mts|ogm|rmv|rmvb|vob|wmv|
Document=chm|diz|djvu|doc|docx|epub|hlp|mobi|nfo|odt|pdf|rtf|srt|txt|xps|
Archive=7z|arc|arj|bin|cab|cue|gz|iso|mds|nrg|rar|tar|tgz|zip|
Application=bat|com|exe|lnk|msi|swf|
System=dll|inf|reg|sys|
Config=cfg|dat|ini|xml|
Code=js|jsx|vbs|xys|
Web=css|htm|html|mht|url|
#>>>;

  $MediaTypeList="=|"; //Caters files with no extensions
  foreach($MediaCat, trim($l_Medias, "<crlf>"), "<crlf>") { // For each media category (Audio, Video...)
    $MediaTypeList = $MediaTypeList."=".$MediaCat;
  }
  perm $CC_MEDIATYPELIST;
  $CC_MEDIATYPELIST = trim($MediaTypeList, "|");
  status "Permanent variable CC_MEDIATYPELIST successfully set";
And the CC definition

Code: Select all

Snip: CustomColumn 1
  XYplorer 13.90.0116, 26-04-2014 17:09:27
Action
  ConfigureColumn
Caption
  Type+
Type
  3
Definition
  return gettoken(gettoken($CC_MEDIATYPELIST, 1, "<cc_ext>|"),-2,"=");
Format
  0
Trigger
  0
Item Type
  0
Item Filter
  
Last edited by nerdweed on 26 Apr 2014 17:20, edited 1 time in total.

Filehero
Posts: 2731
Joined: 27 Feb 2012 18:50
Location: Windows 11@100%

Re: Custom Columns › Type+ (Media Type Groups) [v0.8]

Post by Filehero »

Heya Flux,

you've just created the Awesome Column! :D :appl: :beer:

After a while I will post "my" MDL.


Cheers,
Filehero

FluxTorpedoe
Posts: 906
Joined: 05 Oct 2011 13:15

Re: Custom Columns › Type+ (Media Type Groups) [v0.9]

Post by FluxTorpedoe »

:D Glad it can be useful.

---------
nerdweed wrote:I modified this a bit because I didn't like the repetitive category names in the PV. Haven't done stress test, it still does with two gettokens.
Great! And yep, the repetitions were definitely not intellectually satisfying! :mrgreen:
I had stuck with that because it was the fastest I'd found... BUT!...

Your try gave me the incentive to have a closer look:
1. Fix: indeed, I'd forgotten the "|" before the <cc_ext> so v0.8 wrongly assigned types to files without extensions (fixed in your vers, but prob with files with unknown ext).
2. Now, what about speed? (simulated on a slow machine)
I had previously noted that "reverse" operations seemed to be slower (~ same with regex). Anyway, there had to be a way that a "cleaner" PV would yield faster results! So I re-reversed the PV processing (in v0.9) and after a few more tests:
- The "new" valid speed reference: v0.8 fixed (with the extra pipe) is ~2.16% slower than previous "buggy" v0.8
- your version, with a short PV, is ~6.81% slower than fixed v0.8 (reverse gettoken I presume)
- v0.9, with a short PV, is ~1.25% faster than fixed v0.8
- Ironically in the end, the "buggy" version with a PV more than twice as long is still the fastest (by 0.88%)... :twisted:

Ho, and in v0.9 detection is even stronger, only exact matches are used for extensions, so no risk of wrong detection : e.g htm is different than xhtm (or html or xhtml...).

Anyway, thanks to nerdweed's input, here's a new version, fixed and with a "clean" PV (and a cleaner Configuration), and still as fast as possible — until we find an even faster way...

Have a nice day, 8)
Flux

nerdweed
Posts: 648
Joined: 25 Feb 2012 07:47
Location: XY64 Latest Beta , Win 11, 96dpi, 100%

Re: Custom Columns › Type+ (Media Type Groups) [v0.9]

Post by nerdweed »

- v0.9, with a short PV, is ~1.25% faster than fixed v0.8
- Ironically in the end, the "buggy" version with a PV more than twice as long is still the fastest (by 0.88%)... :twisted:
So we have ~1.25% faster code with the shorted PV. No use counting the speed of the initial buggy version

BTW, it was cheeky to reverse the PV than using reverse gettoken :appl:

Post Reply