Nice script.
I was looking for something similar, but searches IMDB for the details on the movie, based on the filename, so I modified this a bit, and thought you might find a use for it.
After using Filebot to rename movies as I like them, for my Plex server, the names always look like this:
Ex Machina (2015) - [HD 1080p x265 1920x804] [AAC 6ch].mkv
Always the movie name first, then the year. The rest isn't useful for the IMDB search, so my regex only finds the Year, in parens, then extracts it + everything to the left of it, and finally, launches the web browser to search IMDB for that name + the year.
A couple things of note, that are different from yours;
I added .name_stem to the regex search, so that it only searches the actual filename(s), instead of the entire path. it seemed like a better idea to me.
I also wasn't sure what the purpose of having the "only search first file" script/option; I thought "why not just select a single file/the file you want, to do the search for then?" lol, so what I did was mish-mash tBone's example into a function that just checks whether 1 file is selected, or multiple files are selected; and set the true/false flag depending on how many files were selected, so that it's fully automatic now. You don't have to worry about how many are selected, you just select either 1 file, or as many as you want, and it'll handle them as usual. Not sure, if that's ideal for your situation, but, up to you.
I was having trouble with cmd.RunCommand and URLs, in that even with URL Encoding, it was acting strange, so I switched to wscript instead.
What I do is, select "File Types" from the DO menu, select the "movies" file group, then add a context-menu item, where I entered this script. I went out and dug up a small IMDB icon to add to the item as well, so now I just right-click on any movie file and the "Search on IMDB" item is there.
All-in-all, very useful script! Thanks guys, for the head start!
@disablenosel
@script:jscript
function OnClick(data) {
var tab = data.func.sourcetab;
var count = tab.selstats.selfiles;
var FirstFileOnly = (count == 1) ? true : false;
LaunchURL(data, tab, FirstFileOnly);
}
function LaunchURL(data, tab, firstFileOnly) {
var cmd = data.func.command;
var pattern = /.*\(\d{4}\)/;
cmd.ClearFiles();
for (var iEnum = new Enumerator(tab.selected_files); !iEnum.atEnd(); iEnum.moveNext()) {
var file = iEnum.item();
var matchArray = pattern.exec(file.name_stem);
if (matchArray != null) {
var url = 'find?ref_=nv_sr_fn&q=' + encodeURI(matchArray[0]) + '&s=all';
var oShell = new ActiveXObject("WScript.Shell");
oShell.Run('http://www.imdb.com/' + url);
}
if (firstFileOnly) break;
}
}