Skip to content

Commit

Permalink
Allow user defined genre csv
Browse files Browse the repository at this point in the history
  • Loading branch information
jvlflame committed Sep 1, 2020
1 parent 47703c0 commit 8952757
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
21 changes: 17 additions & 4 deletions src/Javinizer/Public/Get-JVAggregatedData.ps1
Expand Up @@ -91,6 +91,10 @@ function Get-JVAggregatedData {
[Alias('sort.metadata.genrecsv')]
[Boolean]$ReplaceGenre,

[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Setting')]
[Alias('sort.metadata.genrecsv.path')]
[Boolean]$GenreCsvPath = (Join-Path -Path ((Get-Item $PSScriptRoot).Parent) -ChildPath 'jvGenres.csv'),

[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Setting')]
[Alias('sort.metadata.genre.ignore')]
[Array]$IgnoreGenre,
Expand Down Expand Up @@ -132,6 +136,16 @@ function Get-JVAggregatedData {
$IgnoreGenre = $Settings.'sort.metadata.genre.ignore'
$Translate = $Settings.'sort.metadata.nfo.translate'
$TranslateLanguage = $Settings.'sort.metadata.nfo.translate.language'
$GenreCsvPath = $Settings.'sort.metadata.genrecsv.path'
$ThumbCsvPath = $Settings.'sort.metadata.thumbcsv.path'
}

if ($ThumbCsvPath -eq '') {
$ThumbCsvPath = (Join-Path -Path ((Get-Item $PSScriptRoot).Parent) -ChildPath 'jvThumbs.csv')
}

if ($GenreCsvPath -eq '') {
$GenreCsvPath = (Join-Path -Path ((Get-Item $PSScriptRoot).Parent) -ChildPath 'jvGenres.csv')
}

$aggregatedDataObject = [PSCustomObject]@{
Expand Down Expand Up @@ -288,12 +302,11 @@ function Get-JVAggregatedData {
}

if ($ReplaceGenre) {
$genreCsvPath = Join-Path -Path ((Get-Item $PSScriptRoot).Parent) -ChildPath 'jvGenres.csv'
if (Test-Path -LiteralPath $genreCsvPath) {
if (Test-Path -LiteralPath $GenreCsvPath) {
try {
$replaceGenres = Import-Csv -LiteralPath $genreCsvPath
$replaceGenres = Import-Csv -LiteralPath $GenreCsvPath
} catch {
Write-JVLog -Level Error -Message "[$($Data[0].Id)] [$($MyInvocation.MyCommand.Name)] Error occurred when importing genre csv [$genreCsvPath]: $PSItem"
Write-JVLog -Level Error -Message "[$($Data[0].Id)] [$($MyInvocation.MyCommand.Name)] Error occurred when importing genre csv [$GenreCsvPath]: $PSItem"
}

$newGenres = $aggregatedDataObject.Genre
Expand Down
11 changes: 9 additions & 2 deletions src/Javinizer/Public/Javinizer.ps1
Expand Up @@ -306,8 +306,6 @@ function Javinizer {
)

process {


try {
if ($Settings) {
$settingsPath = $Settings
Expand Down Expand Up @@ -346,6 +344,15 @@ function Javinizer {
$thumbCsvPath = $Settings.'sort.metadata.thumbcsv.path'
}

if ($Settings.'sort.metadata.genrecsv.path' -eq '') {
$genreCsvPath = Join-Path -Path ((Get-Item $PSScriptRoot).Parent) -ChildPath 'jvGenres.csv'
} else {
if (!(Test-Path -LiteralPath $Settings.'sort.metadata.genrecsv.path' -PathType Leaf)) {
New-Item -LiteralPath $Settings.'sort.metadata.genrecsv.path'
}
$thumbCsvPath = $Settings.'sort.metadata.genrecsv.path'
}

switch ($PsCmdlet.ParameterSetName) {
'Info' {
if ($Find -match 'https?:\/\/') {
Expand Down

0 comments on commit 8952757

Please sign in to comment.