Created
January 14, 2024 01:38
-
-
Save lumynou5/cfda5666b39d4168f54b1545f4477673 to your computer and use it in GitHub Desktop.
A PowerShell script to download Twitch VODs with Streamlink.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Parameter(Mandatory, ParameterSetName="Basic", Position=0)] | |
[Parameter(Mandatory, ParameterSetName="Segment", Position=0)] | |
[ValidatePattern("^\d{10}$")] | |
[string]$Id, | |
[Parameter(Mandatory, ParameterSetName="Segment", Position=1)] | |
[ValidatePattern("^\d{2}:\d{2}:\d{2}$")] | |
[string]$Begin, | |
[Parameter(ParameterSetName="Segment", Position=2)] | |
[ValidatePattern("^\d{2}:\d{2}:\d{2}$")] | |
[string]$End | |
) | |
$args = '' | |
if ($Begin) { | |
$escapedBegin = $Begin.Replace(':', '_') | |
$args += "--hls-start-offset $Begin --output ${Id}-${escapedBegin}" | |
} else { | |
$args += "--output $Id" | |
} | |
if ($End) { | |
$escapedEnd = $End.Replace(':', '_') | |
$duration = [datetime]$End - [datetime]$Begin | |
$args += "-${escapedEnd}.ts --hls-duration $duration" | |
} else { | |
$args += '.ts' | |
} | |
$args += " https://twitch.tv/videos/$Id best" | |
streamlink $args.Split(' ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment