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 like .pptx or .ods.

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, but n

Note Taking - An Art

  Note Taking - An Art Note Taking is an art, there’s no rigid right or wrong. Everyone has their own way of taking notes, and different things work for different people. The skill of note taking also requires years of practice to hone. There are many broad categories of note taking, along with several media to do so. Methods of Note Taking Outlining Method Mapping Method Charting Method Sentence Method Cornell Method Outlining Method: Dash or indented outlining is the easiest and usually best except for some science classes such as physics or math. The information which is most general begins at the left with each more specific group of facts indented with spaces to the right. The relationships between the different parts are carried out through indenting . No numbers, letters, or Roman numerals are needed. This visually depicts the hierarchy of the topics, making it easily digestible. Example: Mapping Method: Mapping is a method that uses comprehension/concentration skills and