Skip to content

Commit

Permalink
Update logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jvlflame committed Sep 1, 2020
1 parent c6b91ce commit 8861383
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Javinizer/Private/Scraper.R18.ps1
Expand Up @@ -223,10 +223,10 @@ function Get-R18Series {

if ($series -like '*...') {
try {
Write-JLog -Level Debug -Message "Performing [GET] on URL [$seriesUrl]"
Write-JVLog -Level Debug -Message "Performing [GET] on URL [$seriesUrl]"
$seriesSearch = Invoke-WebRequest -Uri $seriesUrl -Method Get -Verbose:$false
} catch {
Write-JLog -Level ERROR -Message "Error [GET] on URL [$seriesUrl]: $PSItem"
Write-JVLog -Level ERROR -Message "Error [GET] on URL [$seriesUrl]: $PSItem"
}
$series = (Convert-HtmlCharacter -String ((((($seriesSearch.Content -split '<div class="breadcrumbs">')[1]) -split '<\/span>')[0]) -split '<span>')[1]) -replace "`t", ''
}
Expand Down
30 changes: 16 additions & 14 deletions src/Javinizer/Public/Get-JVData.ps1
Expand Up @@ -70,95 +70,97 @@ function Get-JVData {
$jvModulePath = Join-Path -Path ((Get-Item $PSScriptRoot).Parent) -ChildPath 'Javinizer.psm1'

if ($R18) {
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching R18"
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - R18]"
Start-ThreadJob -Name "$Id-R18" -ScriptBlock {
Import-Module $using:jvModulePath
Get-R18Url -Id $using:Id -Language en | Get-R18Data
} | Out-Null
}

if ($R18Zh) {
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching R18Zh"
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - R18Zh]"
Start-ThreadJob -Name "$Id-R18Zh" -ScriptBlock {
Import-Module $using:jvModulePath
Get-R18Url -Id $using:Id -Language zh | Get-R18Data
} | Out-Null
}

if ($Javlibrary) {
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching Javlibrary"
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - Javlibrary]"
Start-ThreadJob -Name "$Id-Javlibrary" -ScriptBlock {
Import-Module $using:jvModulePath
Get-JavlibraryUrl -Id $using:Id -Language en | Get-JavlibraryData
} | Out-Null
}

if ($JavlibraryJa) {
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching JavlibraryJa"
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - JavlibraryJa]"
Start-ThreadJob -Name "$Id-JavlibraryJa" -ScriptBlock {
Import-Module $using:jvModulePath
Get-JavlibraryUrl -Id $using:Id -Language ja | Get-JavlibraryData
} | Out-Null
}

if ($JavlibraryZh) {
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching JavlibraryZh"
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - JavlibraryZh]"
Start-ThreadJob -Name "$Id-JavlibraryZh" -ScriptBlock {
Import-Module $using:jvModulePath
Get-JavlibraryUrl -Id $using:Id -Language zh | Get-JavlibraryData
} | Out-Null
}

if ($Dmm) {
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching Dmm"
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - Dmm]"
Start-ThreadJob -Name "$Id-Dmm" -ScriptBlock {
Import-Module $using:jvModulePath
Get-DmmUrl -Id $using:Id | Get-DmmData
} | Out-Null
}

if ($Javbus) {
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching Javbus"
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - Javbus]"
Start-ThreadJob -Name "$Id-Javbus" -ScriptBlock {
Import-Module $using:jvModulePath
Get-JavbusUrl -Id $using:Id -Language en | Get-JavbusData
} | Out-Null
}

if ($JavbusJa) {
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching JavbusJa"
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - JavbusJa]"
Start-ThreadJob -Name "$Id-JavbusJa" -ScriptBlock {
Import-Module $using:jvModulePath
Get-JavbusUrl -Id $using:Id -Language ja | Get-JavbusData
} | Out-Null
}

if ($JavbusZh) {
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching JavbusZh"
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - JavbusZh]"
Start-ThreadJob -Name "$Id-JavbusZh" -ScriptBlock {
Import-Module $using:jvModulePath
Get-JavbusUrl -Id $using:Id -Language zh | Get-JavbusData
} | Out-Null
}

if ($Jav321) {
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching Jav321"
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - Jav321]"
Start-ThreadJob -Name "$Id-Jav321" -ScriptBlock {
Import-Module $using:jvModulePath
Get-Jav321Url -Id $using:Id | Get-Jav321Data
} | Out-Null
}

# 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 scraper jobs to complete"

$jobId = @((Get-Job | Where-Object { $_.Name -like "$Id*" } | Select-Object Id).Id)
$jobName = @((Get-Job | Where-Object { $_.Name -like "$Id*" } | Select-Object Name).Name)
Write-Debug "[$Id] [$($MyInvocation.MyCommand.Name)] [Waiting - Scraper jobs] [$jobName]"
Wait-Job -Id $jobId | Out-Null

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

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

$dataObject = [PSCustomObject]@{
Data = $javinizerDataObject
Expand All @@ -171,7 +173,7 @@ function Get-JVData {
} finally {
# Remove all completed or running jobs before exiting this script
# If jobs remain after closure, it may cause issues in concurrent runs
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Stopping/removing all completed/running jobs"
Write-JVLog -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Removed - Scraper jobs]"
Get-Job | Remove-Job -Force
}
}
Expand Down

0 comments on commit 8861383

Please sign in to comment.