Reputation: 21
I've been tinkering with a Powershell script to automate some Streamlink stuff, and it's going okay, but I'm having an issue with the way streamlink is passing a command along, specifically with regards to wrapping the file path.
Here is the code (forgive the terrible formatting, I am not a pro, I'm only a beginner.)
Set-Location (Split-Path $MyInvocation.MyCommand.Path)
$scriptdir = Split-Path $MyInvocation.MyCommand.Path
$streamurl = Read-Host -Prompt 'Stream URL'
$channel = youtube-dl --cookies $scriptdir\Resources\cookies.txt --write-description --skip-download -o "%(uploader)s" --get-filename $streamurl
if (-not (Test-Path -LiteralPath $scriptdir\Recordings\$channel\)) {
try {
New-Item -Path $scriptdir\Recordings\$channel\ -ItemType Directory -ErrorAction Stop | Out-Null #-Force
}
catch {
Write-Error -Message "Unable to create directory '$channel'. Error was: $_" -ErrorAction Stop
}
"Successfully created directory '$channel'."
}
streamlink-auth $scriptdir\Resources\cookies.txt --retry-streams 10 -o "$scriptdir\Recordings\$channel\stream.mp4" $streamurl best
$scriptdir = Where the script is running
$streamurl = Self explanatory
$channel = the channel name of the stream
The issue I'm having is that when this command is passed along to streamlink, it seems to be wrapping wrong, as when streamlink tries to run the command, I get the following error:
streamlink args: --retry-streams 10 -o W:\recordings\Recordings\【LIVE】新宿 大ガード交差点 Tokyo Shinjuku Live Ch\stream.mp4 https://www.youtube.com/watch?v=RQA5RcIZlAM best
usage: streamlink [OPTIONS] <URL> [STREAM]
streamlink: error: unrecognized arguments: Shinjuku Live Ch\stream.mp4 https://www.youtube.com/watch?v=RQA5RcIZlAM best
Source:【LIVE】新宿 大ガード交差点 Tokyo Shinjuku Live Ch
I also tested this with a fully english channel (with the same script) and got the following:
streamlink args: --retry-streams 10 -o W:\recordings\Recordings\Watson Amelia Ch. hololive-EN\stream.mp4 https://www.youtube.com/watch?v=EeC6OHBRFTc best
usage: streamlink [OPTIONS] [STREAM]
streamlink: error: unrecognized arguments: hololive-EN\stream.mp4 https://www.youtube.com/watch?v=EeC6OHBRFTc best
Source: Watson Amelia Ch. hololive-EN
It seems that while the directory can be created fine, passing the variables into the streamlink command fails somewhere along the line. This can be worked around by simply moving into the channel directory with:
cd $scriptdir\Recordings\$channel\
and running the command without the extra variables in the path, but that's not the way I'd like to do it. I also want to add that youtube-dl has no issues with writing files to the directories created with this script as my postprocessing script writes files there without trouble, and powershell can still remove files there too.
I have asked the streamlink folks, and it's definitely not on their end, so obviously it's a powershell thing.
How do I solve this problem, because I am genuinely stumped now.
Upvotes: 1
Views: 215
Reputation: 21
I'm dumb.
Turns out when you pass something into a command, you have to pass it with Double quote, then single quote.
So instead of:
streamlink-auth $scriptdir\Resources\cookies.txt --retry-streams 10 -o "$scriptdir\Recordings\$channel\stream.mp4" $streamurl best
It needs to be:
streamlink-auth $scriptdir\Resources\cookies.txt --retry-streams 10 -o "'$scriptdir\Recordings\$channel\stream.mp4'" $streamurl best
Sorry for being the dum.
Upvotes: 1