0

I would like to know what's wrong with the syntax of the second command below. It doesn't give expected result.

This line results with expected file name that consist of video title from yt and fixed file extension.

yt-dlp --print filename -o %(title)s.mkv https://www.youtube.com/watch?v=Diw4iqKSV8I

gd3kr⧸BlenderGPT - Gource visualisation.mkv

But when I try to set initial commands' output to a variable with this line, the output title is trimmed and there's no extension (missing: " - Gource visualisation.mkv").

for /F %O in ('"yt-dlp --print filename -o %(title)s.mkv https://www.youtube.com/watch?v=Diw4iqKSV8I"') do set output=%O

set output=gd3kr⧸BlenderGPT

How to modify this line to get full expected string?

Rayearth
  • 345
  • 3
  • 5
  • 13

1 Answers1

1

The output title is trimmed and there's no extension

By default, when parsing the output, for /f only returns the first token:

tokens=n The numbered items to read from each line. Default = 1.

...

tokens=* will cause all items on each line to be processed

Source: For - Loop through command output - Windows CMD - SS64.com

The default delimiter for tokens is a space character.

Change your for command to:

for /F "tokens=*" %O in ('"yt-dlp --print filename -o %(title)s.mkv https://www.youtube.com/watch?v=Diw4iqKSV8I"') do set output=%O
DavidPostill
  • 153,128
  • 77
  • 353
  • 394
  • From the article I understand the problem was not the line itself in my case, but the 'blank space'. Either way - thank you! – Rayearth Mar 30 '23 at 20:38