Search in YouTube

function OnClick(data) {
  data.func.command.ClearFiles();
  var objEnum = new Enumerator(data.func.sourcetab.selected);
  while (!objEnum.atEnd()) {
   var item = objEnum.item().name_stem; objEnum.moveNext();
   var encoded = encodeURIComponent(item);
   var search = encoded.replace(/%/g,"%%");
   data.func.command.RunCommand("http://www.google.com/search?q=" + search);
  }
}

I found this button in forum, This button search in google search with the selected file name.
I need to use a regex /^[^.]+/gm with the selected file name data.func.sourcetab.selected
and want to search in YouTube

1 Like

So change the regex and the url to the ones you want.

function OnClick(clickData)
{
	var cmd = clickData.func.command;
	cmd.deselect = false; // Prevent automatic deselection
	
	if (clickData.func.sourcetab.selected.count == 0)
	{
		DOpus.Output("  (none)");
	}
	else
	{
		for (var eSel = new Enumerator(clickData.func.sourcetab.selected); !eSel.atEnd(); eSel.moveNext())
		{
			if (eSel.item().is_dir)
			{
				DOpus.Output("  (d) " + eSel.item().RealPath);
			}
			else
			{
				var printname = (eSel.item().name_stem);
				//DOpus.Output(printname);
				re = /^[^.]+/gm;
				var NewNames = printname.match(re);
				DOpus.Output(NewNames);


//var objEnum = new Enumerator(NewNames);
  //while (!objEnum.atEnd()) {
   //var item = objEnum.item().name_stem; objEnum.moveNext();
   var encoded = encodeURIComponent(NewNames);
   var search = encoded.replace(/%/g,"%%");
   clickData.func.command.RunCommand("http://www.youtube.com/results?search_query={$youtubename}" + search);
 // }

				
			}
		}
	}

}

Here is my code but the problem is If I select 3 files then click the button
there is 9 tabs open in my browser, for each selected files there is 3 tabs open in my browser, How to fix these? Is There Any Easy Way to Do This Job?

I'm not sure but it may be because:

  • clickData.func.command comes with the selected files already added to it... (See Note 1.)

  • Which may cause clickData.func.command.RunCommand(...) to run the line you give it once for each file. (But see Note 2.)

  • That in turn is inside a loop through clickData.func.sourcetab.selected, which means clickData.func.command.RunCommand(...) is called once for each file.

Note 1: The first code you posted removed those files by running data.func.command.ClearFiles();, but you seem to have removed that in your new code.

Note 2: Only if {$youtubename} is interpreted as a file code of some kind. Since that's not a built-in code and not a variable you've defined anywhere in your script, I'm not sure what the result will be.

But the code you've posted there doesn't really make sense.

Not sure. You haven't really said what you're trying to do, and it's definitely not clear from the code you've posted.

What is the overall aim? What do you want the two regex you're using to do? What is {$youtubename}?

My demo file name is: My heart will go on. artist. Celine dion (2)
I want to select that files & click the button & wants to
Open a Tab in my browser & Search My heart will go on on the YouTube.com

Search Selected File names part in YouTube.

Oh That was a Mistake

That's very likely caused by your browser. You need to figure out how to properly handover the urls to avoid these additional tabs.

That seems like something you could do quickly and easily by manually selecting the text and pasting it into YouTube's search bar.

I understand the desire to automate every task, even the small ones, to save a few seconds here and there, but not if it means we have to write every little script for you (and we're already written a lot of them). You're asking us to spend half an hour to save you a few seconds. :slight_smile:

Thanks god you understand that! :grinning:

I don't think that try to save few seconds is a crime :wink: ; the code I have post in my main post which is found in forum, also save this kinds of few seconds. what that code done, we can also do the same job quickly and easily by manually selecting the text and pasting it into google search bar as you said here

in my starting day's even I can not read properly a script. now day by day I am trying to learn. you can check my previous 10 post, you did not write a complete script for me, even in this post I write the code how much I can.