0

I'm trying to write a bash script for Alfred which will let me put in a custom time ($time) to link to a YouTube video ($url)

If one or more ampersands are present remove everything after the first ampersand (If there is no ampersand present just keep the existing url):

https://www.youtube.com/watch?v=n6AwsVGJDOY&t=121s&ab_channel=BigThink

would become:

https://www.youtube.com/watch?v=n6AwsVGJDOY

then I will input in Alfred a time eg 3m02s and it will append it to the end of the URL https://www.youtube.com/watch?v=n6AwsVGJDOY&t=3m02s

preg_match('/[^&]+/', $url, $match);
$url2 = $match[0];

echo "<a href='$url2&t=$time'>$time</a>" | textutil -stdin -format html -convert rtf -stdout | pbcopy

Any help would be appreciated!

The linked question did not answer my query (at least in a way I understand)

  • The linked answer isn't intended to 100% answer your question, it's intended to provide you enough information to answer your own question. If you don't understand it then you need to do more learning so that you can. – Ian Kemp Dec 17 '22 at 21:09

0 Answers0