Last active
February 4, 2018 09:46
-
-
Save chrisbrownie/01d53d6fa96059f6f4d613b1221e6376 to your computer and use it in GitHub Desktop.
Downloads photos from an Olympus camera
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$CameraIp = "192.168.0.10" | |
$DateFrom = Get-Date "29 December 2017" | |
function Invoke-OLApiCommand { | |
Param( | |
[String]$Command, | |
[String]$Arguments | |
) | |
$CommandVerb = $Command.Split("_")[0] | |
$CommandNoun = $Command.Split("_")[1] | |
if ($Arguments) { | |
$ApiUrl = "http://{0}/{1}.cgi?{2}" -f $CameraIp,$Command,$Arguments | |
} else { | |
$ApiUrl = "http://{0}/{1}.cgi" -f $CameraIp,$Command | |
} | |
$response = Invoke-WebRequest -Uri $ApiUrl | Select-Object -ExpandProperty Content | |
try { | |
[xml]$response | |
} catch { | |
$response.Split("`n") | |
} | |
} | |
function Convert-OLDateTimeToDateTime { | |
Param( | |
$Date, | |
$Time | |
) | |
$DateBinary = [Convert]::ToString($Date,2) | |
$TimeBinary = [Convert]::ToString($Time,2) | |
# Olympus date format: | |
# Bits 0-4 = day | |
# Bits 5-8 = month | |
# Bits 9-15 = year - 1980 | |
# | |
# Olympus time format | |
# Bits 0-4 = seconds/2 | |
# Bits 5-10 = minutes | |
# bits 11-15 = hours (24) | |
$Day = [Convert]::ToInt32($DateBinary[-5..-1] -join "",2) | |
$Month = [Convert]::ToInt32($DateBinary[-9..-6] -join "",2) | |
$Year = [Convert]::ToInt32($DateBinary[-16..-10] -join "",2) + 1980 | |
$Seconds = [Convert]::ToInt32($TimeBinary[-5..-1] -join "",2) * 2 | |
$Minutes = [Convert]::ToInt32($TimeBinary[-11..-6] -join "",2) | |
$Hours = [Convert]::ToInt32($TimeBinary[-16..-12] -join "",2) | |
Get-Date -Day $Day -Month $Month -Year $Year -Second $Seconds -Minute $Minutes -Hour $hours | |
} | |
function Get-OLImages { | |
$ImageList = Invoke-OLApiCommand -command "get_imglist" -Arguments "DIR=/DCIM/100OLYMP" | |
$ImageResults = @() | |
foreach ($image in $ImageList) { | |
# Make sure it's not the version specifier line | |
if ($image -ne "VER_100") { | |
$imageBits = $image.Split(",") | |
$ImageResults += New-Object -TypeName PSObject -Property @{ | |
Directory=$imageBits[0] | |
Filename=$imageBits[1] | |
Size=$imageBits[2] | |
TimeStamp=$(try { Convert-OLDateTimeToDateTime -Date $imageBits[4] -Time $imageBits[5] } catch { } ) | |
} | |
} | |
} | |
# Return those after $DateFrom | |
$ImageResults | Where-Object { $_.TimeStamp -gt $DateFrom } | |
} | |
$Images = Get-OLImages | |
$ImageProgress = 1 | |
$ImageCount = $Images.Count | |
foreach ($image in $Images) { | |
$imageUrl = "http://{0}{1}/{2}" -f $CameraIp, $image.Directory, $image.Filename | |
"Getting $ImageProgress of $ImageCount" | |
Invoke-WebRequest -Uri $imageUrl -OutFile $image.Filename | |
$ImageProgress++ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment