Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jvlflame committed Aug 30, 2020
1 parent 1a5fafa commit 5b8407c
Show file tree
Hide file tree
Showing 8 changed files with 636 additions and 62 deletions.
72 changes: 72 additions & 0 deletions src/Javinizer/Private/Convert-JVString.ps1
@@ -0,0 +1,72 @@
function Convert-JVString {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[PSObject]$Data,
[Parameter(Mandatory = $true)]
[String]$FormatString,
[Parameter()]
[Int]$PartNumber,
[Parameter()]
[Int]$MaxTitleLength
)

process {
# These symbols need to be removed to create a valid Windows filesystem name
$invalidSymbols = @(
'\',
'/',
':',
'*',
'?',
'"',
'<',
'>',
'|',
"'"
)

if ($maxTitleLength) {
if ($Data.Title.Length -ge $MaxTitleLength) {
$shortTitle = $Data.Title.Substring(0, $MaxTitleLength)
$splitTitle = $shortTitle -split ' '
if ($splitTitle.Count -gt 1) {
# Remove the last word of the title just in case it is cut off
$title = ($splitTitle[0..($splitTitle.Length - 2)] -join ' ')
if ($title[-1] -match '\W') {
$Data.Title = ($title.Substring(0, $title.Length - 2)) + '...'
} else {
$Data.Title = $title + '...'
}
} else {
$Data.Title = $shortTitle + '...'
}
}
}

$convertedName = $FormatString `
-replace '<ID>', "$($Data.Id)" `
-replace '<TITLE>', "$($Data.Title)" `
-replace '<RELEASEDATE>', "$($Data.ReleaseDate)" `
-replace '<YEAR>', "$(($Data.ReleaseDate -split '-')[0])" `
-replace '<STUDIO>', "($($Data.Maker)" `
-replace '<RUNTIME>', "$($Data.Runtime)" `
-replace '<SET>', "$($Data.Series)" `
-replace '<LABEL>', "$($Data.Label)" `
-replace '<ORIGINALTITLE>', "$($Data.AlternateTitle)"

foreach ($symbol in $invalidSymbols) {
if ([regex]::Escape($symbol) -eq '/') {
$convertedName = $convertedName -replace [regex]::Escape($symbol), '-'
} else {
$convertedName = $convertedName -replace [regex]::Escape($symbol), ''
}
}

if ($PartNumber) {
$convertedName += "-pt$PartNumber"
}

Write-Output $convertedName
}
}
1 change: 1 addition & 0 deletions src/Javinizer/Public/Get-DmmData.ps1
Expand Up @@ -14,6 +14,7 @@ function Get-DmmData {
$webRequest = Invoke-WebRequest -Uri $dmmUrl -Method Get -Verbose:$false
} catch {
Write-JLog -Level Error -Message "Error [GET] on URL [$dmmUrl]: $PSItem"
return
}

$movieDataObject = [PSCustomObject]@{
Expand Down
43 changes: 35 additions & 8 deletions src/Javinizer/Public/Get-JVAggregatedData.ps1
@@ -1,10 +1,9 @@
function Get-JVAggregatedData {
[CmdletBinding(DefaultParameterSetName = 'Pipeline')]
[CmdletBinding(DefaultParameterSetName = 'Setting')]
param (
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Pipeline')]
[Parameter(Mandatory = $true, ParameterSetName = 'Setting')]
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Setting')]
[PSObject]$Data,
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Pipeline')]
[Parameter(Mandatory = $true, ParameterSetName = 'Setting')]
[PSObject]$Settings,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Setting')]
[Alias('sort.metadata.priority.actress')]
Expand Down Expand Up @@ -50,7 +49,31 @@ function Get-JVAggregatedData {
[Array]$TitlePriority,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Setting')]
[Alias('sort.metadata.priority.trailerurl')]
[Array]$TrailerUrlPriority
[Array]$TrailerUrlPriority,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Setting')]
[Alias('sort.metadata.displayname')]
[String]$DisplayNameFormat,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Setting')]
[Alias('sort.metadata.firstnameorder')]
[Boolean]$FirstNameOrder,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Setting')]
[Alias('sort.metadata.thumbcsv')]
[Boolean]$ThumbCsv,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Setting')]
[Alias('sort.metadata.thumbcsv.convertalias')]
[Boolean]$ThumbCsvAlias,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Setting')]
[Alias('sort.metadata.genre.normalize')]
[Boolean]$NormalizeGenre,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Setting')]
[Alias('sort.metadata.genre.ignore')]
[Array]$IgnoreGenre,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Setting')]
[Alias('sort.metadata.requiredfield')]
[Array]$RequiredField,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Setting')]
[Alias('sort.metadata.maxtitlelength')]
[Int]$MaxTitleLength
)

process {
Expand All @@ -70,10 +93,12 @@ function Get-JVAggregatedData {
$ScreenshotUrlPriority = $Settings.'sort.metadata.priority.screenshoturl'
$TitlePriority = $Settings.'sort.metadata.priority.title'
$TrailerUrlPriority = $Settings.'sort.metadata.priority.trailerurl'
$DisplayNameFormat = $Settings.'sort.metadata.nfo.displayname'
}

$aggregatedDataObject = [PSCustomObject]@{
Id = $null
DisplayName = $null
Title = $null
AlternateTitle = $null
Description = $null
Expand Down Expand Up @@ -119,14 +144,16 @@ function Get-JVAggregatedData {
} else {
$aggregatedDataObject.$field = $sourceData.$field
}
Write-Debug "[$field] [$priority] Set to [$($sourceData.$field | ConvertTo-Json -Compress)]"
Write-JLog -Level Debug -Message "[$($Data[0].Id)] [$($MyInvocation.MyCommand.Name)] [$field - $priority] Set to [$($sourceData.$field | ConvertTo-Json -Compress)]"
}
}
}

$aggregatedDataObject.DisplayName = Convert-JVString -Data $aggregatedDataObject -FormatString $DisplayNameFormat


$dataObject = [PSCustomObject]@{
Data = $aggregatedDataObject
Settings = $Settings
Data = $aggregatedDataObject
}

Write-Output $dataObject
Expand Down
75 changes: 47 additions & 28 deletions src/Javinizer/Public/Get-JVData.ps1
@@ -1,7 +1,7 @@
function Get-JVData {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, Position = 0)]
[Parameter(Position = 0, ValueFromPipelineByPropertyName = $true)]
[String]$Id,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('scraper.movie.r18')]
Expand Down Expand Up @@ -40,104 +40,123 @@ function Get-JVData {
process {
$javinizerDataObject = @()

if ($Settings) {
$R18 = $Settings.'scraper.movie.r18'
$R18Zh = $Settings.'scraper.movie.r18zh'
$Jav321 = $Settings.'scraper.movie.jav321'
$Javlibrary = $Settings.'scraper.movie.javlibrary'
$JavlibraryJa = $Settings.'scraper.movie.javlibraryja'
$JavlibraryZh = $Settings.'scraper.movie.javlibraryzh'
$Dmm = $Settings.'scraper.movie.dmm'
$Javbus = $Settings.'scraper.movie.javbus'
$JavbusJa = $Settings.'scraper.movie.javbusja'
$JavbusZh = $Settings.'scraper.movie.javbuszh'
}

try {
if ($R18) {
Write-JLog -Level Info -Message "Searching [R18] for Id: [$Id]"
Write-JLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching R18"
Start-ThreadJob -Name "$Id-R18" -ScriptBlock {
Import-Module X:\git\Projects\JAV-Organizer\src\Javinizer\Javinizer.psm1
Get-R18Url -Id $using:Id -Language en | Get-R18Data
} | Out-Null
}

if ($R18Zh) {
Write-JLog -Level Info -Message "Searching [R18Zh] for Id: [$Id]"
Write-JLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching R18Zh"
Start-ThreadJob -Name "$Id-R18Zh" -ScriptBlock {
Import-Module X:\git\Projects\JAV-Organizer\src\Javinizer\Javinizer.psm1
Get-R18Url -Id $using:Id -Language zh | Get-R18Data
} | Out-Null
}

if ($Javlibrary) {
Write-JLog -Level Info -Message "Searching [Javlibrary] for Id: [$Id]"
Write-JLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching Javlibrary"
Start-ThreadJob -Name "$Id-Javlibrary" -ScriptBlock {
Import-Module X:\git\Projects\JAV-Organizer\src\Javinizer\Javinizer.psm1
Get-JavlibraryUrl -Id $using:Id -Language en | Get-JavlibraryData
} | Out-Null
}

if ($JavlibraryJa) {
Write-JLog -Level Info -Message "Searching [JavlibraryJa] for Id: [$Id]"
Write-JLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching JavlibraryJa"
Start-ThreadJob -Name "$Id-JavlibraryJa" -ScriptBlock {
Import-Module X:\git\Projects\JAV-Organizer\src\Javinizer\Javinizer.psm1
Get-JavlibraryUrl -Id $using:Id -Language ja | Get-JavlibraryData
} | Out-Null
}

if ($JavlibraryZh) {
Write-JLog -Level Info -Message "Searching [JavlibraryZh] for Id: [$Id]"
Write-JLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching JavlibraryZh"
Start-ThreadJob -Name "$Id-JavlibraryZh" -ScriptBlock {
Import-Module X:\git\Projects\JAV-Organizer\src\Javinizer\Javinizer.psm1
Get-JavlibraryUrl -Id $using:Id -Language zh | Get-JavlibraryData
} | Out-Null
}

if ($Dmm) {
Write-JLog -Level Info -Message "Searching [Dmm] for Id: [$Id]"
Write-JLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching Dmm"
Start-ThreadJob -Name "$Id-Dmm" -ScriptBlock {
Import-Module X:\git\Projects\JAV-Organizer\src\Javinizer\Javinizer.psm1
Get-DmmUrl -Id $using:Id | Get-DmmData
} | Out-Null
}

if ($Javbus) {
Write-JLog -Level Info -Message "Searching [Javbus] for Id: [$Id]"
Write-JLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching Javbus"
Start-ThreadJob -Name "$Id-Javbus" -ScriptBlock {
Import-Module X:\git\Projects\JAV-Organizer\src\Javinizer\Javinizer.psm1
Get-JavbusUrl -Id $using:Id -Language en | Get-JavbusData
} | Out-Null
}

if ($JavbusJa) {
Write-JLog -Level Info -Message "Searching [JavbusJa] for Id: [$Id]"
Write-JLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching JavbusJa"
Start-ThreadJob -Name "$Id-JavbusJa" -ScriptBlock {
Import-Module X:\git\Projects\JAV-Organizer\src\Javinizer\Javinizer.psm1
Get-JavbusUrl -Id $using:Id -Language ja | Get-JavbusData
} | Out-Null
}

if ($JavbusZh) {
Write-JLog -Level Info -Message "Searching [JavbusZh] for Id: [$Id]"
Write-JLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching JavbusZh"
Start-ThreadJob -Name "$Id-JavbusZh" -ScriptBlock {
Import-Module X:\git\Projects\JAV-Organizer\src\Javinizer\Javinizer.psm1
Get-JavbusUrl -Id $using:Id -Language zh | Get-JavbusData
} | Out-Null
}

if ($Jav321) {
Write-JLog -Level Info -Message "Searching [Jav321] for Id: [$Id]"
Write-JLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching Jav321"
Start-ThreadJob -Name "$Id-Jav321" -ScriptBlock {
Import-Module X:\git\Projects\JAV-Organizer\src\Javinizer\Javinizer.psm1
Get-Jav321Url -Id $using:Id | Get-Jav321Data
} | Out-Null
}

# Wait for all jobs to complete to write to the combined data object
$javinizerDataObject = Get-Job | Receive-Job -AutoRemoveJob -Wait -Force

# Wait-Job is used separately rather than in a pipeline due to the PowerShell.Exit job that is being created during the first-run of this function
Write-Debug "[$Id] [$($MyInvocation.MyCommand.Name)] Waiting for jobs to complete"
$jobId = @((Get-Job | Where-Object { $_.Name -like "$Id*" } | Select-Object Id).Id)
Wait-Job -Id $jobId | Out-Null

Write-Debug "[$Id] [$($MyInvocation.MyCommand.Name)] Jobs completed"
$javinizerDataObject = Get-Job -Id $jobId | Receive-Job

$hasData = ($javinizerDataObject | Select-Object Source).Source
Write-JLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Data successfully retrieved from sources [$hasData]"

$dataObject = [PSCustomObject]@{
Data = $javinizerDataObject
Settings = $Settings
Data = $javinizerDataObject
}

Write-Output $dataObject

} catch {
Write-JLog -Level Error -Message "Error occured during scraper jobs: $PSItem"
Write-JLog -Level Error -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Error occured during scraper jobs: $PSItem"
} finally {
# Remove all completed or running jobs before exiting this script
# If jobs remain after closure, it may cause issues in concurrent runs
Write-JLog -Level Debug -Message "Stopping/removing all completed/running jobs"
Write-JLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Stopping/removing all completed/running jobs"
Get-Job | Remove-Job -Force
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Javinizer/Public/Get-JVItem.ps1
Expand Up @@ -53,8 +53,8 @@ function Get-JVItem {
}
} else {
foreach ($file in $files) {
$fileObject += $file | Convert-JVTitle -Strict:$Strict -RegexEnabled:$RegexEnabled
}
$fileObject += $file | Convert-JVTitle -Strict:$Strict -RegexEnabled:$RegexEnabled
}
}

Write-Output $fileObject
Expand Down

0 comments on commit 5b8407c

Please sign in to comment.