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)