-
Notifications
You must be signed in to change notification settings - Fork 0
/
screenshots.ps1
176 lines (156 loc) · 4.96 KB
/
screenshots.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<#
.SYNOPSIS
Powershell wrapper for screenshots.py
.DESCRIPTION
A wrapper that provides readline and autocomplete functionality for screenshots.py.
Linux users have access to argcomplete, which is less straightforward to implement
on Windows. This script attempts to fill that gap
.NOTES
This script does minimal input validation and mostly relies on the python script.
For help, please use the -Help parameter which calls the python script.
#>
[CmdletBinding(DefaultParameterSetName = 'Frames')]
param (
[Parameter(Mandatory = $false, Position = 0, ParameterSetName = 'Frames')]
[Parameter(Mandatory = $false, Position = 0, ParameterSetName = 'RandomFrames')]
[ValidateScript(
{
if (!(Test-Path $_)) {
throw "Source input path does not exist"
}
else { $true }
}
)]
[Alias('S')]
[string]$Source,
[Parameter(Mandatory = $false, ParameterSetName = 'Frames')]
[Parameter(Mandatory = $false, ParameterSetName = 'RandomFrames')]
[ValidateScript(
{
$res = $_.ForEach({ Test-Path $_ })
if ($res -contains $false) { throw "One ore more file paths do not exist" }
else { $true }
}
)]
[Alias('E')]
[string[]]$Encodes,
[Parameter(Mandatory = $true, ParameterSetName = 'Frames')]
[Alias('F')]
[int[]]$Frames,
[Parameter(Mandatory = $true, ParameterSetName = 'RandomFrames')]
[ValidateCount(3, 3)]
[Alias('RF')]
[int[]]$RandomFrames,
[Parameter(Mandatory = $false, ParameterSetName = 'Frames')]
[Parameter(Mandatory = $false, ParameterSetName = 'RandomFrames')]
[Alias('O')]
[int]$Offset,
[Parameter(Mandatory = $false, ParameterSetName = 'Frames')]
[Parameter(Mandatory = $false, ParameterSetName = 'RandomFrames')]
[ValidateCount(2, 2)]
[Alias('C')]
[int[]]$Crop,
[Parameter(Mandatory = $false, ParameterSetName = 'Frames')]
[Parameter(Mandatory = $false, ParameterSetName = 'RandomFrames')]
[Alias('T')]
[string[]]$Titles,
[Parameter(Mandatory = $false, ParameterSetName = 'Frames')]
[Parameter(Mandatory = $false, ParameterSetName = 'RandomFrames')]
[ValidateScript(
{
if (!(Test-Path $_)) {
throw "Input directory does not exist"
}
else { $true }
}
)]
[Alias('D')]
[string]$InputDirectory,
[Parameter(Mandatory = $false, ParameterSetName = 'Frames')]
[Parameter(Mandatory = $false, ParameterSetName = 'RandomFrames')]
[Alias('OD')]
[string]$OutputDirectory,
[Parameter(Mandatory = $false, ParameterSetName = 'Frames')]
[Parameter(Mandatory = $false, ParameterSetName = 'RandomFrames')]
[ValidateSet('bilinear', 'bicubic', 'point', 'lanczos', 'spline16', 'spline36', 'spline64')]
[Alias('K')]
[string]$ResizeKernel,
[Parameter(Mandatory = $false, ParameterSetName = 'Frames')]
[Parameter(Mandatory = $false, ParameterSetName = 'RandomFrames')]
[ValidateSet('lsmas', 'ffms2')]
[Alias('LF')]
[string]$LoadFilter,
[Parameter(Mandatory = $false, ParameterSetName = 'Frames')]
[Parameter(Mandatory = $false, ParameterSetName = 'RandomFrames')]
[Alias('NI')]
[switch]$NoFrameInfo,
[Parameter(Mandatory = $true, ParameterSetName = 'Help')]
[Alias('H')]
[switch]$Help
)
if (!$PSBoundParameters['Source'] -and !$PSBoundParameters['Encodes'] -and !$PSBoundParameters['InputDirectory']) {
Write-Error "No input files or directories were provided" -ErrorAction Stop
}
if (!(Get-Command 'python')) {
Write-Error "Python could not be resolved in system PATH" -ErrorAction Stop
}
$scriptPath = Join-Path $PSScriptRoot -ChildPath 'screenshots.py'
if (!(Test-Path $scriptPath)) {
Write-Error "Could not locate 'screenshots.py'. Are you running the wrapper from the same directory?" -ErrorAction Stop
}
if ($Help) {
& python $scriptPath -h
exit 0
}
$pyArgs = @(
$scriptPath
if ($PSBoundParameters['Source']) {
'-s'
$Source
}
if ($PSBoundParameters['Encodes']) {
'-e'
$Encodes
}
if ($PSBoundParameters['Titles']) {
'-t'
$Titles
}
if ($PSBoundParameters['Crop']) {
'-c'
$Crop
}
if ($PSBoundParameters['Frames']) {
'-f'
$Frames
}
if ($PSBoundParameters['RandomFrames']) {
'-rf'
$RandomFrames
}
if ($PSBoundParameters['Offset']) {
'-o'
$Offset
}
if ($PSBoundParameters['InputDirectory']) {
'-d'
$InputDirectory
}
if ($PSBoundParameters['OutputDirectory']) {
'-od'
$OutputDirectory
}
if ($PSBoundParameters['ResizeKernel']) {
'-k'
$ResizeKernel
}
if ($PSBoundParameters['LoadFilter']) {
'-lf'
$LoadFilter
}
if ($NoFrameInfo) {
'-ni'
}
)
# Execute python screenshots script with params
& python $pyArgs