Skip to content

Commit

Permalink
Fixed several issues and moved update script to repository
Browse files Browse the repository at this point in the history
  • Loading branch information
seeyabye committed May 5, 2023
1 parent 4cac59e commit eabd618
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Javinizer/Javinizer.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# Version number of this module.

ModuleVersion = '2.5.11'
ModuleVersion = '2.5.12'

# Supported PSEditions
# CompatiblePSEditions = @('Core')
Expand Down
197 changes: 197 additions & 0 deletions src/Javinizer/Misc/Invoke-Update.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
Write-Progress -Status "Updating Javinizer" -Activity "Fetching Javinizer settings files..." -PercentComplete 25
$modulePath = (Get-InstalledModule Javinizer).InstalledLocation
$origSettings = Get-Content -Path (Join-Path -Path $modulePath -ChildPath 'jvSettings.json') | ConvertFrom-Json -Depth 32

try {
if (Test-Path -Path $origSettings.'location.thumbcsv') {
$origThumbsPath = (Get-Item -Path $origSettings.'location.thumbcsv').FullName
} else {
$origThumbsPath = Join-Path -Path $modulePath -ChildPath 'jvThumbs.csv'
}

$origThumbs = Import-Csv -Path $origThumbsPath -Encoding utf8 -ErrorAction Continue
} catch {
Write-Error "Error occurred when retrieving thumb csv [$origThumbsPath]: $PSItem" -ErrorAction Stop
}

try {
if (Test-Path -Path $origSettings.'location.genrecsv') {
$origGenresPath = (Get-Item -Path $origSettings.'location.genrecsv').FullName
} else {
$origGenresPath = Join-Path -Path $modulePath -ChildPath 'jvGenres.csv'
}

$origGenres = Import-Csv -Path $origGenresPath -Encoding utf8 -ErrorAction Continue
} catch {
Write-Error "Error occurred when retrieving genre csv [$origGenresPath]: $PSItem" -ErrorAction Stop
}

try {
if (Test-Path -Path $origSettings.'location.uncensorcsv') {
$origUncensorPath = (Get-Item -Path $origSettings.'location.uncensorcsv').FullName
} else {
$origUncensorPath = Join-Path -Path $modulePath -ChildPath 'jvUncensor.csv'
}

$origUncensor = Import-Csv -Path $origUncensorPath -Encoding utf8 -ErrorAction Continue
} catch {
Write-Error "Error occurred when retrieving uncensor csv [$origUncensorPath]: $PSItem" -ErrorAction Stop
}

try {
if (Test-Path -Path $origSettings.'location.historycsv') {
$origHistoryPath = (Get-Item -Path $origSettings.'location.historycsv').FullName
} else {
$origHistoryPath = Join-Path -Path $modulePath -ChildPath 'jvHistory.csv'
}

$origHistory = Import-Csv -Path $origHistoryPath -Encoding utf8 -ErrorAction Continue
} catch {
Write-Error "Error occurred when retrieving history csv [$origHistoryPath]: $PSItem" -ErrorAction Stop
}

try {
if (Test-Path -Path $origSettings.'location.tagcsv') {
$origTagsPath = (Get-Item -Path $origSettings.'location.tagcsv').FullName
} else {
$origTagsPath = Join-Path -Path $modulePath -ChildPath 'jvTags.csv'
}

$origTags = Import-Csv -Path $origTagsPath -Encoding utf8 -ErrorAction Continue
} catch {
Write-Error "Error occurred when retrieving tag csv [$origTagsPath]: $PSItem" -ErrorAction Stop
}

try {
Write-Progress -Status "Updating Javinizer" -Activity "Updating Javinizer module via PowerShell Gallery..." -PercentComplete 50
Update-Module -Name 'Javinizer' -Force -Confirm:$false
} catch {
Write-Error "Error occurred when updating the Javinizer module: $PSItem" -ErrorAction Stop
}

$newModulePath = (Get-InstalledModule -Name 'Javinizer').InstalledLocation

# Update jvSettings
$supportedScrapers = Get-Help Get-JVData -Parameter * | Select-Object -ExpandProperty aliases | Where-Object { $_.StartsWith("scraper.movie") } | ForEach-Object { $_.Replace("scraper.movie.", "") }
$newSettingsPath = Join-Path -Path $newModulePath -ChildPath 'jvSettings.json'
$newSettings = Get-JVSettings -Path $newSettingsPath
$newSettings.PSObject.Properties | ForEach-Object {
$property = $_
if ($origSettings.PSObject.Properties.Name -contains $_.Name) {
$newSettings."$($_.Name)" = ($origSettings.PSObject.Properties | Where-Object { $_.Name -eq $property.Name })[0].Value
if ($_.Name.StartsWith("sort.metadata.priority")) {
$elementIndex = $_.Value.IndexOf(($_.Value | Where-Object { $_ -eq "r18" }))
if ($elementIndex -ge 0) {
$_.Value[$elementIndex] = "r18dev"
}
$newSettings."$($_.Name)" = $_.Value | Where-Object { $_ -in $supportedScrapers }
}
}
}

