Listen to a song from youtube with youtube-dl and mpv

listen-to-yt() { if [[ -z "$1" ]]; then echo "Enter a search string!"; else mpv "$(youtube-dl --default-search 'ytsearch1:' \"$1\" --get-url | tail -1)"; fi }
Explanation Firstly the function checks if user gave it any input, and notifies the user if they failed to do so. If user has inputed a search string, the function will call upon youtube-dl to find url of the audio of the first matching youtube video and play that with mpv. Call function by wrapping search string in quotes: listen-to-yt "sultans of swing" You have to paste the line in your .zshrc and source .zshrc for it to work. Limitations The dependancies are youtube-dl and mpv. this oneliner is stolen from

By: emphazer
2019-12-18 14:22:12

What Others Think

seems not working so well.. listen-to-yt cabrel ERROR: age6We05_kQ: YouTube said: Invalid parameters. Playing: [file] Cannot open file '': No such file or directory Failed to open . Exiting... (Errors when loading file)
_xX0V0Xx_ · 97 weeks and 2 days ago
Thanks for sharing the detail of Listen to a song from YouTube with YouTube-dl and mpv. It is a very good idea to share such stuff here for the readers. I read from the review that sharing like this will always helps the readers.
MarianneEMora · 73 weeks and 3 days ago
learned alot here but are there any other alternatives hair extensions new orleans?
looneyhans · 52 weeks and 4 days ago
I wrote about a similar issue, I give you the link to my site. baby photography
idasanka · 47 weeks and 6 days ago
fort collins kitchen remodeling I have been looking for this!
yeoyeo · 46 weeks and 1 day ago
Looked great afterward. Thank you so much, amazing job stairs
sammm · 43 weeks and 1 day ago
You're really good at explaining! loan companies in orlando
geebranz · 28 weeks and 2 days ago
We understand that at this point in the semester, you, like every other student, simply want one thing: cheap custom essay writing. We understand it's crunch time, and you might need our assistance because it's your only hope right now. Come to us if you've had enough and can't wait to relax and be done with it all.
Katehartley · 5 weeks and 5 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: