From 2225ec2572da9381ec9f18e04f33c59702acd8fd Mon Sep 17 00:00:00 2001 From: jvlflame Date: Sun, 9 Aug 2020 15:25:47 -0700 Subject: [PATCH] Update for pipeline input --- .../Private/Convert-CommaDelimitedString.ps1 | 4 +- .../Private/Convert-HTMLCharacter.ps1 | 4 +- src/Javinizer/Private/Get-VideoFile.ps1 | 40 +++++++++---------- .../Private/Test-RequiredMetadata.ps1 | 5 +-- src/Javinizer/Public/Write-JLog.ps1 | 33 +++++++++++++++ 5 files changed, 59 insertions(+), 27 deletions(-) create mode 100644 src/Javinizer/Public/Write-JLog.ps1 diff --git a/src/Javinizer/Private/Convert-CommaDelimitedString.ps1 b/src/Javinizer/Private/Convert-CommaDelimitedString.ps1 index 85134e3f..11957484 100644 --- a/src/Javinizer/Private/Convert-CommaDelimitedString.ps1 +++ b/src/Javinizer/Private/Convert-CommaDelimitedString.ps1 @@ -1,7 +1,7 @@ function Convert-CommaDelimitedString { [CmdletBinding()] param ( - [Parameter(Mandatory = $true, Position = 0)] + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [string]$String ) @@ -17,7 +17,7 @@ function Convert-CommaDelimitedString { $stringArray = $String } - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Begin string: [$String], End string [$stringArray]" + Write-JLog -Level Debug -Message "Begin string: [$String], End string [$stringArray]" Write-Output $stringArray } } diff --git a/src/Javinizer/Private/Convert-HTMLCharacter.ps1 b/src/Javinizer/Private/Convert-HTMLCharacter.ps1 index 12e03347..1c59419d 100644 --- a/src/Javinizer/Private/Convert-HTMLCharacter.ps1 +++ b/src/Javinizer/Private/Convert-HTMLCharacter.ps1 @@ -1,6 +1,7 @@ function Convert-HTMLCharacter { [CmdletBinding()] param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [string]$String ) @@ -17,8 +18,7 @@ function Convert-HTMLCharacter { -replace ''', '' $newString = $String.Trim() - # Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Begin String: [$String]; End string: [$newString]" + # Write-JLog -Level Debug -Message "Begin String: [$String]; End string: [$newString]" Write-Output $newString - } } diff --git a/src/Javinizer/Private/Get-VideoFile.ps1 b/src/Javinizer/Private/Get-VideoFile.ps1 index 20cd9beb..04a310b2 100644 --- a/src/Javinizer/Private/Get-VideoFile.ps1 +++ b/src/Javinizer/Private/Get-VideoFile.ps1 @@ -3,45 +3,45 @@ function Get-VideoFile { param ( [Parameter(Position = 0)] [string]$Path, - [int]$FileSize, + [Parameter()] [switch]$Recurse, - [object]$Settings + [Parameter()] + [int]$MinimumFileSize, + [Parameter()] + [array]$ExcludedStrings, + [Parameter()] + [array]$IncludedExtensions, + [Parameter()] + [string]$RegexEnabled, + [Parameter()] + [string]$RegexString ) begin { - $fileExtensions = @() - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function started" - $FileSize = $Settings.General.'minimum-filesize-to-sort' + Write-JLog -Level Debug -Message "Function started" } process { - $fixedPath = ($Path).replace('`[', '[').replace('`]', ']') - $excludedStrings = Convert-CommaDelimitedString -String $Settings.General.'excluded-file-strings' - $extensionArray = Convert-CommaDelimitedString -String $Settings.General.'included-file-extensions' - foreach ($extension in $extensionArray) { - $fileExtensions += ('.' + $extension) - } - - if ($excludedStrings) { - $files = Get-ChildItem -LiteralPath $fixedPath -Recurse:$Recurse -Exclude:$excludedStrings | Where-Object { - $_.Extension -in $fileExtensions ` + if ($ExcludedStrings) { + $files = Get-ChildItem -LiteralPath $Path -Recurse:$Recurse -Exclude:$ExcludedStrings | Where-Object { + $_.Extension -in $IncludedExtensions ` -and $_.Length -ge ($FileSize * 1MB) } } else { - $files = Get-ChildItem -LiteralPath $fixedPath -Recurse:$Recurse | Where-Object { - $_.Extension -in $fileExtensions ` + $files = Get-ChildItem -LiteralPath $Path -Recurse:$Recurse | Where-Object { + $_.Extension -in $IncludedExtensions ` -and $_.Length -ge ($FileSize * 1MB) } } - if ($Settings.General.'regex-match' -eq 'True') { - $files = $files | Where-Object { $_.BaseName -match ($Settings.General.regex) } + if ($RegexEnabled -eq 'true') { + $files = $files | Where-Object { $_.BaseName -match $RegexString } } Write-Output $files } end { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function ended" + Write-JLog -Level Debug -Message "Function ended" } } diff --git a/src/Javinizer/Private/Test-RequiredMetadata.ps1 b/src/Javinizer/Private/Test-RequiredMetadata.ps1 index 3a1543cd..3f9416a8 100644 --- a/src/Javinizer/Private/Test-RequiredMetadata.ps1 +++ b/src/Javinizer/Private/Test-RequiredMetadata.ps1 @@ -8,7 +8,7 @@ function Test-RequiredMetadata { ) begin { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function started" + Write-JLog -Level Debug -Message "Function started" $nullFields = @() $errors = 0 } @@ -35,7 +35,6 @@ function Test-RequiredMetadata { } end { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function ended" + Write-JLog -Level Debug -Message "Function ended" } } - diff --git a/src/Javinizer/Public/Write-JLog.ps1 b/src/Javinizer/Public/Write-JLog.ps1 new file mode 100644 index 00000000..ef033752 --- /dev/null +++ b/src/Javinizer/Public/Write-JLog.ps1 @@ -0,0 +1,33 @@ +function Write-JLog { + [CmdletBinding()] + param ( + [Parameter()] + [string]$Message, + [Parameter()] + [ValidateSet('Debug', 'Info', 'Warning', 'Error')] + [string]$Level, + [Parameter()] + [ValidateSet('Break', 'Continue', 'Ignore', 'Inquire', 'SilentlyContinue', 'Stop', 'Suspend')] + [string]$Action = 'Stop' + ) + + if ($Level -eq 'Debug') { + Write-Debug -Message $Message + Write-Log -Level $Level -Message $Message | Wait-Logging + } + + if ($Level -eq 'Info') { + Write-Host $Message + Write-Log -Level $Level -Message $Message | Wait-Logging + } + + if ($Level -eq 'Warning') { + Write-Warning -Message $Message + Write-Log -Level $Level -Message $Message | Wait-Logging + } + + if ($Level -eq 'Error') { + Write-Log -Level $Level -Message $Message | Wait-Logging + Write-Error $Message -ErrorAction $Action + } +}