Skip to content

Instantly share code, notes, and snippets.

@lumynou5
Created January 14, 2024 01:38
Show Gist options
  • Save lumynou5/cfda5666b39d4168f54b1545f4477673 to your computer and use it in GitHub Desktop.
Save lumynou5/cfda5666b39d4168f54b1545f4477673 to your computer and use it in GitHub Desktop.
A PowerShell script to download Twitch VODs with Streamlink.
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