1

I want to get the playlist title of a youtube playlist and store it in a variable in a bash script.

I have already tried these things:

  • -e flag but it lists only the video titles
  • -o flag and --get-filename but again the same
  • the best try was to run yt-dlp and grep the first download line that contains the playlist name, but that seems too much for a basic job

Also note that I don't want to use: yt-dlp -o "%(playlist_title)s" because I want the name of the playlist only.

Is it possible to get the playlist title with yt-dlp? or I have to use a workaround like Pafy?

Destroy666
  • 5,299
  • 7
  • 16
  • 35

1 Answers1

0

You need to simply use --print (or -O) instead of -o:

yt-dlp [the rest of your command] --skip-download --print playlist_title

See documentation:

-O, --print [WHEN:]TEMPLATE     Field name or output template to print to screen, optionally prefixed with when to print it, separated by a ":".

--skip-download also prevents the download and you might want to add --no-warnings to output only the playlist title.

A full example with a playlist that outputs only one playlist title (for 1st video - -I 1:1):

yt-dlp https://youtube.com/playlist?list=PLpeFO20OwBF7iEECy0biLfP34s0j-8wzk -I 1:1 --skip-download --no-warning --print playlist_title
Destroy666
  • 5,299
  • 7
  • 16
  • 35