try {
Write-Progress -Status "Updating Javinizer" -Activity "Migrating settings to $newSettingsPath..." -PercentComplete 65
$newSettings | ConvertTo-Json -Depth 32 | Out-File -FilePath $newSettingsPath -Force -ErrorAction Continue
} catch {
Write-Error "Error occurred when updating the existing settings file at path [$newSettingsPath]: $PSItem" -ErrorAction Continue
$tempFile = New-TemporaryFile
$newSettings | ConvertTo-Json -Depth 32 | Out-File -FilePath $tempFile
Write-Warning "Writing updated settings file to temp location: $(Join-Path -Path $env:TEMP -ChildPath $tempFile)"
}

# Update jvThumbs
try {
$newThumbsPath = Join-Path -Path $newModulePath -ChildPath 'jvThumbs.csv'
Write-Progress -Status "Updating Javinizer" -Activity "Migrating thumbs to $newThumbsPath..." -PercentComplete 70
Write-Host "Migrating $origThumbsPath => $newThumbsPath"
Copy-Item -Path $origThumbsPath -Destination $newThumbsPath -Force
<# $newThumbs = Import-Csv -Path $newThumbsPath -Encoding utf8
if ($null -ne $origThumbs) {
$thumbsDifference = (Compare-Object -ReferenceObject $origThumbs -DifferenceObject $newThumbs -ErrorAction SilentlyContinue).InputObject
if ($thumbsDifference) {
$thumbsDifference | Export-Csv -Path $newThumbsPath -Append -Encoding utf8 -ErrorAction SilentlyContinue
Write-Host "Migrating $origThumbsPath => $newThumbsPath"
} else {
Write-Host "Migrating $origThumbsPath => $newThumbsPath (no changes)"
}
} #>
} catch {
Write-Warning "Error [$origThumbsPath]: $PSItem"
}

# Update jvGenres
try {
$newGenresPath = Join-Path -Path $newModulePath -ChildPath 'jvGenres.csv'
Write-Progress -Status "Updating Javinizer" -Activity "Migrating genres to $newGenresPath..." -PercentComplete 75
Write-Host "Migrating $origGenresPath => $newGenresPath"
Copy-Item -Path $origGenresPath -Destination $newGenresPath -Force
<# $newGenres = Import-Csv -Path $newGenresPath -Encoding utf8
if ($null -ne $origGenres) {
$genresDifference = (Compare-Object -ReferenceObject $origGenres -DifferenceObject $newGenres -ErrorAction SilentlyContinue).InputObject
if ($genresDifference) {
$genresDifference | Export-Csv -Path $newGenresPath -Append -Encoding utf8 -ErrorAction SilentlyContinue
} else {
Write-Host "Migrating $origGenresPath => $newGenresPath (no changes)"
}
} #>
} catch {
Write-Warning "Error [$origGenresPath]: $PSItem"
}

# Update jvUncensor
try {
$newUncensorPath = Join-Path -Path $newModulePath -ChildPath 'jvUncensor.csv'
Write-Progress -Status "Updating Javinizer" -Activity "Migrating uncensors to $newUncensorPath..." -PercentComplete 80
$newUncensor = Import-Csv -Path $newUncensorPath -Encoding utf8
if ($null -ne $origUncensor) {
$uncensorDifference = (Compare-Object -ReferenceObject $origUncensor -DifferenceObject $newUncensor -ErrorAction SilentlyContinue).InputObject
if ($uncensorDifference) {
$uncensorDifference | Export-Csv -Path $newUncensorPath -Append -Encoding utf8 -ErrorAction SilentlyContinue
Write-Host "Migrating $origUncensorPath => $newUncensorPath"
} else {
Write-Host "Migrating $origUncensorPath => $newUncensorPath (no changes)"
}
}
} catch {
Write-Warning "Error [$origUncensorPath]: $PSItem"
}

