Command: SelectEx (extended Select command)

Updated to v0.4.1:

  • no need for a selected item when using SIMILARMETAJS

This new "feature" (I actually just removed 2 lines), allows to select without necessarily comparing data with another item.

Example 01:
This selects all wma-files for which their actual filename does not match their track-number, artist information tags.
The filename matched against in this usecase is " - .wma" -> "03 - The Songtitle.wma"

SelectEx SIMILARMETAJS="if (item.name.search('0?'+item.metadata.audio_text.mp3track+' \- '+item.metadata.audio_text.mp3title+'\.wma')!=0) return true;"

Example 02:
This would select all files, for which the title-tag cannot be found in the filename (case-sensitive):

SelectEx SIMILARMETAJS="if (item.name.indexOf(item.metadata.audio_text.mp3title)==-1) return true;"

@ktbcrash
I can't say I mind your kind feedback! o) Thank you! o)

Hi tbone,
many thanks for this great script.
I played around with the JSFILTER argument and tried to achieve the following:

Randomly select 1 hour of music files (???) containing the tag "My Tag" (argument JSFILTER) from a specified folder (argument PATH) and write the result to the file /temp\playlist.m3u (argument TOFILE).

At the moment I'm able to select e.g. 20 tagged files but not 1 hour. Would it be possible to create such a Filter based on mp3songlength? I tried and couldn't get it working. I'd really appreciate any help with this.

Since TOFILE doesn't work together with PATH I have to use the arguments COPYTOCOLL=MyColl and COMMANDS=Go coll://MyColl followed by Select ALL and a second SelectEx line to get the playlist created. It would be nice to have TOFILE working with PATH.

My JSFILTER-snippet to select audio files based on a specific tag:

var jsFilter = ""+
	"var tagstring = '';"+
		"if (item.metadata == 'audio'){ "+
			"for (var tagEnum = new Enumerator(item.metadata.tags);"+
				"!tagEnum.atEnd();"+
				"tagEnum.moveNext() ) {"+
					"tagstring += tagEnum.item();"+
					"tagstring += ','; }"+
			"if (tagstring.indexOf('My Tag') !=-1) return false;"+
		"}";

Updated to v0.4.2:

  • distance() function added for simple fuzzy selections with "SIMILARMETAJS"
  • new option "JSBREAK" for custom rules on when to stop item selection/picking
  • "TOFILE" and "APPEND" now also work in conjunction with "RANDOM"/"LINEAR"

@Kundal
Thanks for giving SelectEx a spin and pushing the limits! o))
Here is a JSBREAK example and code that stops the item picking if a total mp3-duration of 30 minutes has been reached.
The try-catch block at the start initialises the global "totalDuration" variable, which is re-used by the rest of the snippet.

SelectEx RANDOM ITEMCOUNT=99 JSBREAK="try{totalDuration;}catch(e){totalDuration=0;} if ((totalDuration+item.metadata.audio.mp3songlength)>60*30) return true; totalDuration+=item.metadata.audio.mp3songlength;" TOFILE="C:\MyPlaylist.txt

Wow!
I knew you would make me happy but I didn't expect it so fast. "JSBREAK" and "TOFILE" are working fine for me now.
Many many thanks!

You're welcome! o)
As "duration" is quite a sensible thing to select on, I consider adding min/max/totalduration switches in the future. Similar to the existing min/max/totalsize feature. Having to use js-snippetting is probably not everyones first choice I guess, but still good to have for all the special cases. o))

Yes, in my case it would be much easier if instead of JSFILTER the native FILTER=MyFilter argument and/or FILTERDROP/FILTERLIST could be used together with RANDOM/PATH/ITEMCOUNT/... :wink:

Very nice script. Some more options and it's an own app, which should get a GUI :wink:.

A GUI for Random (audio) would be nice... where you can select all meta-options, size, etc. and also save some presets.

@kundal
The filter-idea is tempting and might even boost performance, but I don't see this coming within the next couple of weeks.
It would "just" allow a different way of getting the same results, so priority is not that high I'd assume?! o)

@sasa
Would the filter editor be ok? o)

There's no rush. For my personal needs everything is fine as it is now.

Yep, but a mix of radio-buttons and pulldowns would be better :slight_smile:.

Unfortunately I have no time until middle of next week to design a functional layout (and an icon), which I think is necessary before programming a GUI. But if you can wait...

