Skip to content

Commit 27def16

Browse files
committed
error logging adjusted
add try-catch logging
1 parent 3690a43 commit 27def16

File tree

2 files changed

+88
-17
lines changed

2 files changed

+88
-17
lines changed

PlexPosterMaker.ps1

+87-16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ param (
33
[switch]$Testing
44
)
55

6-
$CurrentScriptVersion = "1.0.20"
6+
$CurrentScriptVersion = "1.0.21"
77
$global:HeaderWritten = $false
88

99
$global:OSType = [System.Environment]::OSVersion.Platform
@@ -146,6 +146,7 @@ function GetTMDBMoviePoster {
146146
}
147147
catch {
148148
Write-Log -Subtext "Could not query TMDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
149+
$errorCount++
149150
}
150151
if ($response) {
151152
if ($response.images.posters) {
@@ -181,6 +182,7 @@ function GetTMDBMoviePoster {
181182
}
182183
catch {
183184
Write-Log -Subtext "Could not query TMDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
185+
$errorCount++
184186
}
185187
if ($response) {
186188
if ($response.images.posters) {
@@ -222,6 +224,7 @@ function GetTMDBMovieBackground {
222224
}
223225
catch {
224226
Write-Log -Subtext "Could not query TMDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
227+
$errorCount++
225228
}
226229
if ($response) {
227230
if ($response.images.backdrops) {
@@ -263,6 +266,7 @@ function GetTMDBMovieBackground {
263266
}
264267
catch {
265268
Write-Log -Subtext "Could not query TMDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
269+
$errorCount++
266270
}
267271
if ($response) {
268272
if ($response.images.backdrops) {
@@ -314,6 +318,7 @@ function GetTMDBShowPoster {
314318
}
315319
catch {
316320
Write-Log -Subtext "Could not query TMDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
321+
$errorCount++
317322
}
318323
if ($response) {
319324
if ($response.images.posters) {
@@ -350,6 +355,7 @@ function GetTMDBShowPoster {
350355
}
351356
catch {
352357
Write-Log -Subtext "Could not query TMDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
358+
$errorCount++
353359
}
354360
if ($response) {
355361
if ($response.images.posters) {
@@ -391,6 +397,7 @@ function GetTMDBSeasonPoster {
391397
}
392398
catch {
393399
Write-Log -Subtext "Could not query TMDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
400+
$errorCount++
394401
}
395402
if ($response) {
396403
if ($response.posters) {
@@ -432,6 +439,7 @@ function GetTMDBSeasonPoster {
432439
}
433440
catch {
434441
Write-Log -Subtext "Could not query TMDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
442+
$errorCount++
435443
}
436444
if ($responseBackup) {
437445
if ($responseBackup.images.posters) {
@@ -505,6 +513,7 @@ function GetTMDBShowBackground {
505513
}
506514
catch {
507515
Write-Log -Subtext "Could not query TMDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
516+
$errorCount++
508517
}
509518
if ($response) {
510519
if ($response.images.backdrops) {
@@ -550,6 +559,7 @@ function GetTMDBShowBackground {
550559
}
551560
catch {
552561
Write-Log -Subtext "Could not query TMDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
562+
$errorCount++
553563
}
554564
if ($response) {
555565
if ($response.images.backdrops) {
@@ -600,6 +610,7 @@ function GetTMDBTitleCard {
600610
}
601611
catch {
602612
Write-Log -Subtext "Could not query TMDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
613+
$errorCount++
603614
}
604615
if ($response) {
605616
if ($response.stills) {
@@ -977,6 +988,7 @@ function GetTVDBMoviePoster {
977988
}
978989
catch {
979990
Write-Log -Subtext "Could not query TVDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
991+
$errorCount++
980992
}
981993
if ($response) {
982994
if ($response.data.artworks) {
@@ -999,6 +1011,7 @@ function GetTVDBMoviePoster {
9991011
}
10001012
catch {
10011013
Write-Log -Subtext "Could not query TVDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
1014+
$errorCount++
10021015
}
10031016
if ($response) {
10041017
if ($response.data.artworks) {
@@ -1044,6 +1057,7 @@ function GetTVDBMovieBackground {
10441057
}
10451058
catch {
10461059
Write-Log -Subtext "Could not query TVDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
1060+
$errorCount++
10471061
}
10481062
if ($response) {
10491063
if ($response.data.artworks) {
@@ -1066,6 +1080,7 @@ function GetTVDBMovieBackground {
10661080
}
10671081
catch {
10681082
Write-Log -Subtext "Could not query TVDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
1083+
$errorCount++
10691084
}
10701085
if ($response) {
10711086
if ($response.data.artworks) {
@@ -1114,6 +1129,7 @@ function GetTVDBShowPoster {
11141129
}
11151130
catch {
11161131
Write-Log -Subtext "Could not query TVDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
1132+
$errorCount++
11171133
}
11181134
if ($response) {
11191135
if ($response.data) {
@@ -1144,6 +1160,7 @@ function GetTVDBShowPoster {
11441160
}
11451161
catch {
11461162
Write-Log -Subtext "Could not query TVDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
1163+
$errorCount++
11471164
}
11481165
if ($response) {
11491166
if ($response.data) {
@@ -1188,6 +1205,7 @@ function GetTVDBSeasonPoster {
11881205
}
11891206
catch {
11901207
Write-Log -Subtext "Could not query TVDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
1208+
$errorCount++
11911209
}
11921210
if ($response) {
11931211
if ($response.data.seasons) {
@@ -1201,6 +1219,7 @@ function GetTVDBSeasonPoster {
12011219
}
12021220
catch {
12031221
Write-Log -Subtext "Could not query TVDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
1222+
$errorCount++
12041223
}
12051224
if ($Seasonresponse) {
12061225
foreach ($lang in $global:PreferredLanguageOrderTVDB) {
@@ -1247,6 +1266,7 @@ function GetTVDBShowBackground {
12471266
}
12481267
catch {
12491268
Write-Log -Subtext "Could not query TVDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
1269+
$errorCount++
12501270
}
12511271
if ($response) {
12521272
if ($response.data) {
@@ -1277,6 +1297,7 @@ function GetTVDBShowBackground {
12771297
}
12781298
catch {
12791299
Write-Log -Subtext "Could not query TVDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
1300+
$errorCount++
12801301
}
12811302
if ($response) {
12821303
if ($response.data) {
@@ -1324,6 +1345,7 @@ function GetTVDBTitleCard {
13241345
}
13251346
catch {
13261347
Write-Log -Subtext "Could not query TVDB url, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
1348+
$errorCount++
13271349
}
13281350
if ($response) {
13291351
if ($response.data.episodes) {
@@ -3275,8 +3297,15 @@ else {
32753297
$joinedTitle = $Titletext
32763298
}
32773299
if ($global:posterurl -or $global:PlexartworkDownloaded ) {
3278-
if (!$global:PlexartworkDownloaded) {
3279-
Invoke-WebRequest -Uri $global:posterurl -OutFile $PosterImage
3300+
try {
3301+
if (!$global:PlexartworkDownloaded) {
3302+
$response = Invoke-WebRequest -Uri $global:posterurl -OutFile $PosterImage -ErrorAction Stop
3303+
}
3304+
}
3305+
catch {
3306+
$statusCode = $_.Exception.Response.StatusCode.value__
3307+
Write-Log -Subtext "An error occurred while downloading the artwork: HTTP Error $statusCode" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
3308+
$errorCount++
32803309
}
32813310
Write-Log -Subtext "Poster url: $global:posterurl" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Info
32823311
if ($global:posterurl -like 'https://image.tmdb.org*') {
@@ -3452,8 +3481,15 @@ else {
34523481
$joinedTitle = $Titletext
34533482
}
34543483
if ($global:posterurl -or $global:PlexartworkDownloaded ) {
3455-
if (!$global:PlexartworkDownloaded) {
3456-
Invoke-WebRequest -Uri $global:posterurl -OutFile $backgroundImage
3484+
try {
3485+
if (!$global:PlexartworkDownloaded) {
3486+
$response = Invoke-WebRequest -Uri $global:posterurl -OutFile $BackgroundImage -ErrorAction Stop
3487+
}
3488+
}
3489+
catch {
3490+
$statusCode = $_.Exception.Response.StatusCode.value__
3491+
Write-Log -Subtext "An error occurred while downloading the artwork: HTTP Error $statusCode" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
3492+
$errorCount++
34573493
}
34583494
Write-Log -Subtext "Poster url: $global:posterurl" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Info
34593495
if ($global:posterurl -like 'https://image.tmdb.org*') {
@@ -3563,6 +3599,7 @@ else {
35633599
}
35643600
catch {
35653601
Write-Log -Subtext "Could not query entries from movies array, error message: $_" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
3602+
$errorCount++
35663603
}
35673604
}
35683605

@@ -3678,8 +3715,15 @@ else {
36783715
$global:posterurl = $global:fanartfallbackposterurl
36793716
}
36803717
if ($global:posterurl -or $global:PlexartworkDownloaded ) {
3681-
if (!$global:PlexartworkDownloaded) {
3682-
Invoke-WebRequest -Uri $global:posterurl -OutFile $PosterImage
3718+
try {
3719+
if (!$global:PlexartworkDownloaded) {
3720+
$response = Invoke-WebRequest -Uri $global:posterurl -OutFile $PosterImage -ErrorAction Stop
3721+
}
3722+
}
3723+
catch {
3724+
$statusCode = $_.Exception.Response.StatusCode.value__
3725+
Write-Log -Subtext "An error occurred while downloading the artwork: HTTP Error $statusCode" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
3726+
$errorCount++
36833727
}
36843728
Write-Log -Subtext "Poster url: $global:posterurl" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Info
36853729
if ($global:posterurl -like 'https://image.tmdb.org*') {
@@ -3861,8 +3905,15 @@ else {
38613905
$joinedTitle = $Titletext
38623906
}
38633907
if ($global:posterurl -or $global:PlexartworkDownloaded ) {
3864-
if (!$global:PlexartworkDownloaded) {
3865-
Invoke-WebRequest -Uri $global:posterurl -OutFile $backgroundImage
3908+
try {
3909+
if (!$global:PlexartworkDownloaded) {
3910+
$response = Invoke-WebRequest -Uri $global:posterurl -OutFile $BackgroundImage -ErrorAction Stop
3911+
}
3912+
}
3913+
catch {
3914+
$statusCode = $_.Exception.Response.StatusCode.value__
3915+
Write-Log -Subtext "An error occurred while downloading the artwork: HTTP Error $statusCode" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
3916+
$errorCount++
38663917
}
38673918
Write-Log -Subtext "Poster url: $global:posterurl" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Info
38683919
if ($global:posterurl -like 'https://image.tmdb.org*') {
@@ -4047,8 +4098,15 @@ else {
40474098
}
40484099
if ($global:posterurl -or $global:PlexartworkDownloaded ) {
40494100
if ($global:ImageProcessing -eq 'true') {
4050-
if (!$global:PlexartworkDownloaded) {
4051-
Invoke-WebRequest -Uri $global:posterurl -OutFile $SeasonImage
4101+
try {
4102+
if (!$global:PlexartworkDownloaded) {
4103+
$response = Invoke-WebRequest -Uri $global:posterurl -OutFile $SeasonImage -ErrorAction Stop
4104+
}
4105+
}
4106+
catch {
4107+
$statusCode = $_.Exception.Response.StatusCode.value__
4108+
Write-Log -Subtext "An error occurred while downloading the artwork: HTTP Error $statusCode" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
4109+
$errorCount++
40524110
}
40534111
Write-Log -Subtext "Poster url: $global:posterurl" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Info
40544112
if ($global:posterurl -like 'https://image.tmdb.org*') {
@@ -4125,8 +4183,15 @@ else {
41254183
}
41264184
}
41274185
Else {
4128-
if (!$global:PlexartworkDownloaded) {
4129-
Invoke-WebRequest -Uri $global:posterurl -OutFile $SeasonImage
4186+
try {
4187+
if (!$global:PlexartworkDownloaded) {
4188+
$response = Invoke-WebRequest -Uri $global:posterurl -OutFile $SeasonImage -ErrorAction Stop
4189+
}
4190+
}
4191+
catch {
4192+
$statusCode = $_.Exception.Response.StatusCode.value__
4193+
Write-Log -Subtext "An error occurred while downloading the artwork: HTTP Error $statusCode" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
4194+
$errorCount++
41304195
}
41314196
Write-Log -Subtext "Poster url: $global:posterurl" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Info
41324197
if ($global:posterurl -like 'https://image.tmdb.org*') {
@@ -4356,8 +4421,15 @@ else {
43564421
}
43574422
if ($global:posterurl -or $global:PlexartworkDownloaded ) {
43584423
if ($global:ImageProcessing -eq 'true') {
4359-
if (!$global:PlexartworkDownloaded) {
4360-
Invoke-WebRequest -Uri $global:posterurl -OutFile $EpisodeImage
4424+
try {
4425+
if (!$global:PlexartworkDownloaded) {
4426+
$response = Invoke-WebRequest -Uri $global:posterurl -OutFile $EpisodeImage -ErrorAction Stop
4427+
}
4428+
}
4429+
catch {
4430+
$statusCode = $_.Exception.Response.StatusCode.value__
4431+
Write-Log -Subtext "An error occurred while downloading the artwork: HTTP Error $statusCode" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
4432+
$errorCount++
43614433
}
43624434
Write-Log -Subtext "Title Card url: $global:posterurl" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Info
43634435
if ($global:posterurl -like 'https://image.tmdb.org*') {
@@ -4445,7 +4517,6 @@ else {
44454517
}
44464518
}
44474519
catch {
4448-
# Not sure how fancy we get here to fall back to another provider, or just log the error and move on
44494520
$statusCode = $_.Exception.Response.StatusCode.value__
44504521
Write-Log -Subtext "An error occurred while downloading the artwork: HTTP Error $statusCode" -Path $global:ScriptRoot\Logs\Scriptlog.log -Type Error
44514522
$errorCount++

Release.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.20
1+
1.0.21

0 commit comments

Comments
 (0)