|
| 1 | +Write-Progress -Status "Updating Javinizer" -Activity "Fetching Javinizer settings files..." -PercentComplete 25 |
| 2 | +$modulePath = (Get-InstalledModule Javinizer).InstalledLocation |
| 3 | +$origSettings = Get-Content -Path (Join-Path -Path $modulePath -ChildPath 'jvSettings.json') | ConvertFrom-Json -Depth 32 |
| 4 | + |
| 5 | +try { |
| 6 | + if (Test-Path -Path $origSettings.'location.thumbcsv') { |
| 7 | + $origThumbsPath = (Get-Item -Path $origSettings.'location.thumbcsv').FullName |
| 8 | + } else { |
| 9 | + $origThumbsPath = Join-Path -Path $modulePath -ChildPath 'jvThumbs.csv' |
| 10 | + } |
| 11 | + |
| 12 | + $origThumbs = Import-Csv -Path $origThumbsPath -Encoding utf8 -ErrorAction Continue |
| 13 | +} catch { |
| 14 | + Write-Error "Error occurred when retrieving thumb csv [$origThumbsPath]: $PSItem" -ErrorAction Stop |
| 15 | +} |
| 16 | + |
| 17 | +try { |
| 18 | + if (Test-Path -Path $origSettings.'location.genrecsv') { |
| 19 | + $origGenresPath = (Get-Item -Path $origSettings.'location.genrecsv').FullName |
| 20 | + } else { |
| 21 | + $origGenresPath = Join-Path -Path $modulePath -ChildPath 'jvGenres.csv' |
| 22 | + } |
| 23 | + |
| 24 | + $origGenres = Import-Csv -Path $origGenresPath -Encoding utf8 -ErrorAction Continue |
| 25 | +} catch { |
| 26 | + Write-Error "Error occurred when retrieving genre csv [$origGenresPath]: $PSItem" -ErrorAction Stop |
| 27 | +} |
| 28 | + |
| 29 | +try { |
| 30 | + if (Test-Path -Path $origSettings.'location.uncensorcsv') { |
| 31 | + $origUncensorPath = (Get-Item -Path $origSettings.'location.uncensorcsv').FullName |
| 32 | + } else { |
| 33 | + $origUncensorPath = Join-Path -Path $modulePath -ChildPath 'jvUncensor.csv' |
| 34 | + } |
| 35 | + |
| 36 | + $origUncensor = Import-Csv -Path $origUncensorPath -Encoding utf8 -ErrorAction Continue |
| 37 | +} catch { |
| 38 | + Write-Error "Error occurred when retrieving uncensor csv [$origUncensorPath]: $PSItem" -ErrorAction Stop |
| 39 | +} |
| 40 | + |
| 41 | +try { |
| 42 | + if (Test-Path -Path $origSettings.'location.historycsv') { |
| 43 | + $origHistoryPath = (Get-Item -Path $origSettings.'location.historycsv').FullName |
| 44 | + } else { |
| 45 | + $origHistoryPath = Join-Path -Path $modulePath -ChildPath 'jvHistory.csv' |
| 46 | + } |
| 47 | + |
| 48 | + $origHistory = Import-Csv -Path $origHistoryPath -Encoding utf8 -ErrorAction Continue |
| 49 | +} catch { |
| 50 | + Write-Error "Error occurred when retrieving history csv [$origHistoryPath]: $PSItem" -ErrorAction Stop |
| 51 | +} |
| 52 | + |
| 53 | +try { |
| 54 | + if (Test-Path -Path $origSettings.'location.tagcsv') { |
| 55 | + $origTagsPath = (Get-Item -Path $origSettings.'location.tagcsv').FullName |
| 56 | + } else { |
| 57 | + $origTagsPath = Join-Path -Path $modulePath -ChildPath 'jvTags.csv' |
| 58 | + } |
| 59 | + |
| 60 | + $origTags = Import-Csv -Path $origTagsPath -Encoding utf8 -ErrorAction Continue |
| 61 | +} catch { |
| 62 | + Write-Error "Error occurred when retrieving tag csv [$origTagsPath]: $PSItem" -ErrorAction Stop |
| 63 | +} |
| 64 | + |
| 65 | +try { |
| 66 | + Write-Progress -Status "Updating Javinizer" -Activity "Updating Javinizer module via PowerShell Gallery..." -PercentComplete 50 |
| 67 | + Update-Module -Name 'Javinizer' -Force -Confirm:$false |
| 68 | +} catch { |
| 69 | + Write-Error "Error occurred when updating the Javinizer module: $PSItem" -ErrorAction Stop |
| 70 | +} |
| 71 | + |
| 72 | +$newModulePath = (Get-InstalledModule -Name 'Javinizer').InstalledLocation |
| 73 | + |
| 74 | +# Update jvSettings |
| 75 | +$supportedScrapers = Get-Help Get-JVData -Parameter * | Select-Object -ExpandProperty aliases | Where-Object { $_.StartsWith("scraper.movie") } | ForEach-Object { $_.Replace("scraper.movie.", "") } |
| 76 | +$newSettingsPath = Join-Path -Path $newModulePath -ChildPath 'jvSettings.json' |
| 77 | +$newSettings = Get-JVSettings -Path $newSettingsPath |
| 78 | +$newSettings.PSObject.Properties | ForEach-Object { |
| 79 | + $property = $_ |
| 80 | + if ($origSettings.PSObject.Properties.Name -contains $_.Name) { |
| 81 | + $newSettings."$($_.Name)" = ($origSettings.PSObject.Properties | Where-Object { $_.Name -eq $property.Name })[0].Value |
| 82 | + if ($_.Name.StartsWith("sort.metadata.priority")) { |
| 83 | + $elementIndex = $_.Value.IndexOf(($_.Value | Where-Object { $_ -eq "r18" })) |
| 84 | + if ($elementIndex -ge 0) { |
| 85 | + $_.Value[$elementIndex] = "r18dev" |
| 86 | + } |
| 87 | + $newSettings."$($_.Name)" = $_.Value | Where-Object { $_ -in $supportedScrapers } |
| 88 | + } |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +try { |
| 93 | + Write-Progress -Status "Updating Javinizer" -Activity "Migrating settings to $newSettingsPath..." -PercentComplete 65 |
| 94 | + $newSettings | ConvertTo-Json -Depth 32 | Out-File -FilePath $newSettingsPath -Force -ErrorAction Continue |
| 95 | +} catch { |
| 96 | + Write-Error "Error occurred when updating the existing settings file at path [$newSettingsPath]: $PSItem" -ErrorAction Continue |
| 97 | + $tempFile = New-TemporaryFile |
| 98 | + $newSettings | ConvertTo-Json -Depth 32 | Out-File -FilePath $tempFile |
| 99 | + Write-Warning "Writing updated settings file to temp location: $(Join-Path -Path $env:TEMP -ChildPath $tempFile)" |
| 100 | +} |
| 101 | + |
| 102 | +# Update jvThumbs |
| 103 | +try { |
| 104 | + $newThumbsPath = Join-Path -Path $newModulePath -ChildPath 'jvThumbs.csv' |
| 105 | + Write-Progress -Status "Updating Javinizer" -Activity "Migrating thumbs to $newThumbsPath..." -PercentComplete 70 |
| 106 | + Write-Host "Migrating $origThumbsPath => $newThumbsPath" |
| 107 | + Copy-Item -Path $origThumbsPath -Destination $newThumbsPath -Force |
| 108 | + <# $newThumbs = Import-Csv -Path $newThumbsPath -Encoding utf8 |
| 109 | + if ($null -ne $origThumbs) { |
| 110 | + $thumbsDifference = (Compare-Object -ReferenceObject $origThumbs -DifferenceObject $newThumbs -ErrorAction SilentlyContinue).InputObject |
| 111 | + if ($thumbsDifference) { |
| 112 | + $thumbsDifference | Export-Csv -Path $newThumbsPath -Append -Encoding utf8 -ErrorAction SilentlyContinue |
| 113 | + Write-Host "Migrating $origThumbsPath => $newThumbsPath" |
| 114 | + } else { |
| 115 | + Write-Host "Migrating $origThumbsPath => $newThumbsPath (no changes)" |
| 116 | + } |
| 117 | + } #> |
| 118 | +} catch { |
| 119 | + Write-Warning "Error [$origThumbsPath]: $PSItem" |
| 120 | +} |
| 121 | + |
| 122 | +# Update jvGenres |
| 123 | +try { |
| 124 | + $newGenresPath = Join-Path -Path $newModulePath -ChildPath 'jvGenres.csv' |
| 125 | + Write-Progress -Status "Updating Javinizer" -Activity "Migrating genres to $newGenresPath..." -PercentComplete 75 |
| 126 | + Write-Host "Migrating $origGenresPath => $newGenresPath" |
| 127 | + Copy-Item -Path $origGenresPath -Destination $newGenresPath -Force |
| 128 | + <# $newGenres = Import-Csv -Path $newGenresPath -Encoding utf8 |
| 129 | + if ($null -ne $origGenres) { |
| 130 | + $genresDifference = (Compare-Object -ReferenceObject $origGenres -DifferenceObject $newGenres -ErrorAction SilentlyContinue).InputObject |
| 131 | + if ($genresDifference) { |
| 132 | + $genresDifference | Export-Csv -Path $newGenresPath -Append -Encoding utf8 -ErrorAction SilentlyContinue |
| 133 | + } else { |
| 134 | + Write-Host "Migrating $origGenresPath => $newGenresPath (no changes)" |
| 135 | + } |
| 136 | + } #> |
| 137 | +} catch { |
| 138 | + Write-Warning "Error [$origGenresPath]: $PSItem" |
| 139 | +} |
| 140 | + |
| 141 | +# Update jvUncensor |
| 142 | +try { |
| 143 | + $newUncensorPath = Join-Path -Path $newModulePath -ChildPath 'jvUncensor.csv' |
| 144 | + Write-Progress -Status "Updating Javinizer" -Activity "Migrating uncensors to $newUncensorPath..." -PercentComplete 80 |
| 145 | + $newUncensor = Import-Csv -Path $newUncensorPath -Encoding utf8 |
| 146 | + if ($null -ne $origUncensor) { |
| 147 | + $uncensorDifference = (Compare-Object -ReferenceObject $origUncensor -DifferenceObject $newUncensor -ErrorAction SilentlyContinue).InputObject |
| 148 | + if ($uncensorDifference) { |
| 149 | + $uncensorDifference | Export-Csv -Path $newUncensorPath -Append -Encoding utf8 -ErrorAction SilentlyContinue |
| 150 | + Write-Host "Migrating $origUncensorPath => $newUncensorPath" |
| 151 | + } else { |
| 152 | + Write-Host "Migrating $origUncensorPath => $newUncensorPath (no changes)" |
| 153 | + } |
| 154 | + } |
| 155 | +} catch { |
| 156 | + Write-Warning "Error [$origUncensorPath]: $PSItem" |
| 157 | +} |
| 158 | + |
| 159 | +# Update jvHistory |
| 160 | +try { |
| 161 | + $newHistoryPath = Join-Path -Path $newModulePath -ChildPath 'jvHistory.csv' |
| 162 | + Write-Progress -Status "Updating Javinizer" -Activity "Migrating history to $newHistoryPath..." -PercentComplete 85 |
| 163 | + Write-Host "Migrating $origHistoryPath => $newHistoryPath" |
| 164 | + Copy-Item -Path $origHistoryPath -Destination $newHistoryPath -Force |
| 165 | + <# $newHistory = Import-Csv -Path $newHistoryPath -Encoding utf8 |
| 166 | + if ($null -ne $origHistory) { |
| 167 | + $historyDifference = (Compare-Object -ReferenceObject $origHistory -DifferenceObject $newHistory -ErrorAction SilentlyContinue).InputObject |
| 168 | + if ($historyDifference) { |
| 169 | + $historyDifference | Export-Csv -Path $newHistoryPath -Append -Encoding utf8 -ErrorAction SilentlyContinue |
| 170 | + } else { |
| 171 | + Write-Host "Migrating $origHistoryPath => $newHistoryPath (no changes)" |
| 172 | + } |
| 173 | + } #> |
| 174 | +} catch { |
| 175 | + Write-Warning "Error [$origHistoryPath]: $PSItem" |
| 176 | +} |
| 177 | + |
| 178 | +# Update jvTags |
| 179 | +try { |
| 180 | + $newTagsPath = Join-Path -Path $newModulePath -ChildPath 'jvTags.csv' |
| 181 | + Write-Progress -Status "Updating Javinizer" -Activity "Migrating tags to $newTagsPath..." -PercentComplete 90 |
| 182 | + Write-Host "Migrating $origTagsPath => $newTagsPath" |
| 183 | + Copy-Item -Path $origTagsPath -Destination $newTagsPath -Force |
| 184 | + <# $newTags = Import-Csv -Path $newTagsPath -Encoding utf8 |
| 185 | + if ($null -ne $origTags) { |
| 186 | + $tagsDifference = (Compare-Object -ReferenceObject $origTags -DifferenceObject $newTags -ErrorAction SilentlyContinue).InputObject |
| 187 | + if ($tagsDifference) { |
| 188 | + $tagsDifference | Export-Csv -Path $newTagsPath -Append -Encoding utf8 -ErrorAction SilentlyContinue |
| 189 | + } else { |
| 190 | + Write-Host "Migrating $origTagsPath => $newTagsPath (no changes)" |
| 191 | + } |
| 192 | + } #> |
| 193 | +} catch { |
| 194 | + Write-Warning "Error [$origTagsPath]: $PSItem" |
| 195 | +} |
| 196 | + |
| 197 | +Write-Host "Javinizer update completed! Restart your shell to continue." -ForegroundColor Green |
0 commit comments