You sound like I would be eager to do that GUI-thing, I'm actually not! o) Though admittedly, it's interesting as an experiment! o)
If you could provide some basic *.html or a *.xaml representation of a finished layout.. I'd consider putting it into working condition as an HTA (hypertext application) or powershell driven .Net-GUI.

Oh wow that's some serious amount of (quite nice) code (over 1600 lines, 125 KB in current latest version)! :astonished:
And a very powerful add-on indeed! :thumbsup:

Updated to v0.4.3:

  • MAKEVISIBLE fixed, threw error in previous upload
  • JSBREAK finetuning: return true to stop item picking, false to skip item and null/undefined will select/pick
  • JSFILTER performance gain
  • Usage of Confighelper v1.2 and XLog 0.3

@jsys -> Thanks thanks! o)
Actually it's around 60kb, but it comes in UTF16 because the upload preparation of ScriptWizard requires that.
Not an issue I guess, but if size matters for anyone, the well known TurboImploder might also work for DO add-ins. o))
youtube.com/watch?v=gMZskyQyxzI

I tested your exact config-line and path and it works here, do you use the latest SelectEx version?

What kind of saved selection are you talking about? Selections stored to memory or to file?
Actually both of them should survive a DO restart, but maybe you can share some more details and we find what's going on. o)

It's version 0.4.3, which should be the newest one. Maybe i made a mistake, by just appending some lines at the bottom, like here:

;you can use ; or // or # to comment out lines
;syntax is: [REGEX=]<path> => [REGEX=]<item name>

;standard path (select program files)
C:\ => Program Files

;alias for path and regex for item
/home => REGEX=dopus.exe|dopusrt.exe

;env-var in path and regex for item (all log files)
%windir% => REGEX=.+\.log$

;using regex for the path
REGEX=.*\\drivers\\etc => hosts

*\Directory Opus => dopus.exe
*\Outlook => Outlook.pst
C:\Passwords => File4.txt
C:\Program Files\Light Alloy => LA.exe
...

So maybe it has to be applied in another way? The red lines represent your example part, the green ones are those i've added.

For example, i select some random files for a test, then choose "save selection to" -> example.txt, then "load selection from" (the same .txt file), but nothing happens.

Ok, i have better results now with the "store to memory" option, which loads the files fine even after a restart. Interesting feature. But the selection will be lost, only if i change the file display once, and change back.

Funny, but now it works, after i restarted Opus. And i did not forget to set the "autoselect" option to "true", when i tried first. :smiley:
Anyway, i have to play around now a bit with this very useful script tool set.

tbone, i'm playing around with both scripts (Leo's and yours), and i have a suggestion for your version of the "autoselect" part. If i use the option "automatically select first file in folder" in my Opus settings, which i do, i will end up having two selected items, if i use the script to point at a certain folder. Therefore i would suggest, that you include some sort of "select none", before your script selects the given item, overriding the "first file" selection.

Updated to v0.4.4

  • TOFILE/FROMFILE encoding-awareness added (did not always load selection-files correctly)
    SelectEx will detect unsupported encodings now (that is UTF8 and UTF16-BE) and suggest converting the files.
  • new script config "AutoSelect.DeselectNoMatch" to deselect automatically selected first file

@abr

  1. I was able to reproduce the FROMFILE feature not working in all conditions, maybe you like to try again. Make sure the selection-files you try to load are ANSI or UTF16-LE (UNICODE) encoded if they were not created by SelectEx. You can use notepad.exe to convert files that do not meet this requirement.

  2. Suggestion implemented

  3. You mean the red lines are those you added, right? o))
    This won't work, as currently there is no support for wildcards: *\Directory Opus => dopus.exe
    But you can use regex, which should be more versatile, like this: REGEX=.*\\Directory Opus => dopus.exe

Updated to v0.4.5:

  • the AUTO feature, to trigger auto-selection from commandline (same as AutoSelect when entering a folder), is now independent from the "AutoSelect" script configs (despite the list). That means you can disable AutoSelect and still use it occasionally from a "SelectEx AUTO" button. The script configs "AutoSelect.MakeVisible" and "AutoSelect.DeselectNoMatch" also don't apply anymore if AUTO is invoked from a button or commandline (use the regular MAKEVISIBLE and DESELECTNOMATCH switches if desired).