# Update jvHistory
try {
$newHistoryPath = Join-Path -Path $newModulePath -ChildPath 'jvHistory.csv'
Write-Progress -Status "Updating Javinizer" -Activity "Migrating history to $newHistoryPath..." -PercentComplete 85
Write-Host "Migrating $origHistoryPath => $newHistoryPath"
Copy-Item -Path $origHistoryPath -Destination $newHistoryPath -Force
<# $newHistory = Import-Csv -Path $newHistoryPath -Encoding utf8
if ($null -ne $origHistory) {
$historyDifference = (Compare-Object -ReferenceObject $origHistory -DifferenceObject $newHistory -ErrorAction SilentlyContinue).InputObject
if ($historyDifference) {
$historyDifference | Export-Csv -Path $newHistoryPath -Append -Encoding utf8 -ErrorAction SilentlyContinue
} else {
Write-Host "Migrating $origHistoryPath => $newHistoryPath (no changes)"
}
} #>
} catch {
Write-Warning "Error [$origHistoryPath]: $PSItem"
}

# Update jvTags
try {
$newTagsPath = Join-Path -Path $newModulePath -ChildPath 'jvTags.csv'
Write-Progress -Status "Updating Javinizer" -Activity "Migrating tags to $newTagsPath..." -PercentComplete 90
Write-Host "Migrating $origTagsPath => $newTagsPath"
Copy-Item -Path $origTagsPath -Destination $newTagsPath -Force
<# $newTags = Import-Csv -Path $newTagsPath -Encoding utf8
if ($null -ne $origTags) {
$tagsDifference = (Compare-Object -ReferenceObject $origTags -DifferenceObject $newTags -ErrorAction SilentlyContinue).InputObject
if ($tagsDifference) {
$tagsDifference | Export-Csv -Path $newTagsPath -Append -Encoding utf8 -ErrorAction SilentlyContinue
} else {
Write-Host "Migrating $origTagsPath => $newTagsPath (no changes)"
}
} #>
} catch {
Write-Warning "Error [$origTagsPath]: $PSItem"
}

