-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest-FullWorkflow.ps1
More file actions
352 lines (306 loc) · 14.8 KB
/
Test-FullWorkflow.ps1
File metadata and controls
352 lines (306 loc) · 14.8 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
[CmdletBinding()]
param()
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " FULL WORKFLOW TEST (DRY RUN)" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
$testResults = @{
CleanupBefore = $null
Stage1 = $null
Stage2 = $null
Stage3 = $null
Stage4a = $null
CleanupAfter = $null
OverallSuccess = $true
}
$performanceMetrics = @{
Stage1Duration = $null
Stage2Duration = $null
Stage3Duration = $null
Stage4aDuration = $null
TotalDuration = $null
}
$metadataStats = @{
TotalFiles = 0
EmbeddedFiles = 0
InferredFiles = 0
HybridDirectories = 0
}
# Change to Scripts directory
Set-Location "$PSScriptRoot\Scripts"
# =============================================================================
# Cleanup: Remove existing mapping files
# =============================================================================
Write-Host ">>> CLEANUP: Remove existing mapping files <<<" -ForegroundColor Magenta
Write-Host ""
try {
$outputDir = "..\Output"
$existingMappings = Get-ChildItem -Path $outputDir -Filter "mapping-*.json" -File -ErrorAction SilentlyContinue
if ($existingMappings.Count -gt 0) {
Write-Host " Found $($existingMappings.Count) existing mapping file(s)" -ForegroundColor Yellow
foreach ($file in $existingMappings) {
Remove-Item -Path $file.FullName -Force
Write-Host " Deleted: $($file.Name)" -ForegroundColor Red
}
}
else {
Write-Host " No existing mapping files found" -ForegroundColor Gray
}
$testResults.CleanupBefore = "PASS"
}
catch {
Write-Host " ERROR: Cleanup failed - $($_.Exception.Message)" -ForegroundColor Red
$testResults.CleanupBefore = "FAIL"
$testResults.OverallSuccess = $false
}
Write-Host ""
Start-Sleep -Seconds 1
# =============================================================================
# Stage 1: Analyze Ripped Media
# =============================================================================
Write-Host ">>> STAGE 1: Analyze Ripped Media <<<" -ForegroundColor Magenta
Write-Host ""
$stage1Start = Get-Date
try {
$mappingFile = .\1-Analyze-RippedMedia.ps1 -SourcePath "C:\DVDFab\DVDFab13\Output\Video" -ErrorAction Stop
$performanceMetrics.Stage1Duration = (Get-Date) - $stage1Start
Write-Host ""
Write-Host " Mapping file created: $mappingFile" -ForegroundColor Green
Write-Host " Duration: $([math]::Round($performanceMetrics.Stage1Duration.TotalSeconds, 2)) seconds" -ForegroundColor Gray
$testResults.Stage1 = "PASS"
}
catch {
$performanceMetrics.Stage1Duration = (Get-Date) - $stage1Start
Write-Host " ERROR: Stage 1 failed - $($_.Exception.Message)" -ForegroundColor Red
$testResults.Stage1 = "FAIL"
$testResults.OverallSuccess = $false
return
}
Write-Host ""
Start-Sleep -Seconds 1
# =============================================================================
# Stage 2: Lookup Metadata
# =============================================================================
Write-Host ">>> STAGE 2: Lookup Metadata <<<" -ForegroundColor Magenta
Write-Host ""
$stage2Start = Get-Date
try {
.\2-Lookup-Metadata.ps1 -MappingFile $mappingFile -ErrorAction Stop
$performanceMetrics.Stage2Duration = (Get-Date) - $stage2Start
Write-Host " Duration: $([math]::Round($performanceMetrics.Stage2Duration.TotalSeconds, 2)) seconds" -ForegroundColor Gray
$testResults.Stage2 = "PASS"
}
catch {
$performanceMetrics.Stage2Duration = (Get-Date) - $stage2Start
Write-Host " ERROR: Stage 2 failed - $($_.Exception.Message)" -ForegroundColor Red
$testResults.Stage2 = "FAIL"
$testResults.OverallSuccess = $false
}
Write-Host ""
Start-Sleep -Seconds 1
# =============================================================================
# Stage 3: Review & Approve (Automated for Testing)
# =============================================================================
Write-Host ">>> STAGE 3: Review Metadata (Auto-Approve for Testing) <<<" -ForegroundColor Magenta
Write-Host ""
$stage3Start = Get-Date
try {
# Load mapping
$mapping = Get-Content $mappingFile -Raw | ConvertFrom-Json
# Show summary of proposed changes
Write-Host " Proposed Changes Summary:" -ForegroundColor Cyan
$tvSeriesCount = ($mapping.content | Where-Object { $_.content_type -eq 'tv_series' }).Count
$movieCount = ($mapping.content | Where-Object { $_.content_type -eq 'movie' }).Count
$totalFiles = ($mapping.content | ForEach-Object { $_.files.Count } | Measure-Object -Sum).Sum
Write-Host " TV Series groups: $tvSeriesCount" -ForegroundColor Gray
Write-Host " Movie groups: $movieCount" -ForegroundColor Gray
Write-Host " Total files: $totalFiles" -ForegroundColor Gray
Write-Host ""
# NEW: Analyze metadata sources
$embeddedCount = 0
$inferredCount = 0
$hybridDirs = 0
$unresolvedCount = 0
foreach ($content in $mapping.content) {
if ($content.metadata_source -eq "hybrid") {
$hybridDirs++
}
foreach ($file in $content.files) {
if ($file.metadata_source -eq "embedded") {
$embeddedCount++
}
elseif ($file.metadata_source -eq "inferred") {
$inferredCount++
}
if ($file.proposed_name -match '\[Needs Lookup\]') {
$unresolvedCount++
}
}
}
# Store for final summary
$metadataStats.TotalFiles = $totalFiles
$metadataStats.EmbeddedFiles = $embeddedCount
$metadataStats.InferredFiles = $inferredCount
$metadataStats.HybridDirectories = $hybridDirs
Write-Host " Metadata Source Distribution:" -ForegroundColor Cyan
if ($embeddedCount -gt 0) {
Write-Host " Embedded metadata: $embeddedCount ($([math]::Round($embeddedCount/$totalFiles*100, 1))%)" -ForegroundColor Green
}
if ($inferredCount -gt 0) {
Write-Host " Claude inferred: $inferredCount ($([math]::Round($inferredCount/$totalFiles*100, 1))%)" -ForegroundColor Yellow
}
if ($hybridDirs -gt 0) {
Write-Host " Hybrid directories: $hybridDirs" -ForegroundColor Cyan
}
Write-Host ""
if ($unresolvedCount -gt 0) {
Write-Host " WARNING: $unresolvedCount file(s) still need metadata lookup" -ForegroundColor Yellow
}
else {
Write-Host " ✓ All files have complete metadata" -ForegroundColor Green
}
Write-Host ""
# Add approval metadata
$mapping | Add-Member -NotePropertyName "approved_date" -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -Force
$mapping | Add-Member -NotePropertyName "approved_by" -NotePropertyValue "TEST_WORKFLOW" -Force
$mapping | Add-Member -NotePropertyName "approval_status" -NotePropertyValue "approved" -Force
# Save approved mapping
$mapping | ConvertTo-Json -Depth 10 | Out-File -FilePath $mappingFile -Encoding UTF8 -Force
$performanceMetrics.Stage3Duration = (Get-Date) - $stage3Start
Write-Host " Approval Status: APPROVED (automated for testing)" -ForegroundColor Green
Write-Host " Duration: $([math]::Round($performanceMetrics.Stage3Duration.TotalSeconds, 2)) seconds" -ForegroundColor Gray
$testResults.Stage3 = "PASS"
}
catch {
$performanceMetrics.Stage3Duration = (Get-Date) - $stage3Start
Write-Host " ERROR: Stage 3 failed - $($_.Exception.Message)" -ForegroundColor Red
$testResults.Stage3 = "FAIL"
$testResults.OverallSuccess = $false
}
Write-Host ""
Start-Sleep -Seconds 1
# =============================================================================
# Stage 4a: Rename TV Series (-WhatIf Mode)
# =============================================================================
Write-Host ">>> STAGE 4a: Rename TV Series (-WhatIf Mode) <<<" -ForegroundColor Magenta
Write-Host ""
$stage4aStart = Get-Date
try {
.\4-Rename-TVSeries.ps1 -MappingFile $mappingFile -WhatIf -ErrorAction Stop
$performanceMetrics.Stage4aDuration = (Get-Date) - $stage4aStart
Write-Host ""
Write-Host " Duration: $([math]::Round($performanceMetrics.Stage4aDuration.TotalSeconds, 2)) seconds" -ForegroundColor Gray
$testResults.Stage4a = "PASS"
}
catch {
$performanceMetrics.Stage4aDuration = (Get-Date) - $stage4aStart
Write-Host " ERROR: Stage 4a failed - $($_.Exception.Message)" -ForegroundColor Red
$testResults.Stage4a = "FAIL"
$testResults.OverallSuccess = $false
}
Write-Host ""
# =============================================================================
# Cleanup: Remove test mapping files
# =============================================================================
Write-Host ">>> CLEANUP: Remove test mapping files <<<" -ForegroundColor Magenta
Write-Host ""
try {
$testMappings = Get-ChildItem -Path $outputDir -Filter "mapping-*.json" -File -ErrorAction SilentlyContinue
if ($testMappings.Count -gt 0) {
Write-Host " Removing $($testMappings.Count) test mapping file(s)" -ForegroundColor Yellow
foreach ($file in $testMappings) {
Remove-Item -Path $file.FullName -Force
Write-Host " Deleted: $($file.Name)" -ForegroundColor Red
}
}
$testResults.CleanupAfter = "PASS"
}
catch {
Write-Host " ERROR: Final cleanup failed - $($_.Exception.Message)" -ForegroundColor Red
$testResults.CleanupAfter = "FAIL"
$testResults.OverallSuccess = $false
}
Write-Host ""
# =============================================================================
# Test Summary
# =============================================================================
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " TEST RESULTS SUMMARY" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Cleanup (Before): $($testResults.CleanupBefore)" -ForegroundColor $(if ($testResults.CleanupBefore -eq "PASS") { "Green" } else { "Red" })
Write-Host "Stage 1 (Analyze): $($testResults.Stage1)" -ForegroundColor $(if ($testResults.Stage1 -eq "PASS") { "Green" } else { "Red" })
Write-Host "Stage 2 (Lookup): $($testResults.Stage2)" -ForegroundColor $(if ($testResults.Stage2 -eq "PASS") { "Green" } else { "Red" })
Write-Host "Stage 3 (Review): $($testResults.Stage3)" -ForegroundColor $(if ($testResults.Stage3 -eq "PASS") { "Green" } else { "Red" })
Write-Host "Stage 4a (Rename -WhatIf): $($testResults.Stage4a)" -ForegroundColor $(if ($testResults.Stage4a -eq "PASS") { "Green" } else { "Red" })
Write-Host "Cleanup (After): $($testResults.CleanupAfter)" -ForegroundColor $(if ($testResults.CleanupAfter -eq "PASS") { "Green" } else { "Red" })
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " PERFORMANCE METRICS" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
if ($performanceMetrics.Stage1Duration) {
Write-Host "Stage 1 (Analyze): $([math]::Round($performanceMetrics.Stage1Duration.TotalSeconds, 2))s" -ForegroundColor Gray
}
if ($performanceMetrics.Stage2Duration) {
Write-Host "Stage 2 (Lookup): $([math]::Round($performanceMetrics.Stage2Duration.TotalSeconds, 2))s" -ForegroundColor Gray
}
if ($performanceMetrics.Stage3Duration) {
Write-Host "Stage 3 (Review): $([math]::Round($performanceMetrics.Stage3Duration.TotalSeconds, 2))s" -ForegroundColor Gray
}
if ($performanceMetrics.Stage4aDuration) {
Write-Host "Stage 4a (Rename): $([math]::Round($performanceMetrics.Stage4aDuration.TotalSeconds, 2))s" -ForegroundColor Gray
}
$totalDuration = 0
if ($performanceMetrics.Stage1Duration) { $totalDuration += $performanceMetrics.Stage1Duration.TotalSeconds }
if ($performanceMetrics.Stage2Duration) { $totalDuration += $performanceMetrics.Stage2Duration.TotalSeconds }
if ($performanceMetrics.Stage3Duration) { $totalDuration += $performanceMetrics.Stage3Duration.TotalSeconds }
if ($performanceMetrics.Stage4aDuration) { $totalDuration += $performanceMetrics.Stage4aDuration.TotalSeconds }
Write-Host "-----------------------------------" -ForegroundColor DarkGray
Write-Host "Total Workflow: $([math]::Round($totalDuration, 2))s" -ForegroundColor White
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host " METADATA SOURCE ANALYSIS" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
Write-Host "Total files processed: $($metadataStats.TotalFiles)" -ForegroundColor White
Write-Host ""
if ($metadataStats.EmbeddedFiles -gt 0) {
$embeddedPercent = [math]::Round($metadataStats.EmbeddedFiles / $metadataStats.TotalFiles * 100, 1)
Write-Host "Embedded metadata: $($metadataStats.EmbeddedFiles) files ($embeddedPercent%)" -ForegroundColor Green
}
if ($metadataStats.InferredFiles -gt 0) {
$inferredPercent = [math]::Round($metadataStats.InferredFiles / $metadataStats.TotalFiles * 100, 1)
Write-Host "Claude AI inferred: $($metadataStats.InferredFiles) files ($inferredPercent%)" -ForegroundColor Yellow
}
if ($metadataStats.HybridDirectories -gt 0) {
Write-Host "Hybrid directories: $($metadataStats.HybridDirectories)" -ForegroundColor Cyan
}
Write-Host ""
# Calculate efficiency gains
if ($metadataStats.EmbeddedFiles -gt 0) {
$apiCallsSaved = $metadataStats.EmbeddedFiles
$savingsPercent = [math]::Round(($metadataStats.EmbeddedFiles / $metadataStats.TotalFiles) * 100, 1)
Write-Host "Efficiency Gains:" -ForegroundColor Cyan
Write-Host " API calls saved: $apiCallsSaved" -ForegroundColor Green
Write-Host " Savings: $savingsPercent% reduction" -ForegroundColor Green
if ($metadataStats.EmbeddedFiles -eq $metadataStats.TotalFiles) {
Write-Host ""
Write-Host " ✓ Perfect efficiency! 100% embedded metadata" -ForegroundColor Green
Write-Host " Zero Claude/TVMaze/TMDb API calls needed!" -ForegroundColor Green
}
}
Write-Host ""
Write-Host "========================================" -ForegroundColor Cyan
Write-Host ""
if ($testResults.OverallSuccess) {
Write-Host "OVERALL STATUS: ALL TESTS PASSED ✓" -ForegroundColor Green
}
else {
Write-Host "OVERALL STATUS: SOME TESTS FAILED ✗" -ForegroundColor Red
}
Write-Host ""
Write-Host "NOTE: This was a complete dry run test." -ForegroundColor Yellow
Write-Host " No files were actually renamed (Stage 4 used -WhatIf mode)." -ForegroundColor Yellow
Write-Host " All test mapping files have been cleaned up." -ForegroundColor Yellow
Write-Host ""