You are not logged in.

#1 15 May 2021 09:52

Rekrul
Member
Registered: 17 Apr 2016
Posts: 98

Put output of YouTube-DL into a variable?

This works;

@echo off
set url=https://www.youtube.com/watch?v=GsSxEdL56sU
youtube-dl.exe --get-filename %url%

However, when I try to feed the output of that command to a For token, YouTube-DL itself fails;

@echo off
set url=https://www.youtube.com/watch?v=GsSxEdL56sU
for /f %%F in ('youtube-dl.exe --get-filename %url%') do set Name=%%F
echo %Name%

Am I doing something wrong?

Offline

#2 15 May 2021 10:24

Shadow Thief
Member
Registered: 12 Jul 2012
Posts: 205

Re: Put output of YouTube-DL into a variable?

The = is treated as a separator in for loops, so you need to wrap the URL in quotes.

@echo off
set url=https://www.youtube.com/watch?v=GsSxEdL56sU
for /f %%F in ('youtube-dl.exe --get-filename "%url%"') do set Name=%%F
echo %Name%

Offline

#3 16 May 2021 09:00

Rekrul
Member
Registered: 17 Apr 2016
Posts: 98

Re: Put output of YouTube-DL into a variable?

Shadow Thief wrote:

The = is treated as a separator in for loops, so you need to wrap the URL in quotes.

@echo off
set url=https://www.youtube.com/watch?v=GsSxEdL56sU
for /f %%F in ('youtube-dl.exe --get-filename "%url%"') do set Name=%%F
echo %Name%

Thank you. I also had to add "delims=" or it only returned the first word of the title.

Offline

Board footer

Powered by