Write-Host "Javinizer update completed! Restart your shell to continue." -ForegroundColor Green
20 changes: 15 additions & 5 deletions src/Javinizer/Public/Javinizer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ function Javinizer {
.PARAMETER Nfo
Specifies to output the nfo contents from -Find.
.PARAMETER R18Dev
Specifies to search R18.dev when using -Find.
.PARAMETER Dmm
Specifies to search Dmm when using -Find.
Expand Down Expand Up @@ -180,7 +183,7 @@ function Javinizer {
Sorts files from a path and specify an external settings file to use.
.EXAMPLE
Javinizer -Find 'ABP-420' -R18 -Dmm
Javinizer -Find 'ABP-420' -R18Dev -Dmm
Description
-----------
Expand All @@ -194,7 +197,7 @@ function Javinizer {
Find an array of urls metadata and aggregates them according to your settings file.
.EXAMPLE
Javinizer -Find 'ABP-420' -R18 -Javlibrary -Dmm -Aggregated -Nfo
Javinizer -Find 'ABP-420' -R18Dev -Javlibrary -Dmm -Aggregated -Nfo
Description
-----------
Expand Down Expand Up @@ -333,6 +336,9 @@ function Javinizer {
[Parameter(ParameterSetNAme = 'Info')]
[Switch]$Nfo,

[Parameter(ParameterSetName = 'Info')]
[Switch]$R18Dev,

[Parameter(ParameterSetName = 'Info')]
[Switch]$Dmm,

Expand Down Expand Up @@ -718,7 +724,7 @@ function Javinizer {
$item.Url | Get-JavlibraryData -JavlibraryBaseUrl $Settings.'javlibrary.baseurl'
}

if ($item.Source -match 'r18') {
if ($item.Source -match 'r18dev') {
$item.Url | Get-R18DevData -UncensorCsvPath:$uncensorCsvPath
}

Expand Down Expand Up @@ -748,7 +754,7 @@ function Javinizer {
}
} else {
$data = Get-JVData -Id $Find -Javlibrary:$Javlibrary -JavlibraryJa:$JavlibraryJa -JavlibraryZh:$JavlibraryZh -Dmm:$Dmm `
-DmmJa:$DmmJa -Javbus:$Javbus -JavbusJa:$JavbusJa -JavbusZh:$JavbusZh -Jav321Ja:$Jav321Ja -JavlibraryBaseUrl $Settings.'javlibrary.baseurl' `
-DmmJa:$DmmJa -R18Dev:$R18Dev -Javbus:$Javbus -JavbusJa:$JavbusJa -JavbusZh:$JavbusZh -Jav321Ja:$Jav321Ja -JavlibraryBaseUrl $Settings.'javlibrary.baseurl' `
-MgstageJa:$MgstageJa -Aventertainment:$Aventertainment -AventertainmentJa:$AventertainmentJa -Tokyohot:$Tokyohot -TokyohotJa:$TokyohotJa -TokyohotZh:$TokyohotZh -UncensorCsvPath $uncensorCsvPath -Strict:$Strict `
-Javdb:$Javdb -JavdbZh:$JavdbZh -Session:$CfSession -JavdbSession:$Settings.'javdb.cookie.session' -AllResults:$AllResults
}
Expand Down Expand Up @@ -980,7 +986,11 @@ function Javinizer {
$DestinationPath = $Settings.'location.output'
} catch {
# Default destination path to the current directory if settings not specified
$DestinationPath = (Get-Item -LiteralPath $Path).Directory
if ((Get-Item $Path).PSIsContainer) {
$DestinationPath = (Get-Item -LiteralPath $Path).FullName
} else {
$DestinationPath = (Get-Item -LiteralPath $Path).DirectoryName
}
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/Javinizer/Public/Update-JVModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ function Update-JVModule {
[Switch]$GuiVersion,

[Parameter(ParameterSetName = 'Update')]
[String]$UpdateUrl = 'https://gist.githubusercontent.com/jvlflame/0e8293198e59c286ccf1a438ea8a76e9/raw'
[String]$UpdateUrl = 'https://raw.githubusercontent.com/jvlflame/Javinizer/master/src/Javinizer/Misc/Invoke-Update.ps1'
)

process {
switch ($PsCmdlet.ParameterSetName) {
'Check' {
if ($IsWeb) {
$installedVersion = (Get-JVModuleInfo).Version
$latestVersion = (Find-Module -Name 'Javinizer').Version
if ($installedVersion -ne $latestVersion) {
$latestVersion = ((Find-Module -Name 'Javinizer') | Select-Object -First 1).Version
if ([System.Version]$installedVersion -lt [System.Version]$latestVersion) {
Show-JVToast -Type Success -Message "There is a new version of Javinizer available $installedVersion => $latestVersion"
} else {
Show-JVToast -Type Info -Message "There are no updates for Javinizer available"
Expand All @@ -32,7 +32,7 @@ function Update-JVModule {
$guiCheck = Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/jvlflame/Javinizer/master/src/Javinizer/Universal/Repository/javinizergui.ps1' -MaximumRetryCount 3
$latestGuiVersion = ($guiCheck.Content | Select-String -Pattern "\`$cache\:guiVersion = '(.*)'").Matches.Groups[1].Value

if ($GuiVersion -ne $latestGuiVersion) {
if ([System.Version]$GuiVersion -lt [System.Version]$latestGuiVersion) {
Show-JVToast -Type Success -Message "There is a new version of Javinizer GUI available $GuiVersion => $latestGuiVersion"
} else {
Show-JVToast -Type Info -Message "There are no updates for Javinizer GUI available"
Expand All @@ -42,11 +42,11 @@ function Update-JVModule {
# Set global variable to determine that check has already been completed in the current session
$global:jvUpdateCheck = $true
$installedVersion = (Get-JVModuleInfo).Version
$latestVersion = (Find-Module -Name 'Javinizer').Version
$latestVersion = ((Find-Module -Name 'Javinizer') | Select-Object -First 1).Version
Write-Debug "Installed version: $installedVersion"
Write-Debug "Latest version: $latestVersion"

if ($installedVersion -ne $latestVersion) {
if ([System.Version]$installedVersion -lt [System.Version]$latestVersion) {
Write-Warning "There is a newer version of Javinizer available! (Set 'admin.updates.check' to false to hide this message)"
Write-Warning "You can update your module using 'Javinizer -UpdateModule'"
Write-Warning "$installedVersion => $latestVersion"
Expand All @@ -62,9 +62,9 @@ function Update-JVModule {
}

$installedVersion = (Get-JVModuleInfo).Version
$latestVersion = (Find-Module -Name 'Javinizer').Version
$latestVersion = ((Find-Module -Name 'Javinizer') | Select-Object -First 1).Version

if ($installedVersion -ne $latestVersion) {
if ([System.Version]$installedVersion -lt [System.Version]$latestVersion) {
Write-Warning "Starting update process, please make sure to close all related Javinizer settings files before continuing"
Write-Warning "Updating from version [$installedVersion => $latestVersion]"
Pause
Expand Down
2 changes: 1 addition & 1 deletion src/Javinizer/Universal/Repository/javinizergui.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$cache:guiVersion = '2.5.11-1'
$cache:guiVersion = '2.5.12-1'

# Define Javinizer module file paths
$cache:modulePath = (Get-InstalledModule -Name Javinizer).InstalledLocation
Expand Down

0 comments on commit eabd618

Please sign in to comment.