Skip to content

Commit

Permalink
Update for pipeline input
Browse files Browse the repository at this point in the history
  • Loading branch information
jvlflame committed Aug 9, 2020
1 parent f8cdb56 commit 2225ec2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 27 deletions.
4 changes: 2 additions & 2 deletions 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
)

Expand All @@ -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
}
}
4 changes: 2 additions & 2 deletions src/Javinizer/Private/Convert-HTMLCharacter.ps1
@@ -1,6 +1,7 @@
function Convert-HTMLCharacter {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
[string]$String
)

Expand All @@ -17,8 +18,7 @@ function Convert-HTMLCharacter {
-replace '&#039', ''

$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

}
}
40 changes: 20 additions & 20 deletions src/Javinizer/Private/Get-VideoFile.ps1
Expand Up @@ -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"
}
}
5 changes: 2 additions & 3 deletions src/Javinizer/Private/Test-RequiredMetadata.ps1
Expand Up @@ -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
}
Expand All @@ -35,7 +35,6 @@ function Test-RequiredMetadata {
}

end {
Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function ended"
Write-JLog -Level Debug -Message "Function ended"
}
}

33 changes: 33 additions & 0 deletions 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
}
}

0 comments on commit 2225ec2

Please sign in to comment.