Skip to main content

Search and Play Youtube Videos from the Terminal - yt


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

Popular posts from this blog

Dont waste time using powerpoint or google slides to make simple presentations

present github repo: github.com/sayan01/present youtube video:  https://www.youtube.com/watch?v=0Ns4rMnR5A4 I was frustrated with the likes of microsoft powerpoint and google slides for making simple presentations. Presentations are always supposed to be simple and easy to follow, with no unnecesary decorations.  Reference:  https://www.youtube.com/watch?v=Unzc731iCUY  [How To Speak - MIT] For this reason I dislike apps like slides and powerpoint which spoil the user with too many choices. This forces them to take bad design decisions, as well as waste their time. creating slides should take 5 minutes. preparing for presenting those slides should take the rest of your time. If you spend all your time making the slides (which are just tools to aid your presentation) then you are wasting your time and not practising your presentation itself. For this I made a presentation software that is very simple and fast to use. You dont need to work on proprietary project files l...

Connect with people online without the 'algorithm' coming in between - How I made a social network in one week.

website:  scsp.sayn.work github:  https://github.com/sayan01/scsp This semester in my college I had to build a web project as a part of one of my courses, and I decided to make a social network platform that works for its users, unlike the most of them. The idea was simple, provide a platform to your users, nothing more, nothing less. The software does not assume what you want to see, or what you dont. It doesnt give you 'recommendations' or automatically hide posts from people you follow because it thinks it is irrelevant. If you follow someone, you see their posts. Its that simple.  But how are we sorting the posts? By time? By likes? For this I resorted to one of the most unbiased platforms - reddit. I used its hotranking algorithm to mathematically determine which post is deserving by using its age, as well as the number of likes and dislikes it gained from other users to dynamically assign it a score to sort the posts. The comments are also sorted using an algorithm,...

Moving to Bangalore: Experiences and Observations

Moving to Bangalore Recently I moved to Bangalore for my studies. Here I'm staying in a co-living facility in the edge of the city. Being my first time in the city, many a thing amazed me.  Travel My travel began early in the morning, from the CCU airport. As it was my first flight, and that too amidst the lockdown and its guidelines, anxiety was like a shadow, ever following me in every step. But the entire process of boarding was hassle-free regardless. If the internet had taught me anything, it was to choose the window seat in a flight, although other than a few good pictures, I could see no other benefits. Checking-in Upon arrival, I checked into the co-living facility I intend to stay in for the next three years. The key things to test out in any new home are the WiFi-speed, toilet, and comfort of the bed: in that order. ...