I've been using yt-dlp to download audio files before running mpv for playing them back.

I've been specifically using the following commands:

yt-dlp -f ba "ytsearch:major artist cool music"

mpv [Title of the audio file downloaded].webm

Now, what bothers me is that I would prefer to have a super command that chains the both of them without having to wait and follow-up with the mpv command after the download concludes.

The bottleneck for downloading the file is understandable, and the randomness of the file name is reasonable since the search criteria depends on YouTube's algorithm to return the best search.

Is there a command that knows beforehand the most recent downloaded file and allows mpv to play the file as soon as it finishes downloading regardless of its file name?

I have tried the usual piping a la yt-dlp ... | mpv but it yielded errors. My understanding of UNIX is still wanting but I'll address that however you advise.

To add to my personal debugging of this scripting issue, E.g.:

mpv | yt-dlp -f ba "ytsearch:selena gomez good for you remix lyrics" -

Yields this error:

ERROR: [generic] None: '-' is not a valid URL. Set --default-search "ytsearch" (or run yt-dlp "ytsearch:-" ) to search YouTube

yt-dlp was downloaded via pip(Python 3.11).

All this running in Windows 11 Terminal (Windows Powershell). But I don't see why it can't apply on (U/Li)nux

  • are you familiar with yt-dlp's -g switch? Or -o? (hint: have you read the yt-dlp man page?) Commented Jun 29, 2023 at 9:45
  • Thanks for the reply. No I'm not familiar with any of those. Was just looking for a "high level" way of overriding those commands since mpv is involved. Haven't checked out the manual in a while. I'll get to it before I get back to you
    – Gabe Devs
    Commented Jun 29, 2023 at 9:49
  • @MarcusMüller I've played around with the -o and the -g flags. -g is particularly useful since mpv can playback the audio from the link. But I still need a way to search then immediately playback whatever link gets output. More help would be appreciated. Something like: mpv | yt-dlp -f ba "ytsearch:selena gomez good for you remix lyrics" -g
    – Gabe Devs
    Commented Jun 29, 2023 at 10:11
  • Never mind. Have found it: mpv $(yt-dlp -f ba "ytsearch:selena gomez good for you remix lyrics" -g) Thanks for the direction
    – Gabe Devs
    Commented Jun 29, 2023 at 10:14

2 Answers 2


man mpv says there is a ytdl:// protocol so that you can use its youtube-dl script for any URL:

mpv --ytdl-format=ba 'ytdl://ytsearch:major artist cool music'
  • Thanks. I had actually used this one some years ago but forgot about it due to its network-esque format. Is there a way to show the title of the media being played while it's being played back? I want to know the exact title of the video/audio for quality purposes
    – Gabe Devs
    Commented Jun 29, 2023 at 14:28
  • No worries. I already have a solution for what I wanted: unix.stackexchange.com/a/566623/577500
    – Gabe Devs
    Commented Jun 29, 2023 at 14:37
  • Final answer (with title showing): mpv --ytdl-format=ba --term-playing-msg='Title: ${media-title}' 'ytdl://ytsearch:major artist cool music'
    – Gabe Devs
    Commented Jun 29, 2023 at 14:41
  • 1
    Even less output: mpv --ytdl-format=ba --no-video --msg-level=all=no,input=status,statusline=status --term-status-msg=$'\n''${time-pos}/${duration} [${file-format}] ${metadata/by-key/artist:}: ${media-title:${filename}} (${playlist-pos-1}/${playlist-count})'
    – xebeche
    Commented Jun 29, 2023 at 22:15
mpv $(yt-dlp -f ba "ytsearch:song/music description" -g)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .