Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $immichBaseUrl = "http://192.168.0.7:2283/api"
- $apiKey = "API_KEY_HERE"
- $targetName = "Jane"
- $outputFolder = "C:\Users\sixstringnerd\Desktop\immichexport"
- # 1. Quality Selection Menu
- Clear-Host
- Write-Host "==========================================" -ForegroundColor Cyan
- Write-Host " IMMICH PHOTO EXPORT QUALITY " -ForegroundColor Cyan
- Write-Host "==========================================" -ForegroundColor Cyan
- Write-Host "1. Original (Full resolution, original file format)"
- Write-Host "2. Preview (Medium size, converted to JPG)"
- Write-Host "3. Thumbnail (Small tile size, converted to JPG)"
- Write-Host "==========================================" -ForegroundColor Cyan
- $choice = ""
- while ($choice -notin @("1", "2", "3")) {
- $choice = Read-Host "Select quality option (1-3)"
- }
- # Configure settings based on selection
- switch ($choice) {
- "1" {
- $qualityMode = "Original"
- $endpointSuffix = "original"
- Write-Host "Selected: Original quality files." -ForegroundColor Green
- }
- "2" {
- $qualityMode = "Preview"
- $endpointSuffix = "thumbnail?size=preview"
- Write-Host "Selected: Medium preview JPEGs." -ForegroundColor Green
- }
- "3" {
- $qualityMode = "Thumbnail"
- $endpointSuffix = "thumbnail"
- Write-Host "Selected: Small thumbnail JPEGs." -ForegroundColor Green
- }
- }
- # Create output directory if it does not exist
- if (-not (Test-Path -Path $outputFolder)) {
- New-Item -ItemType Directory -Path $outputFolder -Force | Out-Null
- }
- # Define the headers so the API key is actually sent!
- $headers = @{
- "x-api-key" = $apiKey
- "Accept" = "application/json"
- }
- # 2. Get the Person ID automatically
- $personUrl = "$immichBaseUrl/search/person?name=$targetName"
- $personData = Invoke-RestMethod -Uri $personUrl -Headers $headers -Method Get
- if ($personData.Count -eq 0) {
- Write-Host "Person not found in Immich."
- exit
- }
- $personId = $personData[0].id
- Write-Host "Found ID for ${targetName}: $personId"
- # 3. Loop through pages of assets
- $page = 1
- $hasMore = $true
- $searchUrl = "$immichBaseUrl/search/metadata"
- while ($hasMore) {
- Write-Host "Fetching page $page..."
- $searchBody = @{
- personIds = @($personId)
- size = 1000
- page = $page
- withPeople = $true # Forces Immich to include the faces in the response
- } | ConvertTo-Json -Depth 5
- $searchResponse = Invoke-RestMethod -Uri $searchUrl -Headers $headers -Method Post -Body $searchBody -ContentType "application/json"
- $assets = $searchResponse.assets.items
- if ($assets.Count -eq 0) {
- $hasMore = $false
- continue
- }
- # 4. Filter for solo shots and download
- foreach ($asset in $assets) {
- $peopleCount = @($asset.people).Count
- # Only check that our target person is the ONLY recognized person
- if ($peopleCount -eq 1) {
- $assetId = $asset.id
- $fileName = $asset.originalFileName
- $downloadUrl = "$immichBaseUrl/assets/$assetId/$endpointSuffix"
- # Handle naming and file extensions based on choice
- if ($qualityMode -eq "Original") {
- $outFile = Join-Path -Path $outputFolder -ChildPath "$assetId-$fileName"
- } else {
- $baseName = [System.IO.Path]::GetFileNameWithoutExtension($fileName)
- $outFile = Join-Path -Path $outputFolder -ChildPath "$assetId-$baseName.jpg"
- }
- Write-Host "Downloading ($qualityMode): $fileName"
- Invoke-RestMethod -Uri $downloadUrl -Headers $headers -Method Get -OutFile $outFile
- }
- }
- $page++
- }
- Write-Host "Extraction complete!"
Advertisement
Add Comment
Please, Sign In to add comment