codesoap/ytools

ytools-search only prints "No videos found." recently

codesoap opened this issue · 4 comments

At first it appeared sporadic, but now I'm not getting any results from ytools-search anymore. All I get is the No videos found. message. YouTube seemingly changed the structure of the HTML it returns and ytools should adapt to these changes.

The new HTML contains some JSON, which seems to contain all needed info. It can be inspected like this:

curl -s 'https://www.youtube.com/results?search_query=Daniel%20Deluxe' | \
grep 'window..ytInitialData.. =' | \
sed -e 's/^[^=]*. *//' -e 's/; *$//' | \
jq '.'

I can get the video IDs like this:

curl -s 'https://www.youtube.com/results?search_query=Daniel%20Deluxe' | \
grep 'window..ytInitialData.. =' | \
sed -e 's/^[^=]*. *//' -e 's/; *$//' | \
jq '.. | .videoRenderer? | select(type != "null") .videoId'

And the titles like this:

curl -s 'https://www.youtube.com/results?search_query=Daniel%20Deluxe' | \
grep 'window..ytInitialData.. =' | \
sed -e 's/^[^=]*. *//' -e 's/; *$//' | \
jq '.. | .videoRenderer? | select(type != "null") .title.runs[0].text'

I adapted to the new HTML in commits f211570, 50502c0 and abd198c. I'll take some time to test this before closing this issue.

Seems to work well for me. Closing...