From 950fcef2f6b64106d3d1883ebb0d7f7d5d49617d Mon Sep 17 00:00:00 2001 From: Morten Strandbo Date: Thu, 30 Nov 2023 12:05:26 +0100 Subject: [PATCH] Added year-parameter --- TimelapseGenerator.ps1 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/TimelapseGenerator.ps1 b/TimelapseGenerator.ps1 index 6036d20..4ecefa3 100644 --- a/TimelapseGenerator.ps1 +++ b/TimelapseGenerator.ps1 @@ -5,10 +5,11 @@ # v1.2 - Some bugfixes for running as scheduled task, month-handling, etc. # v1.1 - A bit more dynamic, updated ffmpeg to newest available version, changed codec to x265, added parameter handling # v1.0 - Initial concept -param ($Camera,$Style='Daily',[string]$Month) +param ($Camera,$Style='Daily',[string]$Month,$Year) Set-Location $PSScriptRoot + if (!$Camera) { $Camera = Read-Host "Enter camera you want to process" } switch ($Style) { @@ -27,6 +28,11 @@ $CompletedTimelapseDir = "\\megabyte.home.zyrex.org\Mediavault\Privat\Timelapses $MonthProcess = (Get-Date).AddMonths(-1) $MonthProcess = $MonthProcess|Get-Date -Format MM +# Set this year if not passed +if (!$Year) { + $Year = (Get-Date).Year +} + # Use passed parameter if it exists if ($Month) { $MonthProcess = $Month @@ -36,11 +42,11 @@ if ($Month) { $photos = Get-ChildItem $TimelapsePhotoSrc if ($style -eq "Monthly") { - $Copyphotos = $photos | Where-Object {$_.name -Like "$($Camera)_????$($MonthProcess)??_12-00-??.jpg"} + $Copyphotos = $photos | Where-Object {$_.name -Like "$($Camera)_$($Year)$($MonthProcess)??_12-00-??.jpg"} } elseif ($Style -eq "Daily") { $photos = $photos|Where-Object {$_.length -gt 120000} # Maybe do a check on the size, it will require tuning - $Copyphotos = $photos | Where-Object {$_.name -Like "$($Camera)_????$($MonthProcess)*"} + $Copyphotos = $photos | Where-Object {$_.name -Like "$($Camera)_$($Year)$($MonthProcess)*"} } #elseif ($Style -eq "Yearly") { # # Takes all previous monthlies and combines them to a yearly timelapse @@ -54,7 +60,7 @@ $regex = '(?\d{4}(?:\.|-|_)?\d{2}(?:\.|-|_)?\d{2})[^0-9]' If($Copyphotos[1] -match $regex) { $date = $Matches['filedate'] -replace '(\.|-|_)','' $date = [datetime]::ParseExact($date,'yyyyMMdd',[cultureinfo]::InvariantCulture) - $Year = Get-date $date -Format yyyy +# $Year = Get-date $date -Format yyyy } foreach ($lapse in $Copyphotos) {