Files
immich-tv-viewer/tools/immich_count_all_photos.ps1

64 lines
1.5 KiB
PowerShell

param(
[string]$Server = "http://192.168.1.29:2283",
[int]$Size = 250
)
if (-not $env:IMMICH_KEY -and -not $IMMICH_KEY) {
Write-Host "ERREUR: définis d'abord la clé API :" -ForegroundColor Red
Write-Host '$env:IMMICH_KEY = "TA_CLE_API"'
exit 1
}
$key = if ($env:IMMICH_KEY) { $env:IMMICH_KEY } else { $IMMICH_KEY }
$total = 0
$page = 1
$nextPage = "1"
while ($null -ne $nextPage -and $nextPage -ne "") {
Write-Host "Lecture page $page..." -ForegroundColor Yellow
$body = @{
type = "IMAGE"
size = $Size
page = $page
order = "desc"
withArchived = $false
withDeleted = $false
withPeople = $false
withStacked = $true
} | ConvertTo-Json
$result = Invoke-RestMethod `
-Uri "$Server/api/search/metadata" `
-Headers @{ "x-api-key" = $key } `
-Method POST `
-ContentType "application/json" `
-Body $body
$items = @()
if ($result.assets -and $result.assets.items) {
$items = @($result.assets.items)
$nextPage = $result.assets.nextPage
} elseif ($result.items) {
$items = @($result.items)
$nextPage = $result.nextPage
} else {
$nextPage = $null
}
$imageItems = @($items | Where-Object { $_.type -eq "IMAGE" -and $_.isTrashed -ne $true })
$total += $imageItems.Count
Write-Host "Page $page : $($imageItems.Count) photos, total provisoire : $total" -ForegroundColor Cyan
if ($null -eq $nextPage -or $nextPage -eq "") {
break
}
$page = [int]$nextPage
}
Write-Host ""
Write-Host "TOTAL PHOTOS COMPTEES : $total" -ForegroundColor Green