[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" } $episodes = Get-ChildItem -LiteralPath $resolved -File -Recurse -ErrorAction SilentlyContinue | Where-Object { $_.Extension -in '.mkv', '.mp4', '.avi', '.mov', '.m4v' } | ForEach-Object { if ($_.Name -match '(?i)S(?\d{1,2})[ ._-]*E(?\d{1,3})') { [pscustomobject]@{ Season = [int]$Matches['season'] Episode = [int]$Matches['episode'] File = $_.FullName } } } if (-not $episodes) { Write-Host 'Эпизоды с номерами SxxEyy не найдены.' exit 0 } $rows = foreach ($group in ($episodes | Group-Object Season | Sort-Object { [int]$_.Name })) { $numbers = @($group.Group.Episode | Sort-Object -Unique) $minimum = ($numbers | Measure-Object -Minimum).Minimum $maximum = ($numbers | Measure-Object -Maximum).Maximum $missing = @($minimum..$maximum | Where-Object { $_ -notin $numbers }) if ($missing.Count -gt 0) { [pscustomobject]@{ Season = [int]$group.Name Episodes = $numbers.Count First = $minimum Last = $maximum Missing = ($missing -join ', ') } } } if (-not $rows) { Write-Host 'Пропусков в нумерации не найдено.' exit 0 } $rows | Format-Table -AutoSize -Wrap if ($Csv) { $rows | Export-Csv -LiteralPath $Csv -NoTypeInformation -Encoding UTF8 Write-Host "Отчёт сохранён: $Csv" }