[CmdletBinding()] param( [Parameter(Mandatory = $true)] [string]$Path, [string]$Csv ) $ErrorActionPreference = 'Stop' $resolved = Resolve-Path -LiteralPath $Path -ErrorAction Stop if (-not (Test-Path -LiteralPath $resolved -PathType Container)) { throw "Укажите папку библиотеки: $resolved" } $issues = [System.Collections.Generic.List[object]]::new() $videoExtensions = @('.mkv', '.mp4', '.avi', '.mov', '.m4v') $movies = Join-Path $resolved 'Movies' if (Test-Path -LiteralPath $movies -PathType Container) { foreach ($folder in Get-ChildItem -LiteralPath $movies -Directory -ErrorAction SilentlyContinue) { if ($folder.Name -notmatch '\(\d{4}\)$') { $issues.Add([pscustomobject]@{ Area = 'Movies'; Item = $folder.FullName; Problem = 'Нет года в имени папки' }) } $video = Get-ChildItem -LiteralPath $folder.FullName -File -ErrorAction SilentlyContinue | Where-Object { $_.Extension -in $videoExtensions } | Select-Object -First 1 if (-not $video) { $issues.Add([pscustomobject]@{ Area = 'Movies'; Item = $folder.FullName; Problem = 'Нет видеофайла' }) } } } else { $issues.Add([pscustomobject]@{ Area = 'Movies'; Item = $movies; Problem = 'Папка Movies не найдена' }) } $tv = Join-Path $resolved 'TV Shows' if (-not (Test-Path -LiteralPath $tv -PathType Container)) { $tv = Join-Path $resolved 'TV' } if (Test-Path -LiteralPath $tv -PathType Container) { foreach ($show in Get-ChildItem -LiteralPath $tv -Directory -ErrorAction SilentlyContinue) { $seasons = @(Get-ChildItem -LiteralPath $show.FullName -Directory -ErrorAction SilentlyContinue | Where-Object { $_.Name -match '^Season \d{2}$' }) if ($seasons.Count -eq 0) { $issues.Add([pscustomobject]@{ Area = 'TV'; Item = $show.FullName; Problem = 'Нет папок Season NN' }) continue } foreach ($season in $seasons) { foreach ($file in Get-ChildItem -LiteralPath $season.FullName -File -ErrorAction SilentlyContinue) { if ($file.Extension -notin $videoExtensions) { continue } if ($file.Name -notmatch '(?i)S\d{2}E\d{2,3}') { $issues.Add([pscustomobject]@{ Area = 'TV'; Item = $file.FullName; Problem = 'Нет SxxEyy в имени' }) } } } } } else { $issues.Add([pscustomobject]@{ Area = 'TV'; Item = $tv; Problem = 'Папка TV Shows не найдена' }) } if ($issues.Count -eq 0) { Write-Host 'Явных проблем структуры Plex не найдено.' exit 0 } $issues | Format-Table -AutoSize -Wrap Write-Host "Проблем: $($issues.Count)" if ($Csv) { $issues | Export-Csv -LiteralPath $Csv -NoTypeInformation -Encoding UTF8 Write-Host "Отчёт сохранён: $Csv" }