Skip to content

Commit c6e95f1

Browse files
committed
feat: add IM Autoupdate
CLoses #128
1 parent 5849d4c commit c6e95f1

File tree

4 files changed

+71
-12
lines changed

4 files changed

+71
-12
lines changed

Posterizarr.ps1

+67-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ param (
88
[string]$mediatype
99
)
1010

11-
$CurrentScriptVersion = "1.2.27"
11+
$CurrentScriptVersion = "1.2.28"
1212
$global:HeaderWritten = $false
1313
$ProgressPreference = 'SilentlyContinue'
1414

@@ -2603,6 +2603,68 @@ function CheckImageMagick {
26032603
}
26042604
}
26052605
}
2606+
Else {
2607+
$CurrentImagemagickversion = & $magick -version
2608+
$CurrentImagemagickversion = [regex]::Match($CurrentImagemagickversion, 'Version: ImageMagick (\d+(\.\d+){1,2}-\d+)')
2609+
if ($global:OSType -eq "DockerAlpine"){
2610+
$Url = "https://pkgs.alpinelinux.org/package/edge/community/x86_64/imagemagick"
2611+
$response = Invoke-WebRequest -Uri $url
2612+
$htmlContent = $response.Content
2613+
$regexPattern = '<th class="header">Version<\/th>\s*<td>\s*<strong>\s*<a[^>]*>([^<]+)<\/a>\s*<\/strong>\s*<\/td>'
2614+
$Versionmatching = [regex]::Matches($htmlContent, $regexPattern)
2615+
2616+
if ($Versionmatching.Count -gt 0) {
2617+
$LatestImagemagickversion = $Versionmatching[0].Groups[1].Value.split('-')[0]
2618+
}
2619+
}
2620+
Elseif ($global:OSType -eq "Win32NT"){
2621+
$Url = "https://imagemagick.org/archive/binaries/?C=M;O=D"
2622+
$result = Invoke-WebRequest -Uri $Url
2623+
$LatestImagemagickversion = ($result.links.href | Where-Object { $_ -like '*portable-Q16-HDRI-x64.zip' } | Sort-Object -Descending)[0].Replace('-portable-Q16-HDRI-x64.zip','').Replace('ImageMagick-','')
2624+
}
2625+
Else {
2626+
$LatestImagemagickversion = (Invoke-RestMethod -Uri "https://api.github.com/repos/ImageMagick/ImageMagick/releases/latest" -Method Get).tag_name
2627+
}
2628+
Write-Entry -Message "Current Imagemagick Version: $($CurrentImagemagickversion.Groups[1].Value)" -Path $configLogging -Color Yellow -log Info
2629+
Write-Entry -Message "Latest Imagemagick Version: $LatestImagemagickversion" -Path $configLogging -Color DarkMagenta -log Info
2630+
2631+
# Auto Update Magick
2632+
if ($AutoUpdateIM -eq 'True' -and $global:OSType -ne "DockerAlpine" -and $LatestImagemagickversion -gt $CurrentImagemagickversion.Groups[1].Value){
2633+
if ($global:OSType -eq "Win32NT"){
2634+
Remove-Item -LiteralPath $magickinstalllocation -Recurse -Force
2635+
}
2636+
Else {
2637+
Remove-Item -LiteralPath "$global:ScriptRoot/magick" -Force
2638+
}
2639+
if ($global:OSType -ne "Win32NT") {
2640+
if ($global:OSType -ne "DockerAlpine") {
2641+
Write-Entry -Subtext "Downloading the latest Imagemagick portable version for you..." -Path $configLogging -Color Cyan -log Info
2642+
$magickUrl = "https://imagemagick.org/archive/binaries/magick"
2643+
Invoke-WebRequest -Uri $magickUrl -OutFile "$global:ScriptRoot/magick"
2644+
chmod +x "$global:ScriptRoot/magick"
2645+
Write-Entry -Subtext "Made the portable Magick executable..." -Path $configLogging -Color Green -log Info
2646+
}
2647+
}
2648+
else {
2649+
Write-Entry -Subtext "Downloading the latest Imagemagick portable version for you..." -Path $configLogging -Color Cyan -log Info
2650+
$result = Invoke-WebRequest "https://imagemagick.org/archive/binaries/?C=M;O=D"
2651+
$LatestRelease = ($result.links.href | Where-Object { $_ -like '*portable-Q16-HDRI-x64.zip' } | Sort-Object -Descending)[0]
2652+
$DownloadPath = Join-Path -Path $global:ScriptRoot -ChildPath (Join-Path -Path 'temp' -ChildPath $LatestRelease)
2653+
Invoke-WebRequest "https://imagemagick.org/archive/binaries/$LatestRelease" -OutFile $DownloadPath
2654+
Expand-Archive -Path $DownloadPath -DestinationPath $magickinstalllocation -Force
2655+
if ((Get-ChildItem -Directory -LiteralPath $magickinstalllocation).name -eq $($LatestRelease.replace('.zip', ''))) {
2656+
Copy-item -Force -Recurse "$magickinstalllocation\$((Get-ChildItem -Directory -LiteralPath $magickinstalllocation).name)\*" $magickinstalllocation
2657+
Remove-Item -Recurse -LiteralPath "$magickinstalllocation\$((Get-ChildItem -Directory -LiteralPath $magickinstalllocation).name)" -Force
2658+
}
2659+
if (Test-Path -LiteralPath $magickinstalllocation\magick.exe) {
2660+
Write-Entry -Subtext "Placed Portable ImageMagick here: $magickinstalllocation" -Path $configLogging -Color Green -log Info
2661+
}
2662+
Else {
2663+
Write-Entry -Subtext "Error During extraction, please manually install/copy portable Imagemagick from here: https://imagemagick.org/archive/binaries/$LatestRelease" -Path $configLogging -Color Red -log Error
2664+
}
2665+
}
2666+
}
2667+
}
26062668
}
26072669
function CheckOverlayDimensions {
26082670
param (
@@ -2853,6 +2915,7 @@ if (!$global:FavProvider) {
28532915
$LibstoExclude = $config.PlexPart.LibstoExclude
28542916
$PlexUrl = $config.PlexPart.PlexUrl
28552917
# Prerequisites Part
2918+
$AutoUpdateIM = $config.PrerequisitePart.AutoUpdateIM
28562919
$show_skipped = $config.PrerequisitePart.show_skipped
28572920
$AssetPath = RemoveTrailingSlash $config.PrerequisitePart.AssetPath
28582921

@@ -2994,12 +3057,7 @@ Else {
29943057
$fileExtensions = @(".otf", ".ttf", ".otc", ".ttc", ".png")
29953058
$errorCount = 0
29963059

2997-
$CurrentImagemagickversion = & $magick -version
2998-
$CurrentImagemagickversion = [regex]::Match($CurrentImagemagickversion, 'Version: ImageMagick (\d+(\.\d+){1,2}-\d+)')
2999-
$LatestImagemagickversion = (Invoke-RestMethod -Uri "https://api.github.com/repos/ImageMagick/ImageMagick/releases/latest" -Method Get).tag_name
30003060

3001-
Write-Entry -Message "Current Imagemagick Version: $($CurrentImagemagickversion.Groups[1].Value)" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Yellow -log Info
3002-
Write-Entry -Message "Latest Imagemagick Version: $LatestImagemagickversion" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color DarkMagenta -log Info
30033061

30043062
# Initialize Other Variables
30053063
$SeasonsTemp = $null
@@ -3020,6 +3078,9 @@ if ($Testing) {
30203078
$configLogging = Join-Path $LogsPath 'Testinglog.log'
30213079
}
30223080

3081+
# Check ImageMagick now:
3082+
CheckImageMagick -magick $magick -magickinstalllocation $magickinstalllocation
3083+
30233084
# Create directories if they don't exist
30243085
foreach ($path in $LogsPath, $TempPath, $TestPath, $AssetPath) {
30253086
if (!(Test-Path $path)) {
@@ -3104,9 +3165,6 @@ CheckJsonPaths -font $font -backgroundfont $backgroundfont -titlecardfont $title
31043165
# Check Plex now:
31053166
[xml]$Libs = CheckPlexAccess -PlexUrl $PlexUrl -PlexToken $PlexToken
31063167

3107-
# Check ImageMagick now:
3108-
CheckImageMagick -magick $magick -magickinstalllocation $magickinstalllocation
3109-
31103168
# Check overlay artwork for poster, background, and titlecard dimensions
31113169
Write-Entry -Message "Checking size of overlay files..." -Path $configLogging -Color White -log Info
31123170
CheckOverlayDimensions -Posteroverlay "$Posteroverlay" -Backgroundoverlay "$Backgroundoverlay" -Titlecardoverlay "$titlecardoverlay" -PosterSize "$PosterSize" -BackgroundSize "$BackgroundSize"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ Posterizarr is cross-platform ready, meaning it can run on Linux, [Docker (Alpin
153153
- `SkipTBA` : Set to `true` to skip TitleCard creation if the Titletext is `TBA`.
154154
- `SkipJapTitle` : Set to `true` to skip TitleCard creation if the Titletext is `Jap or Chinese`.
155155
- `AssetCleanup` : Set to `true` to cleanup Assets that are no longer in Plex.
156-
156+
- `AutoUpdateIM` : Set to `true` to AutoUpdate Imagemagick Portable Version (Does not work with Docker/Unraid).
157157

158158
```diff
159159
- !! IMPORTANT !! -

Release.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.27
1+
1.2.28

config.example.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
"TitleCards": "false",
3737
"SkipTBA": "false",
3838
"SkipJapTitle": "false",
39-
"AssetCleanup": "false"
39+
"AssetCleanup": "false",
40+
"AutoUpdateIM": "false"
4041
},
4142
"OverlayPart":{
4243
"ImageProcessing": "true",

0 commit comments

Comments
 (0)