From 8edce73375718448e9ebc9bae192c808efc20c1b Mon Sep 17 00:00:00 2001 From: Rouzax Date: Wed, 31 May 2023 09:41:33 +0200 Subject: [PATCH] Fixed issue #3 --- TorrentScript.ps1 | 66 ++++++++++++-------------- functions/CleanProcessPath.ps1 | 11 ++--- functions/Get-Input.ps1 | 3 +- functions/Import-Medusa.ps1 | 18 +++---- functions/Import-Radarr.ps1 | 15 ++---- functions/New-Mutex.ps1 | 6 +-- functions/Remove-Mutex.ps1 | 3 +- functions/Start-MKV-Subtitle-Strip.ps1 | 39 +++++---------- functions/Start-RoboCopy.ps1 | 21 +++----- functions/Start-SubEdit.ps1 | 6 +-- functions/Start-Subliminal.ps1 | 9 ++-- functions/Start-UnRar.ps1 | 6 +-- functions/Stop-Script.ps1 | 3 +- functions/Test-Variable-Path.ps1 | 2 +- functions/Write-HTMLLog.ps1 | 12 ++--- 15 files changed, 82 insertions(+), 138 deletions(-) diff --git a/TorrentScript.ps1 b/TorrentScript.ps1 index d86889d..3811d58 100644 --- a/TorrentScript.ps1 +++ b/TorrentScript.ps1 @@ -25,8 +25,7 @@ param( try { $configPath = Join-Path $PSScriptRoot 'config.json' $Config = Get-Content $configPath -ErrorAction Stop | ConvertFrom-Json -ErrorAction Stop -} -catch { +} catch { Write-Host 'Exception:' $_.Exception.Message -ForegroundColor Red Write-Host 'Invalid config.json file' -ForegroundColor Red exit 1 @@ -88,14 +87,13 @@ $WantedLanguages = $Config.WantedLanguages $SubtitleNamesToRemove = $Config.SubtitleNamesToRemove # Get function definition files. -$Functions = @( Get-ChildItem -Path $PSScriptRoot\functions\*.ps1 -ErrorAction SilentlyContinue ) +$Functions = @( Get-ChildItem -Path $PSScriptRoot\functions\*.ps1 -ErrorAction SilentlyContinue ) # Dot source the files ForEach ($import in @($Functions)) { Try { # Lightweight alternative to dotsourcing a function script . ([ScriptBlock]::Create([System.Io.File]::ReadAllText($import))) - } - Catch { + } Catch { Write-Error -Message "Failed to import function $($import.fullname): $_" } } @@ -108,10 +106,11 @@ Test-Variable-Path -Path $SubtitleEditPath -Name 'SubtitleEditPath' Test-Variable-Path -Path $SubliminalPath -Name 'SubliminalPath' Test-Variable-Path -Path $MailSendPath -Name 'MailSendPath' - # Get input if no parameters defined # Build the download Location, this is the Download Root Path added with the Download name -if ( ($Null -eq $DownloadPath) -or ($DownloadPath -eq '') ) { +if ($PSBoundParameters.ContainsKey('DownloadPath')) { + Write-Host "Download Path is defined" +} else { $DownloadPath = Get-Input -Message 'Download Name' -Required $DownloadPath = Join-Path -Path $DownloadRootPath -ChildPath $DownloadPath } @@ -120,9 +119,18 @@ if ( ($Null -eq $DownloadPath) -or ($DownloadPath -eq '') ) { $DownloadName = Split-Path -Path $DownloadPath -Leaf # Download Label -if ( ($Null -eq $DownloadLabel) -or ($DownloadLabel -eq '') ) { - $DownloadLabel = Get-Input -Message 'Download Label' +if ($PSBoundParameters.ContainsKey('DownloadLabel')) { + Write-Host "Download Label is defined" + # Handle empty Torrent Label +} else { + $DownloadLabel = Get-Input -Message 'Download Label' } + +# Handle Empty Download Label +if ($DownloadLabel -eq '') { + $DownloadLabel = 'NoLabel' +} + # Torrent Hash (only needed for Radarr) if ( ($Null -eq $TorrentHash) -or ($TorrentHash -eq '') ) { $TorrentHash = Get-Input -Message 'Torrent Hash' @@ -137,11 +145,6 @@ if ($DownloadLabel -eq 'NoProcess') { Exit } -# Handle empty Torrent Label -if ($DownloadLabel -eq '') { - $DownloadLabel = 'NoLabel' -} - # Create Log file # Log file of current processing file (will be used to send out the mail) $LogFilePath = Join-Path -Path $LogArchivePath -ChildPath "$LogFileDateFormat-$DownloadName.html" @@ -155,10 +158,10 @@ Write-HTMLLog -Column1 'Name:' -Column2 $DownloadName Write-HTMLLog -Column1 'Hash:' -Column2 $TorrentHash # Test File Paths -If (!(Test-Path -LiteralPath $ProcessPath)) { +If (!(Test-Path -LiteralPath $ProcessPath)) { New-Item -ItemType Directory -Force -Path $ProcessPath | Out-Null } -If (!(Test-Path -LiteralPath $LogArchivePath)) { +If (!(Test-Path -LiteralPath $LogArchivePath)) { New-Item -ItemType Directory -Force -Path $LogArchivePath | Out-Null } @@ -169,7 +172,7 @@ $ScriptMutex = New-Mutex -MutexName 'DownloadScript' $StopWatch = [system.diagnostics.stopwatch]::startNew() # Check paths from Parameters -If (!(Test-Path -LiteralPath $DownloadPath)) { +If (!(Test-Path -LiteralPath $DownloadPath)) { Write-Host "$DownloadPath - Not valid location" Write-HTMLLog -Column1 'Path:' -Column2 "$DownloadPath - Not valid location" -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' @@ -184,8 +187,7 @@ $Folder = (Get-Item -LiteralPath $DownloadPath) -is [System.IO.DirectoryInfo] if ($Folder) { $ProcessPathFull = Join-Path -Path $ProcessPath -ChildPath $DownloadLabel | Join-Path -ChildPath $DownloadName $RarFilePaths = (Get-ChildItem -LiteralPath $DownloadPath -Recurse -Filter '*.rar').FullName -} -elseif ($SingleFile) { +} elseif ($SingleFile) { $ProcessPathFull = Join-Path -Path $ProcessPath -ChildPath $DownloadLabel | Join-Path -ChildPath $DownloadName.Substring(0, $DownloadName.LastIndexOf('.')) $DownloadRootPath = Split-Path -Path $DownloadPath if ([IO.Path]::GetExtension($DownloadPath) -eq '.rar') { @@ -197,13 +199,12 @@ elseif ($SingleFile) { $RarCount = $RarFilePaths.Count if ($RarCount -gt 0) { $RarFile = $true -} -else { +} else { $RarFile = $false } # Check is destination folder exists otherwise create it -If (!(Test-Path -LiteralPath $ProcessPathFull)) { +If (!(Test-Path -LiteralPath $ProcessPathFull)) { New-Item -ItemType Directory -Force -Path $ProcessPathFull | Out-Null } @@ -219,12 +220,10 @@ if ($RarFile) { $UnRarStopWatch.Stop() Write-HTMLLog -Column1 'Size:' -Column2 (Format-Size -SizeInBytes $TotalSize) Write-HTMLLog -Column1 'Throughput:' -Column2 "$(Format-Size -SizeInBytes ($TotalSize/$UnRarStopWatch.Elapsed.TotalSeconds))/s" -} -elseif (-not $RarFile -and $SingleFile) { +} elseif (-not $RarFile -and $SingleFile) { Write-HTMLLog -Column1 '*** Single File ***' -Header Start-RoboCopy -Source $DownloadRootPath -Destination $ProcessPathFull -File $DownloadName -} -elseif (-not $RarFile -and $Folder) { +} elseif (-not $RarFile -and $Folder) { Write-HTMLLog -Column1 '*** Folder ***' -Header Start-RoboCopy -Source $DownloadPath -Destination $ProcessPathFull -File '*.*' } @@ -236,8 +235,7 @@ if ($DownloadLabel -eq $TVLabel) { $MKVCount = $MKVFiles.Count if ($MKVCount -gt 0) { $MKVFile = $true - } - else { + } else { $MKVFile = $false } if ($MKVFile) { @@ -261,8 +259,7 @@ if ($DownloadLabel -eq $TVLabel) { Write-HTMLLog -Column1 ' ' -Column2 $srt.name } } - } - else { + } else { Write-HTMLLog -Column1 '*** Files ***' -Header $Files = Get-ChildItem -LiteralPath $ProcessPathFull -Recurse -Filter '*.*' foreach ($File in $Files) { @@ -274,14 +271,12 @@ if ($DownloadLabel -eq $TVLabel) { Import-Medusa -Source $ProcessPathFull CleanProcessPath -Path $ProcessPathFull -NoCleanUp $NoCleanUp Stop-Script -ExitReason "$DownloadLabel - $DownloadName" -} -elseif ($DownloadLabel -eq $MovieLabel) { +} elseif ($DownloadLabel -eq $MovieLabel) { $MKVFiles = Get-ChildItem -LiteralPath $ProcessPathFull -Recurse -Filter '*.mkv' $MKVCount = $MKVFiles.Count if ($MKVCount -gt 0) { $MKVFile = $true - } - else { + } else { $MKVFile = $false } if ($MKVFile) { @@ -303,8 +298,7 @@ elseif ($DownloadLabel -eq $MovieLabel) { foreach ($Srt in $SrtFiles) { Write-HTMLLog -Column1 ' ' -Column2 $srt.name } - } - else { + } else { Write-HTMLLog -Column1 '*** Files ***' -Header $Files = Get-ChildItem -LiteralPath $ProcessPathFull -Recurse -Filter '*.*' foreach ($File in $Files) { diff --git a/functions/CleanProcessPath.ps1 b/functions/CleanProcessPath.ps1 index ea38673..bd0dcbb 100644 --- a/functions/CleanProcessPath.ps1 +++ b/functions/CleanProcessPath.ps1 @@ -19,8 +19,7 @@ function CleanProcessPath { Try { . $PSScriptRoot\$commandName.ps1 Write-Host "$commandName Function loaded." -ForegroundColor Green - } - Catch { + } Catch { Write-Error -Message "Failed to import $commandName function: $_" exit 1 } @@ -30,14 +29,12 @@ function CleanProcessPath { if ($NoCleanUp) { Write-HTMLLog -Column1 'Cleanup' -Column2 'NoCleanUp switch was given at command line, leaving files' - } - else { + } else { try { - If (Test-Path -LiteralPath $ProcessPathFull) { + If (Test-Path -LiteralPath $ProcessPathFull) { Remove-Item -Force -Recurse -LiteralPath $ProcessPathFull } - } - catch { + } catch { Write-HTMLLog -Column1 'Exception:' -Column2 $_.Exception.Message -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' } diff --git a/functions/Get-Input.ps1 b/functions/Get-Input.ps1 index 4feefa0..8847d55 100644 --- a/functions/Get-Input.ps1 +++ b/functions/Get-Input.ps1 @@ -37,8 +37,7 @@ Function Get-Input { $Variable = Read-Host -Prompt "$Message" $Variable = $Variable.Trim() } - } - else { + } else { $Variable = Read-Host -Prompt "$Message" $Variable = $Variable.Trim() } diff --git a/functions/Import-Medusa.ps1 b/functions/Import-Medusa.ps1 index a5a3f43..b96d728 100644 --- a/functions/Import-Medusa.ps1 +++ b/functions/Import-Medusa.ps1 @@ -31,8 +31,7 @@ function Import-Medusa { Try { . $PSScriptRoot\$commandName.ps1 Write-Host "$commandName Function loaded." -ForegroundColor Green - } - Catch { + } Catch { Write-Error -Message "Failed to import $commandName function: $_" exit 1 } @@ -58,8 +57,7 @@ function Import-Medusa { Write-HTMLLog -Column1 '*** Medusa Import ***' -Header try { $response = Invoke-RestMethod -Uri "http://$MedusaHost`:$MedusaPort/api/v2/postprocess" -Method Post -Body $Body -Headers $headers - } - catch { + } catch { Write-HTMLLog -Column1 'Exception:' -Column2 $_.Exception.Message -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' Stop-Script -ExitReason "Medusa Error: $DownloadLabel - $DownloadName" @@ -70,8 +68,7 @@ function Import-Medusa { do { try { $status = Invoke-RestMethod -Uri "http://$MedusaHost`:$MedusaPort/api/v2/postprocess/$($response.queueItem.identifier)" -Method Get -Headers $headers - } - catch { + } catch { Write-HTMLLog -Column1 'Exception:' -Column2 $_.Exception.Message -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' Stop-Script -ExitReason "Medusa Error: $DownloadLabel - $DownloadName" @@ -92,19 +89,16 @@ function Import-Medusa { } Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' Stop-Script -ExitReason "Medusa Error: $DownloadLabel - $DownloadName" - } - else { + } else { Write-HTMLLog -Column1 'Result:' -Column2 'Successful' -ColorBg 'Success' } - } - else { + } else { Write-HTMLLog -Column1 'Medusa:' -Column2 $status.success -ColorBg 'Error' Write-HTMLLog -Column1 'Medusa:' -Column2 "Import Timeout: ($MedusaTimeOutMinutes) minutes" -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' Stop-Script -ExitReason "Medusa Error: $DownloadLabel - $DownloadName" } - } - else { + } else { Write-HTMLLog -Column1 'Medusa:' -Column2 $response.status -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' Stop-Script -ExitReason "Medusa Error: $DownloadLabel - $DownloadName" diff --git a/functions/Import-Radarr.ps1 b/functions/Import-Radarr.ps1 index 98f3f3f..05c8b24 100644 --- a/functions/Import-Radarr.ps1 +++ b/functions/Import-Radarr.ps1 @@ -30,8 +30,7 @@ function Import-Radarr { Try { . $PSScriptRoot\$commandName.ps1 Write-Host "$commandName Function loaded." -ForegroundColor Green - } - Catch { + } Catch { Write-Error -Message "Failed to import $commandName function: $_" exit 1 } @@ -53,8 +52,7 @@ function Import-Radarr { Write-HTMLLog -Column1 '*** Radarr Import ***' -Header try { $MoviesScanJob = Invoke-RestMethod -Uri "http://$RadarrHost`:$RadarrPort/api/v3/command" -Method Post -Body $Body -Headers $headers - } - catch { + } catch { Write-HTMLLog -Column1 'Exception:' -Column2 $_.Exception.Message -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' Stop-Script -ExitReason "Radarr Error: $DownloadLabel - $DownloadName" @@ -65,8 +63,7 @@ function Import-Radarr { do { try { $MoviesScanResult = Invoke-RestMethod -Uri "http://$RadarrHost`:$RadarrPort/api/v3/command/$($MoviesScanJob.id)" -Method Get -Headers $headers - } - catch { + } catch { Write-HTMLLog -Column1 'Exception:' -Column2 $_.Exception.Message -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' Stop-Script -ExitReason "Radarr Error: $DownloadLabel - $DownloadName" @@ -77,8 +74,7 @@ function Import-Radarr { if ($MoviesScanResult.status -eq 'completed') { if ($MoviesScanResult.result -eq 'successful') { Write-HTMLLog -Column1 'Result:' -Column2 'Successful' -ColorBg 'Success' - } - else { + } else { Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' Stop-Script -ExitReason "Radarr Error: $DownloadLabel - $DownloadName" } @@ -95,8 +91,7 @@ function Import-Radarr { Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' Stop-Script -ExitReason "Radarr Error: $DownloadLabel - $DownloadName" } - } - else { + } else { Write-HTMLLog -Column1 'Radarr:' -Column2 $MoviesScanJob.status -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' Stop-Script -ExitReason "Radarr Error: $DownloadLabel - $DownloadName" diff --git a/functions/New-Mutex.ps1 b/functions/New-Mutex.ps1 index 8f94862..8d4e541 100644 --- a/functions/New-Mutex.ps1 +++ b/functions/New-Mutex.ps1 @@ -44,16 +44,14 @@ function New-Mutex { [void][System.Reflection.Assembly]::LoadWithPartialName('System.Threading') try { $Mutex = [System.Threading.Mutex]::OpenExisting($MutexName) - } - catch { + } catch { $Mutex = New-Object System.Threading.Mutex($true, $MutexName, [ref]$MutexWasCreated) } try { if (!$MutexWasCreated) { $Mutex.WaitOne() | Out-Null } - } - catch { + } catch { } Write-Host "Lock [$MutexName] acquired. Executing..." -ForegroundColor DarkGray Write-Output ([PSCustomObject]@{ Name = $MutexName; Mutex = $Mutex }) diff --git a/functions/Remove-Mutex.ps1 b/functions/Remove-Mutex.ps1 index 91dd60a..26a272f 100644 --- a/functions/Remove-Mutex.ps1 +++ b/functions/Remove-Mutex.ps1 @@ -26,7 +26,6 @@ function Remove-Mutex { Write-Host "Releasing lock [$($MutexObject.Name)]..." -ForegroundColor DarkGray try { [void]$MutexObject.Mutex.ReleaseMutex() - } - catch { + } catch { } } # Remove-Mutex \ No newline at end of file diff --git a/functions/Start-MKV-Subtitle-Strip.ps1 b/functions/Start-MKV-Subtitle-Strip.ps1 index 3029818..e482e0e 100644 --- a/functions/Start-MKV-Subtitle-Strip.ps1 +++ b/functions/Start-MKV-Subtitle-Strip.ps1 @@ -34,8 +34,7 @@ function Start-MKV-Subtitle-Strip { Try { . $PSScriptRoot\$commandName.ps1 Write-Host "$commandName Function loaded." -ForegroundColor Green - } - Catch { + } Catch { Write-Error -Message "Failed to import $commandName function: $_" exit 1 } @@ -74,16 +73,13 @@ function Start-MKV-Subtitle-Strip { Write-HTMLLog -Column1 'Exit Code:' -Column2 $($Process.ExitCode) -ColorBg 'Error' Write-HTMLLog -Column1 'mkvmerge:' -Column2 $stdout -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' - } - elseif ($Process.ExitCode -eq 1) { + } elseif ($Process.ExitCode -eq 1) { Write-HTMLLog -Column1 'Exit Code:' -Column2 $($Process.ExitCode) -ColorBg 'Error' Write-HTMLLog -Column1 'mkvmerge:' -Column2 $stdout -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Warning' -ColorBg 'Error' - } - elseif ($Process.ExitCode -eq 0) { + } elseif ($Process.ExitCode -eq 0) { $fileMetadata = $stdout | ConvertFrom-Json - } - else { + } else { Write-HTMLLog -Column1 'Exit Code:' -Column2 $($Process.ExitCode) -ColorBg 'Error' Write-HTMLLog -Column1 'mkvmerge:' -Column2 $stdout -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Warning' -ColorBg 'Error' @@ -125,8 +121,7 @@ function Start-MKV-Subtitle-Strip { # Handle multiple subtitles of same language, if exist append ID to file if ("$($episode.FileName).$($FileTrack.properties.language).srt" -in $SubNamesToKeep) { $prefix = "$($FileTrack.id).$($FileTrack.properties.language)" - } - else { + } else { $prefix = "$($FileTrack.properties.language)" } @@ -138,8 +133,7 @@ function Start-MKV-Subtitle-Strip { # Add subtitle ID to for MKV remux $SubIDsToExtract += $FileTrack.id - } - else { + } else { $SubIDsToRemove += $FileTrack.id } } @@ -170,17 +164,14 @@ function Start-MKV-Subtitle-Strip { Write-HTMLLog -Column1 'Exit Code:' -Column2 $($Process.ExitCode) -ColorBg 'Error' Write-HTMLLog -Column1 'mkvextract:' -Column2 $stdout -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' - } - elseif ($Process.ExitCode -eq 1) { + } elseif ($Process.ExitCode -eq 1) { Write-HTMLLog -Column1 'Exit Code:' -Column2 $($Process.ExitCode) -ColorBg 'Error' Write-HTMLLog -Column1 'mkvextract:' -Column2 $stdout -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Warning' -ColorBg 'Error' - } - elseif ($Process.ExitCode -eq 0) { + } elseif ($Process.ExitCode -eq 0) { $SubsExtracted = $true # Write-HTMLLog -Column1 "Extracted:" -Column2 "$($SubsToExtract.count) Subtitles" - } - else { + } else { Write-HTMLLog -Column1 'Exit Code:' -Column2 $($Process.ExitCode) -ColorBg 'Error' Write-HTMLLog -Column1 'mkvextract:' -Column2 $stdout -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Unknown' -ColorBg 'Error' @@ -209,18 +200,15 @@ function Start-MKV-Subtitle-Strip { Write-HTMLLog -Column1 'Exit Code:' -Column2 $($Process.ExitCode) -ColorBg 'Error' Write-HTMLLog -Column1 'mkvmerge:' -Column2 $stdout -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' - } - elseif ($Process.ExitCode -eq 1) { + } elseif ($Process.ExitCode -eq 1) { Write-HTMLLog -Column1 'Exit Code:' -Column2 $($Process.ExitCode) -ColorBg 'Error' Write-HTMLLog -Column1 'mkvmerge:' -Column2 $stdout -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Warning' -ColorBg 'Error' - } - elseif ($Process.ExitCode -eq 0) { + } elseif ($Process.ExitCode -eq 0) { # Overwrite original mkv after successful remux Move-Item -Path $TmpMkvPath -Destination $($episode.FilePath) -Force # Write-HTMLLog -Column1 "Removed:" -Column2 "$($SubIDsToRemove.Count) unwanted subtitle languages" - } - else { + } else { Write-HTMLLog -Column1 'Exit Code:' -Column2 $($Process.ExitCode) -ColorBg 'Error' Write-HTMLLog -Column1 'mkvmerge:' -Column2 $stdout -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Warning' -ColorBg 'Error' @@ -252,8 +240,7 @@ function Start-MKV-Subtitle-Strip { Write-HTMLLog -Column1 'Subtitles:' -Column2 "$TotalSubsToRemove Removed" } Write-HTMLLog -Column1 'Result:' -Column2 'Successful' -ColorBg 'Success' - } - else { + } else { Write-HTMLLog -Column1 'Result:' -Column2 'No SRT subs found in MKV' } } \ No newline at end of file diff --git a/functions/Start-RoboCopy.ps1 b/functions/Start-RoboCopy.ps1 index 9217c96..f20f29f 100644 --- a/functions/Start-RoboCopy.ps1 +++ b/functions/Start-RoboCopy.ps1 @@ -41,8 +41,7 @@ function Start-RoboCopy { Try { . $PSScriptRoot\$commandName.ps1 Write-Host "$commandName Function loaded." -ForegroundColor Green - } - Catch { + } Catch { Write-Error -Message "Failed to import $commandName function: $_" exit 1 } @@ -52,8 +51,7 @@ function Start-RoboCopy { # Start if ($File -ne '*.*') { $options = @('/R:1', '/W:1', '/J', '/NP', '/NP', '/NJH', '/NFL', '/NDL', '/MT8') - } - elseif ($File -eq '*.*') { + } elseif ($File -eq '*.*') { $options = @('/R:1', '/W:1', '/E', '/J', '/NP', '/NJH', '/NFL', '/NDL', '/MT8') } @@ -64,8 +62,7 @@ function Start-RoboCopy { try { # executing Robocopy command $Output = robocopy @cmdArgs - } - catch { + } catch { Write-Host 'Exception:' $_.Exception.Message -ForegroundColor Red Write-Host 'RoboCopy not found' -ForegroundColor Red exit 1 @@ -114,16 +111,13 @@ function Start-RoboCopy { if ($column -eq 'k') { $tempByteArray[$tempByteArrayCounter - 1] = '{0:N2}' -f ([single]($bytes[$counter - 1]) * 1024) $counter += 1 - } - elseif ($column -eq 'm') { + } elseif ($column -eq 'm') { $tempByteArray[$tempByteArrayCounter - 1] = '{0:N2}' -f ([single]($bytes[$counter - 1]) * 1048576) $counter += 1 - } - elseif ($column -eq 'g') { + } elseif ($column -eq 'g') { $tempByteArray[$tempByteArrayCounter - 1] = '{0:N2}' -f ([single]($bytes[$counter - 1]) * 1073741824) $counter += 1 - } - else { + } else { $tempByteArray[$tempByteArrayCounter] = $column $counter += 1 $tempByteArrayCounter += 1 @@ -156,8 +150,7 @@ function Start-RoboCopy { Write-HTMLLog -Column1 'Size:' -Column2 "$FailedSize Failed" -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' Stop-Script -ExitReason "Copy Error: $DownloadLabel - $DownloadName" - } - else { + } else { Write-HTMLLog -Column1 'Dirs:' -Column2 "$CopiedDirs Copied" Write-HTMLLog -Column1 'Files:' -Column2 "$CopiedFiles Copied" Write-HTMLLog -Column1 'Size:' -Column2 "$CopiedSize" diff --git a/functions/Start-SubEdit.ps1 b/functions/Start-SubEdit.ps1 index 137341a..44075e3 100644 --- a/functions/Start-SubEdit.ps1 +++ b/functions/Start-SubEdit.ps1 @@ -38,8 +38,7 @@ function Start-SubEdit { Try { . $PSScriptRoot\$commandName.ps1 Write-Host "$commandName Function loaded." -ForegroundColor Green - } - Catch { + } Catch { Write-Error -Message "Failed to import $commandName function: $_" exit 1 } @@ -65,8 +64,7 @@ function Start-SubEdit { Write-HTMLLog -Column1 'Error:' -Column2 $stderr -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' Stop-Script -ExitReason "SubEdit Error: $DownloadLabel - $DownloadName" - } - else { + } else { Write-HTMLLog -Column1 'Result:' -Column2 'Successful' -ColorBg 'Success' } } \ No newline at end of file diff --git a/functions/Start-Subliminal.ps1 b/functions/Start-Subliminal.ps1 index 26aa8a6..42190d6 100644 --- a/functions/Start-Subliminal.ps1 +++ b/functions/Start-Subliminal.ps1 @@ -30,8 +30,7 @@ function Start-Subliminal { Try { . $PSScriptRoot\$commandName.ps1 Write-Host "$commandName Function loaded." -ForegroundColor Green - } - Catch { + } Catch { Write-Error -Message "Failed to import $commandName function: $_" exit 1 } @@ -73,8 +72,7 @@ function Start-Subliminal { Write-HTMLLog -Column1 'Exit Code:' -Column2 $($Process.ExitCode) -ColorBg 'Error' Write-HTMLLog -Column1 'Error:' -Column2 $stderr -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' - } - else { + } else { if ($SubsDownloaded -gt 0) { # Write-HTMLLog -Column1 "Downloaded:" -Column2 "$SubsDownloaded Subtitles" Write-HTMLLog -Column1 'Collected:' -Column2 "$VideoCollected Videos" @@ -82,8 +80,7 @@ function Start-Subliminal { Write-HTMLLog -Column1 'Error:' -Column2 "$VideoError Videos" Write-HTMLLog -Column1 'Downloaded:' -Column2 "$SubsDownloaded Subtitles" Write-HTMLLog -Column1 'Result:' -Column2 'Successful' -ColorBg 'Success' - } - else { + } else { Write-HTMLLog -Column1 'Result:' -Column2 'No subs downloaded with Subliminal' } } diff --git a/functions/Start-UnRar.ps1 b/functions/Start-UnRar.ps1 index 2956f76..3fdb22e 100644 --- a/functions/Start-UnRar.ps1 +++ b/functions/Start-UnRar.ps1 @@ -31,8 +31,7 @@ function Start-UnRar { Try { . $PSScriptRoot\$commandName.ps1 Write-Host "$commandName Function loaded." -ForegroundColor Green - } - Catch { + } Catch { Write-Error -Message "Failed to import $commandName function: $_" exit 1 } @@ -62,8 +61,7 @@ function Start-UnRar { Write-HTMLLog -Column1 'Error:' -Column2 $stderr -ColorBg 'Error' Write-HTMLLog -Column1 'Result:' -Column2 'Failed' -ColorBg 'Error' Stop-Script -ExitReason "Unrar Error: $DownloadLabel - $DownloadName" - } - else { + } else { Write-HTMLLog -Column1 'Result:' -Column2 'Successful' -ColorBg 'Success' } } \ No newline at end of file diff --git a/functions/Stop-Script.ps1 b/functions/Stop-Script.ps1 index f1afbc0..dd41b0e 100644 --- a/functions/Stop-Script.ps1 +++ b/functions/Stop-Script.ps1 @@ -30,8 +30,7 @@ function Stop-Script { Try { . $PSScriptRoot\$commandName.ps1 Write-Host "$commandName Function loaded." -ForegroundColor Green - } - Catch { + } Catch { Write-Error -Message "Failed to import $commandName function: $_" exit 1 } diff --git a/functions/Test-Variable-Path.ps1 b/functions/Test-Variable-Path.ps1 index f4bb4d6..fbefb62 100644 --- a/functions/Test-Variable-Path.ps1 +++ b/functions/Test-Variable-Path.ps1 @@ -30,7 +30,7 @@ function Test-Variable-Path { )] [string]$Name ) - if (!(Test-Path -LiteralPath $Path)) { + if (!(Test-Path -LiteralPath $Path)) { Write-Host "Cannot find: $Path" -ForegroundColor Red Write-Host "As defined in variable: $Name" -ForegroundColor Red Write-Host 'Will now exit!' -ForegroundColor Red diff --git a/functions/Write-HTMLLog.ps1 b/functions/Write-HTMLLog.ps1 index 240b84f..981dd84 100644 --- a/functions/Write-HTMLLog.ps1 +++ b/functions/Write-HTMLLog.ps1 @@ -32,8 +32,7 @@ function Format-Table { $global:Log += "" $global:Log += "" $global:Log += '' - } - else { + } else { $global:Log += '' $global:Log += '' } @@ -101,19 +100,16 @@ Function Write-HTMLLog { $global:Log += '' if ($Header) { $global:Log += "$Column1" - } - else { + } else { if ($ColorBg -eq '') { $global:Log += "$Column1" $global:Log += "$Column2" $global:Log += '' - } - elseif ($ColorBg -eq 'Success') { + } elseif ($ColorBg -eq 'Success') { $global:Log += "$Column1" $global:Log += "$Column2" $global:Log += '' - } - elseif ($ColorBg -eq 'Error') { + } elseif ($ColorBg -eq 'Error') { $global:Log += "$Column1" $global:Log += "$Column2" $global:Log += ''