astrostrings

get_pics.ps1

May 25th, 2026
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $immichBaseUrl = "http://192.168.0.7:2283/api"
  2. $apiKey = "API_KEY_HERE"
  3. $targetName = "Jane"
  4. $outputFolder = "C:\Users\sixstringnerd\Desktop\immichexport"
  5.  
  6. # 1. Quality Selection Menu
  7. Clear-Host
  8. Write-Host "==========================================" -ForegroundColor Cyan
  9. Write-Host "      IMMICH PHOTO EXPORT QUALITY         " -ForegroundColor Cyan
  10. Write-Host "==========================================" -ForegroundColor Cyan
  11. Write-Host "1. Original  (Full resolution, original file format)"
  12. Write-Host "2. Preview   (Medium size, converted to JPG)"
  13. Write-Host "3. Thumbnail (Small tile size, converted to JPG)"
  14. Write-Host "==========================================" -ForegroundColor Cyan
  15.  
  16. $choice = ""
  17. while ($choice -notin @("1", "2", "3")) {
  18.     $choice = Read-Host "Select quality option (1-3)"
  19. }
  20.  
  21. # Configure settings based on selection
  22. switch ($choice) {
  23.     "1" {
  24.         $qualityMode = "Original"
  25.         $endpointSuffix = "original"
  26.         Write-Host "Selected: Original quality files." -ForegroundColor Green
  27.     }
  28.     "2" {
  29.         $qualityMode = "Preview"
  30.         $endpointSuffix = "thumbnail?size=preview"
  31.         Write-Host "Selected: Medium preview JPEGs." -ForegroundColor Green
  32.     }
  33.     "3" {
  34.         $qualityMode = "Thumbnail"
  35.         $endpointSuffix = "thumbnail"
  36.         Write-Host "Selected: Small thumbnail JPEGs." -ForegroundColor Green
  37.     }
  38. }
  39.  
  40. # Create output directory if it does not exist
  41. if (-not (Test-Path -Path $outputFolder)) {
  42.     New-Item -ItemType Directory -Path $outputFolder -Force | Out-Null
  43. }
  44.  
  45. # Define the headers so the API key is actually sent!
  46. $headers = @{
  47.     "x-api-key" = $apiKey
  48.     "Accept" = "application/json"
  49. }
  50.  
  51. # 2. Get the Person ID automatically
  52. $personUrl = "$immichBaseUrl/search/person?name=$targetName"
  53. $personData = Invoke-RestMethod -Uri $personUrl -Headers $headers -Method Get
  54.  
  55. if ($personData.Count -eq 0) {
  56.     Write-Host "Person not found in Immich."
  57.     exit
  58. }
  59. $personId = $personData[0].id
  60. Write-Host "Found ID for ${targetName}: $personId"
  61.  
  62. # 3. Loop through pages of assets
  63. $page = 1
  64. $hasMore = $true
  65. $searchUrl = "$immichBaseUrl/search/metadata"
  66.  
  67. while ($hasMore) {
  68.     Write-Host "Fetching page $page..."
  69.     $searchBody = @{
  70.         personIds = @($personId)
  71.         size = 1000
  72.         page = $page
  73.         withPeople = $true  # Forces Immich to include the faces in the response
  74.     } | ConvertTo-Json -Depth 5
  75.  
  76.     $searchResponse = Invoke-RestMethod -Uri $searchUrl -Headers $headers -Method Post -Body $searchBody -ContentType "application/json"
  77.     $assets = $searchResponse.assets.items
  78.  
  79.     if ($assets.Count -eq 0) {
  80.         $hasMore = $false
  81.         continue
  82.     }
  83.  
  84.     # 4. Filter for solo shots and download
  85.     foreach ($asset in $assets) {
  86.         $peopleCount = @($asset.people).Count
  87.        
  88.         # Only check that our target person is the ONLY recognized person
  89.         if ($peopleCount -eq 1) {
  90.             $assetId = $asset.id
  91.             $fileName = $asset.originalFileName
  92.            
  93.             $downloadUrl = "$immichBaseUrl/assets/$assetId/$endpointSuffix"
  94.            
  95.             # Handle naming and file extensions based on choice
  96.             if ($qualityMode -eq "Original") {
  97.                 $outFile = Join-Path -Path $outputFolder -ChildPath "$assetId-$fileName"
  98.             } else {
  99.                 $baseName = [System.IO.Path]::GetFileNameWithoutExtension($fileName)
  100.                 $outFile = Join-Path -Path $outputFolder -ChildPath "$assetId-$baseName.jpg"
  101.             }
  102.            
  103.             Write-Host "Downloading ($qualityMode): $fileName"
  104.             Invoke-RestMethod -Uri $downloadUrl -Headers $headers -Method Get -OutFile $outFile
  105.         }
  106.     }
  107.     $page++
  108. }
  109.  
  110. Write-Host "Extraction complete!"
Advertisement
Add Comment
Please, Sign In to add comment