-
Notifications
You must be signed in to change notification settings - Fork 61
/
Get-JVData.ps1
163 lines (145 loc) · 7.78 KB
/
Get-JVData.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
function Get-JVData {
[CmdletBinding()]
param (
[Parameter(Position = 0, ValueFromPipelineByPropertyName = $true)]
[String]$Id,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('scraper.movie.r18')]
[Boolean]$R18,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('scraper.movie.r18zh')]
[Boolean]$R18Zh,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('scraper.movie.javlibrary')]
[Boolean]$Javlibrary,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('scraper.movie.javlibraryja')]
[Boolean]$JavlibraryJa,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('scraper.movie.javlibraryzh')]
[Boolean]$JavlibraryZh,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('scraper.movie.dmm')]
[Boolean]$Dmm,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('scraper.movie.javbus')]
[Boolean]$Javbus,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('scraper.movie.javbusja')]
[Boolean]$JavbusJa,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('scraper.movie.javbuszh')]
[Boolean]$JavbusZh,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[Alias('scraper.movie.jav321')]
[Boolean]$Jav321,
[Parameter(ValueFromPipeline = $true)]
[PSObject]$Settings
)
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 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 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 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 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 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 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 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 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 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 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-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
}
Write-Output $dataObject
} catch {
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 "[$Id] [$($MyInvocation.MyCommand.Name)] Stopping/removing all completed/running jobs"
Get-Job | Remove-Job -Force
}
}
}