Closed madepolli closed 3 years ago
I'm working on something without an API key that does the same thing. It's super rough around the edges and does not show the title of the video yet, but the basic functionality is there.
mpv https://youtube.com"$(curl -s "https://www.youtube.com/results?search_query=$(printf "" | \
dmenu-wl -p "Search:" | tr ' ' '+')&sp=EgIQAQ%253D%253D" | \
grep -Po '(/watch\?v=.{11})' | \
perl -ne '$seen{$_}++ or print;' | \
dmenu-wl -l 7 || notify-send "Something went wrong...")"
Probably not the best method to use grep
and perl
with those flags, but it gets the job done
See full prototype script with playlist support at: https://github.com/notthewave/ytlist-src
Spent a few hours curling YouTube search results into my terminal lol...
This is not simple now also there is a guy sayan21 - https://github.com/sayan01/scripts/blob/master/yt He also made similar stuff by getting inspired by my script and he did it with web scraping. SO no need of python now.
It might be a good idea to use the Invidious API for this: https://github.com/iv-org/documentation/blob/master/API.md
Since using Youtoube API for simple search seems like too much trouble (and is limited in the number of uses anyways), why not use a webpage scraper?
By a quick google, I found youtube-search (
pip3 install youtube-search
), and I changed the bash script to use the following python script instead of querying youtube API:main bash lines then become:
It works great for me. It does require some polishing regarding the location of both scripts which influences how you call python from bash etc. The two scripts could probably be even merged into one (heredocs in bash or use python to call fzf and mpv) for extra points :)
So I'm just leaving this idea here with you, if I ever foolproof it, I'l turn it into a merge request.