Skip to content

Commit

Permalink
feat: add currently running detection
Browse files Browse the repository at this point in the history
Closes #122
  • Loading branch information
fscorrupt committed May 2, 2024
1 parent c4ab0e7 commit d775ad3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
42 changes: 37 additions & 5 deletions Posterizarr.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ param (
[string]$mediatype
)

$CurrentScriptVersion = "1.2.16"
$CurrentScriptVersion = "1.2.17"
$global:HeaderWritten = $false
$ProgressPreference = 'SilentlyContinue'

Expand Down Expand Up @@ -2720,7 +2720,6 @@ if ($env:POWERSHELL_DISTRIBUTION_CHANNEL -like 'PSDocker-Alpine*') {
$global:NotifyUrl = $config.Notification.Discord
if ($global:NotifyUrl -eq 'https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}' -and $global:SendNotification -eq 'True') {
Write-Entry -Message "Found default Notification Url, please update url in config..." -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Red -log Error
Pause
Exit
}
}
Expand All @@ -2732,7 +2731,6 @@ Else {
$global:NotifyUrl = $config.Notification.Discord
if ($global:NotifyUrl -eq 'https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}' -and $global:SendNotification -eq 'True') {
Write-Entry -Message "Found default Notification Url, please update url in config..." -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Red -log Error
Pause
Exit
}
}
Expand Down Expand Up @@ -2963,13 +2961,32 @@ foreach ($path in $LogsPath, $TempPath, $TestPath, $AssetPath) {
New-Item -ItemType Directory -Path $path -Force | Out-Null
}
}
# Check temp dir if there is a Currently running file present
$CurrentlyRunning = Join-Path $TempPath 'Posterizarr.Running'

if (Test-Path $CurrentlyRunning) {
Write-Entry -Message "Another Posterizarr instance already running, exiting now..." -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Yellow -log Warning
Write-Entry -Subtext "If its a false positive message you can manually delete the 'Posterizarr.Running' file in temp dir..." -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Cyan -log Warning
Exit
}
Else {
New-Item -Path $CurrentlyRunning -Force | out-null

if ($Tautulli) {
Write-Entry -Message "Recently Added running file created..." -Path $global:ScriptRoot\Logs\Scriptlog.log -Color White -log Info
}
Elseif ($Testing) {
Write-Entry -Message "Testing running file created..." -Path $global:ScriptRoot\Logs\Scriptlog.log -Color White -log Info
}
Else {
Write-Entry -Message "Posterizarr running file created..." -Path $global:ScriptRoot\Logs\Scriptlog.log -Color White -log Info
}
}
# Delete all files and subfolders within the temp directory
if (Test-Path $TempPath) {
Remove-Item -Path (Join-Path $TempPath '*') -Recurse -Force
Get-ChildItem -Path (Join-Path $TempPath '*') -Recurse | Where-Object { $_.Name -ne 'Posterizarr.Running' } | Remove-Item -Force
Write-Entry -Message "Deleting temp folder: $TempPath" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color White -log Info
}

if ($Testing) {
if ((Test-Path $TestPath)) {
Remove-Item -Path (Join-Path $TestPath '*') -Recurse -Force
Expand Down Expand Up @@ -4158,6 +4175,11 @@ Elseif ($Testing) {
}
}
}

# Clear Running File
if (Test-Path $CurrentlyRunning) {
Remove-Item -LiteralPath $CurrentlyRunning | out-null
}
}
Elseif ($Tautulli) {
# Get Plex data for this Show/Movie
Expand Down Expand Up @@ -7280,6 +7302,11 @@ Elseif ($Tautulli) {
Write-Entry -Message "No ImageChoices.csv found, creating dummy file for you..." -Path $global:ScriptRoot\Logs\Scriptlog.log -Color White -log Info
}
Write-Entry -Message "Script execution time: $FormattedTimespawn" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color White -log Info

# Clear Running File
if (Test-Path $CurrentlyRunning) {
Remove-Item -LiteralPath $CurrentlyRunning | out-null
}
}
else {
Write-Entry -Message "Query plex libs..." -Path $global:ScriptRoot\Logs\Scriptlog.log -Color White -log Info
Expand Down Expand Up @@ -10577,4 +10604,9 @@ else {
Push-ObjectToDiscord -strDiscordWebhook $global:NotifyUrl -objPayload $jsonPayload
}
}

# Clear Running File
if (Test-Path $CurrentlyRunning) {
Remove-Item -LiteralPath $CurrentlyRunning | out-null
}
}
2 changes: 1 addition & 1 deletion Release.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.16
1.2.17

0 comments on commit d775ad3

Please sign in to comment.