Joined July 2012
·

Dan Bennett

Web Developer at Perkz Ltd
·
Northants, UK
·
·
·

I hope you don't mind, but I've done a bit of work expanding on the code you've posted here. Of course, I've attributed you as the original author.

I turned it into a shell script for easier development, and I've combined the search output and URL generation under -s and -w flags. My intention is to make it so you can do a search, then pick a video and even specify how to handle launching the video.

So far I've only tested on Windows using Git Bash, but here's what I've got:
https://gist.github.com/Ultrabenosaurus/8974206b2cba0f1c615a

Yeah, I had to add -r as the first flag to sed and then treat the pattern like normal regex - as in, only escape characters you want as literals. So it now looks like this:

curl -s https://www.youtube.com/results\?search_query\=$3 | \
        grep -o 'watch?v=[^"]*"[^>]*title="[^"]*' | \
        sed -r -e 's/^watch\?v=([^"]*)".*title="(.*)/\1 \2/g'

You still have to escape the ? because it's a text character you want to match, you don't want it to be evaluated as a regex operator.

Sorry, I deleted it as after posting I found that exact download. Now, though, sed seems to be doing nothing...

ytsearch usage

specific test

Definitely surprised that Referenced is always slower than Passed, not to mention the fluctuation in the size of the gap between their performance across your tests. I'd have thought Passed would be slower, or they'd be nearly identical - if anyone knows why this isn't the case, I'd love to know!

What is your intent with using grep -o? My bash is telling me that's not a valid option.

Achievements
48 Karma
263 Total ProTip Views
Interests & Skills