-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-YTDlpHelp.ps1
52 lines (41 loc) · 1.35 KB
/
Get-YTDlpHelp.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using namespace System.Collections.Generic
$ErrorActionPreference = 'Stop'
New-Variable HeaderRe -Value ([regex]'(?<=^\s{2})[^\s-][^:]+') -Option Constant -Scope Script
New-Variable OptionRe -Value ([regex]'(?m)(?<=^\s{4})\S.+?$(^\s{10,}}.+$)*') -Option Constant -Scope Script
# function Get-YTDlp () {
# Get-Command yt-dlp -All
# | Select-String $HeaderRe,$OptionRe -Raw
# | ForEach-Object {
# $match = [regex]::Match($_.Path, '(?<=Python)(?<major>3)(?<minor>\d+)')
# $version = $match.Success ? [version]::new(
# "$($match.Groups[1]).$($match.Groups[2])"
# ) : $null
# [PSCustomObject]@{
# Command = $_
# Version = $version
# }
# }
# | Sort-Object -Property PythonVersion -Descending
# | Select-Object -First 1 -ExpandProperty Command
# }
# $ytDlp = Get-YTDlp
$content = Invoke-Expression "yt-dlp -h"
$category = $null
foreach ($line in $content) {
if ($line -match '^\S') {
continue
}
$categoryMatch = $HeaderRe.Match($line)
if ($categoryMatch.Success) {
$category = $categoryMatch.Value
continue
}
$optionMatch = $OptionRe.Match($line)
if ($optionMatch.Success) {
[PSCustomObject]@{
Category = $category
Option = ($optionMatch).Value -split '\s{10,}'
}
}
$i++
}