yt
For a long time I've been searching for a command-line utility to search
YouTube for videos and play them with mpv (or any other video player)
without having to open the browser and the slow and bloated YouTube web-page.
There exists many such tools like mps-youtube and youtube-viewer, but all of
them require you to have a YouTube API key.
Although using API makes the tool much more useful and adds many
features, it has a major flaw, that is you cant search use it anymore if
you exceed your daily API quota. Also, getting an API key and setting the
tool up is a pain.
To combat this, I wrote a script myself that uses simple
web-scraping using
grep.
As it uses web-scraping, it doesn't need any API key to work, and can
work out of the box perfectly. You dont even need to be logged in to use
it.
yt
The script itself is pretty small and simple, and is written in bash. So
can be run directly from the terminal. It takes the user's search query,
gives it to the youtube search, and then greps out the results along
with their ids from the response and shows them to the user. Any of the
video can be then chosen to be played and is played directly by mpv
(which uses youtube-dl under the hood).
It also supports playlists (playlists are marked with a '(playlist)' at
the beginning of their name).
On choosing a playlist, its first video starts playing in mpv, and the
next and previous buttons can be used to navigate the playlist.
The script can be found here: https://github.com/sayan01/scripts/blob/master/yt
To use it, just download the script and put it somewhere in
your
PATH
. Then call it:
yt <Search Term>
The script can also be run with the -r flag which runs it in rofi mode
(change it to dmenu in the code if you use that instead) and we dont
even need to use the terminal if we bind yt -r to a hotkey.
For more details on the script and how to use it, check this video
out:
Hope you find this script as useful as I do. You can also check out
other scripts I've written over the span of the years in the same
GitHub repo.
If you have any suggestion or comment on the script, feel free to
leave them here or open an issue.
Sayan
Jan 6, 2021
Comments
Post a Comment
Leave your ideas, opinions, or criticisms.
Remember to be respectful and polite to internet strangers.