Skip to content

Commit

Permalink
feat: Add Arm support & tvdb search fixes
Browse files Browse the repository at this point in the history
- Code changes
- Add walkthrough
- fix tvdb search when more then 500 items are returned
  • Loading branch information
fscorrupt committed Jul 11, 2024
1 parent 5bc422f commit ab35be9
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 32 deletions.
94 changes: 64 additions & 30 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.35"
$CurrentScriptVersion = "1.2.36"
$global:HeaderWritten = $false
$ProgressPreference = 'SilentlyContinue'

Expand Down Expand Up @@ -1947,7 +1947,7 @@ function GetTVDBSeasonPoster {
continue
}
}
if (!$global:posterurl){
if (!$global:posterurl) {
Write-Entry -Subtext "No Poster found on TVDB" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Yellow -log Warning
}
}
Expand Down Expand Up @@ -2072,37 +2072,53 @@ function GetTVDBShowBackground {
function GetTVDBTitleCard {
if ($global:tvdbid) {
Write-Entry -Subtext "Searching on TVDB for: $global:show_name 'Season $global:season_number - Episode $global:episodenumber' Title Card" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Cyan -log Info
try {
$response = (Invoke-WebRequest -Uri "https://api4.thetvdb.com/v4/series/$($global:tvdbid)/episodes/default?" -Method GET -Headers $global:tvdbheader).content | ConvertFrom-Json
}
catch {
Write-Entry -Subtext "Could not query TVDB url, error message: $($_.Exception.Message)" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Red -log Error
Write-Entry -Subtext "[ERROR-HERE] See above. ^^^" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Red -log Error
$errorCount++
}
$allEpisodes = @()
$page = 0

do {
try {
$response = (Invoke-WebRequest -Uri "https://api4.thetvdb.com/v4/series/81797/episodes/default?page=$page" -Method GET -Headers $global:tvdbheader).content | ConvertFrom-Json
$episodes = $response.data.episodes
$seriesData = $response.data

if ($episodes) {
$allEpisodes += $seriesData
$page++
}
}
catch {
Write-Entry -Subtext "Could not query TVDB url, error message: $($_.Exception.Message)" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Red -log Error
Write-Entry -Subtext "[ERROR-HERE] See above. ^^^" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Red -log Error
$errorCount++
break
}
} while ($episodes -and $episodes.Count -gt 0)

# Now $allEpisodes contains all the episodes retrieved from the API

if ($response) {
if ($response.data.episodes) {
$global:NoLangImageUrl = $response.data.episodes | Where-Object { $_.seasonNumber -eq $global:season_number -and $_.number -eq $global:episodenumber }
if ($allEpisodes.episodes) {
$global:NoLangImageUrl = $allEpisodes.episodes | Where-Object { $_.seasonNumber -eq $global:season_number -and $_.number -eq $global:episodenumber }
if ($global:NoLangImageUrl.image) {
$global:posterurl = $global:NoLangImageUrl.image
Write-Entry -Subtext "Found Title Card on TVDB" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Blue -log Info
$global:TextlessPoster = $true
$global:PosterWithText = $null
$global:TVDBAssetChangeUrl = "https://thetvdb.com/series/$($response.data.series.slug)/episodes/$($global:NoLangImageUrl.id)"
$global:TVDBAssetChangeUrl = "https://thetvdb.com/series/$($allEpisodes.series.slug)/episodes/$($global:NoLangImageUrl.id)"

return $global:NoLangImageUrl.image
}
Else {
Write-Entry -Subtext "No Title Card found on TVDB" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Yellow -log Warning
Write-Entry -Subtext "[ERROR-HERE] See above. ^^^" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Red -log Error
$global:TVDBAssetChangeUrl = "https://thetvdb.com/series/$($response.data.slug)/#artwork"
$global:TVDBAssetChangeUrl = "https://thetvdb.com/series/$($allEpisodes.slug)/#artwork"
$errorCount++
}
}
Else {
Write-Entry -Subtext "No Title Card found on TVDB" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Yellow -log Warning
Write-Entry -Subtext "[ERROR-HERE] See above. ^^^" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Red -log Error
$global:TVDBAssetChangeUrl = "https://thetvdb.com/series/$($response.data.slug)/#artwork"
$global:TVDBAssetChangeUrl = "https://thetvdb.com/series/$($allEpisodes.slug)/#artwork"
$errorCount++
}
}
Expand Down Expand Up @@ -2713,17 +2729,20 @@ function InvokeMagickCommand {
Write-Entry -Subtext "[ERROR-HERE] See above. ^^^" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Red -log Error
$errorCount++
}
} catch {
}
catch {
Write-Entry -Subtext "Failed to start the process or read the error output:" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Red -log Error
Write-Entry -Subtext $_.Exception.Message -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Red -log Error
Write-Entry -Subtext "[ERROR-HERE] See above. ^^^" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Red -log Error
$errorCount++
} finally {
}
finally {
if ($process) {
$process.Dispose()
}
}
} catch {
}
catch {
Write-Entry -Subtext "An unexpected error occurred while setting up the process:" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Red -log Error
Write-Entry -Subtext $_.Exception.Message -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Red -log Error
Write-Entry -Subtext "[ERROR-HERE] See above. ^^^" -Path $global:ScriptRoot\Logs\Scriptlog.log -Color Red -log Error
Expand Down Expand Up @@ -3032,8 +3051,9 @@ $fontImagemagick = $font.replace('\', '\\')
$backgroundfontImagemagick = $backgroundfont.replace('\', '\\')
$TitleCardfontImagemagick = $TitleCardfont.replace('\', '\\')
if ($global:OSType -ne "Win32NT") {
if ($global:OSType -eq "DockerAlpine") {
$magick = 'magick'
$global:OSarch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture
if ($global:OSType -eq "DockerAlpine" -or $global:OSarch -eq "Arm64") {
$magick = 'magick'
}
Else {
$magickinstalllocation = $global:ScriptRoot
Expand Down Expand Up @@ -3068,13 +3088,27 @@ if ($Testing) {
$configLogging = Join-Path $LogsPath 'Testinglog.log'
}

# Check ImageMagick now:
CheckImageMagick -magick $magick -magickinstalllocation $magickinstalllocation
if ($global:OSarch -eq "Arm64") {
try {
$CurrentImagemagickversion = & $magick -version
}
catch {
Write-Entry -Message "Could not query installed Imagemagick" -Path $configLogging -Color Red -log Error
Exit
}
$CurrentImagemagickversion = [regex]::Match($CurrentImagemagickversion, 'Version: ImageMagick (\d+(\.\d+){1,2}-\d+)')
$CurrentImagemagickversion = $CurrentImagemagickversion.Groups[1].Value.replace('-', '.')
Write-Entry -Message "Current Imagemagick Version: $CurrentImagemagickversion" -Path $configLogging -Color White -log Info
}
Else {
# Check ImageMagick now:
CheckImageMagick -magick $magick -magickinstalllocation $magickinstalllocation

$CurrentImagemagickversion = & $magick -version
$CurrentImagemagickversion = [regex]::Match($CurrentImagemagickversion, 'Version: ImageMagick (\d+(\.\d+){1,2}-\d+)')
$CurrentImagemagickversion = $CurrentImagemagickversion.Groups[1].Value.replace('-', '.')
Write-Entry -Message "Current Imagemagick Version: $CurrentImagemagickversion" -Path $configLogging -Color White -log Info
$CurrentImagemagickversion = & $magick -version
$CurrentImagemagickversion = [regex]::Match($CurrentImagemagickversion, 'Version: ImageMagick (\d+(\.\d+){1,2}-\d+)')
$CurrentImagemagickversion = $CurrentImagemagickversion.Groups[1].Value.replace('-', '.')
Write-Entry -Message "Current Imagemagick Version: $CurrentImagemagickversion" -Path $configLogging -Color White -log Info
}
if ($global:OSType -eq "DockerAlpine") {
$Url = "https://pkgs.alpinelinux.org/package/edge/community/x86_64/imagemagick"
$response = Invoke-WebRequest -Uri $url
Expand All @@ -3094,10 +3128,10 @@ Elseif ($global:OSType -eq "Win32NT") {
Else {
$LatestImagemagickversion = (Invoke-RestMethod -Uri "https://api.github.com/repos/ImageMagick/ImageMagick/releases/latest" -Method Get).tag_name
}
$LatestImagemagickversion = $LatestImagemagickversion.replace('-','.')
$LatestImagemagickversion = $LatestImagemagickversion.replace('-', '.')
Write-Entry -Message "Latest Imagemagick Version: $LatestImagemagickversion" -Path $configLogging -Color Yellow -log Info
# Auto Update Magick
if ($AutoUpdateIM -eq 'True' -and $global:OSType -ne "DockerAlpine" -and $LatestImagemagickversion -gt $CurrentImagemagickversion) {
if ($AutoUpdateIM -eq 'True' -and $global:OSType -ne "DockerAlpine" -and $LatestImagemagickversion -gt $CurrentImagemagickversion -and $global:OSarch -ne "Arm64") {
if ($global:OSType -eq "Win32NT") {
Remove-Item -LiteralPath $magickinstalllocation -Recurse -Force
}
Expand Down Expand Up @@ -7795,7 +7829,7 @@ else {
$tvdbpattern = 'tvdb://(\d+)'
if ($Metadata.MediaContainer.$contentquery.Location) {
$location = $Metadata.MediaContainer.$contentquery.Location.path
if ($location){
if ($location) {
$location = $location.replace('\\?\', '')
}
if ($location.count -gt '1') {
Expand Down Expand Up @@ -7829,7 +7863,7 @@ else {
}
Else {
$location = $Metadata.MediaContainer.$contentquery.media.part.file
if ($location){
if ($location) {
$location = $location.replace('\\?\', '')
}
if ($location.count -gt '1') {
Expand Down
2 changes: 1 addition & 1 deletion Release.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.35
1.2.36
56 changes: 55 additions & 1 deletion walkthrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
- **Plex Token:** [Optain Plex Token](https://support.plex.tv/articles/204059436-finding-an-authentication-token-x-plex-token/)

1. For Docker please continue here: [Docker](#docker)

1. For Linux/ARM please Start here: [ARM](#ARM)
1. Please install Powershell
- [Linux](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-linux?view=powershell-7.4)
- [macOS](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-macos?view=powershell-7.4)
Expand Down Expand Up @@ -249,5 +249,59 @@ docker exec -it posterizarr pwsh Posterizarr.ps1 -Testing
```sh
docker exec -it posterizarr pwsh Posterizarr.ps1
```

## ARM Prerequisites
1. Install Powershell (make an sh file and run it) - [Official Link](https://learn.microsoft.com/en-us/powershell/scripting/install/community-support?view=powershell-7.4#raspberry-pi-os):
```sh
# Prerequisites
# Update package lists
sudo apt-get update
# Install dependencies
sudo apt-get install jq libssl1.1 libunwind8 -y
# Download and extract PowerShell
# Grab the latest tar.gz
bits=$(getconf LONG_BIT)
release=$(curl -sL https://api.github.com/repos/PowerShell/PowerShell/releases/latest)
package=$(echo $release | jq -r ".assets[].browser_download_url" | grep "linux-arm${bits}.tar.gz")
wget $package
# Make folder to put powershell
mkdir ~/powershell
# Unpack the tar.gz file
tar -xvf "./${package##*/}" -C ~/powershell
# Make Powershell executable PowerShell
sudo chmod +x ~/powershell/pwsh
# Create Symlink
sudo ~/powershell/pwsh -command 'New-Item -ItemType SymbolicLink -Path "/usr/bin/pwsh" -Target "$PSHOME/pwsh" -Force'
```
1. Install ImageMagick 7:
```sh
# Prerequisites
sudo apt update
sudo apt install build-essential
apt install libjpeg-dev
apt install libpng-dev
apt install libfreetype-dev
# Download/extract
wget https://imagemagick.org/archive/ImageMagick.tar.gz
tar xvzf ImageMagick.tar.gz
cd ImageMagick-7.1.1-34 # Version can differ
# Compilation and Installation
./configure
make
sudo make install
sudo ldconfig /usr/local/lib
# Check if it is working
magick -version
```
1. Now you can Contuine on Step 5 here: [Docker](#Getting-Started)
> [!NOTE]
> Have a look at the [Assets Tip](https://github.com/fscorrupt/Posterizarr?tab=readme-ov-file#assets-tip)

0 comments on commit ab35be9

Please sign in to comment.