-
Notifications
You must be signed in to change notification settings - Fork 61
/
Get-JVData.ps1
253 lines (217 loc) · 12.8 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#Requires -PSEdition Core
function Get-JVData {
[CmdletBinding(DefaultParameterSetName = 'Id')]
param (
[Parameter(Position = 0, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Id')]
[String]$Id,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Id')]
[Alias('scraper.movie.r18')]
[Boolean]$R18,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Id')]
[Alias('scraper.movie.r18zh')]
[Boolean]$R18Zh,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Id')]
[Alias('scraper.movie.javlibrary')]
[Boolean]$Javlibrary,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Id')]
[Alias('scraper.movie.javlibraryja')]
[Boolean]$JavlibraryJa,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Id')]
[Alias('scraper.movie.javlibraryzh')]
[Boolean]$JavlibraryZh,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Id')]
[Alias('scraper.movie.dmm')]
[Boolean]$Dmm,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Id')]
[Alias('scraper.movie.javbus')]
[Boolean]$Javbus,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Id')]
[Alias('scraper.movie.javbusja')]
[Boolean]$JavbusJa,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Id')]
[Alias('scraper.movie.javbuszh')]
[Boolean]$JavbusZh,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Id')]
[Alias('scraper.movie.jav321')]
[Boolean]$Jav321,
[Parameter(ValueFromPipelineByPropertyName = $true, ParameterSetName = 'Id')]
[Alias('javlibrary.baseurl')]
[String]$JavlibraryBaseUrl = 'http://www.javlibrary.com',
[Parameter(ValueFromPipeline = $true, ParameterSetName = 'Id')]
[Parameter(ValueFromPipeline = $true, ParameterSetName = 'Url')]
[PSObject]$Settings,
[Parameter(ParameterSetName = 'Url')]
[PSObject]$Url
)
process {
$javinizerDataObject = @()
$Id = $Id.ToUpper()
if ($Url) {
$urlObject = $Url | Get-JVUrlLocation
} elseif ($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'
}
if ($Settings) {
$JavlibraryBaseUrl = $Settings.'javlibrary.baseurl'
}
if ($JavlibraryBaseUrl[-1] -eq '/') {
# Remove the trailing slash if it is included to create the valid searchUrl
$JavlibraryBaseUrl = $JavlibraryBaseUrl[0..($JavlibraryBaseUrl.Length - 1)] -join ''
}
try {
# You need to change this path if you're running the script from outside of the Javinizer module folder
$jvModulePath = Join-Path -Path ((Get-Item $PSScriptRoot).Parent) -ChildPath 'Javinizer.psm1'
foreach ($item in $urlObject) {
Set-Variable -Name "$($item.Source)" -Value $true
Set-Variable -Name "$($item.Source)Url" -Value $item.Url
}
if ($R18) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - R18] [Url - $R18Url]"
Start-ThreadJob -Name "jvdata-R18" -ThrottleLimit 100 -ScriptBlock {
Import-Module $using:jvModulePath
if ($using:R18Url) {
$using:R18Url | Get-R18Data
} else {
Get-R18Url -Id $using:Id -Language en | Get-R18Data
}
} | Out-Null
}
if ($R18Zh) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - R18Zh] [Url - $R18ZhUrl]"
Start-ThreadJob -Name "jvdata-R18Zh" -ThrottleLimit 100 -ScriptBlock {
Import-Module $using:jvModulePath
if ($using:R18ZhUrl) {
$using:R18ZhUrl | Get-R18Data
} else {
Get-R18Url -Id $using:Id -Language zh | Get-R18Data
}
} | Out-Null
}
if ($Javlibrary) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - Javlibrary] [Url - $JavlibraryUrl]"
Start-ThreadJob -Name "jvdata-Javlibrary" -ThrottleLimit 100 -ScriptBlock {
Import-Module $using:jvModulePath
if ($using:JavlibraryUrl) {
$using:JavlibraryUrl | Get-JavlibraryData
} else {
Get-JavlibraryUrl -Id $using:Id -BaseUrl $using:JavlibraryBaseUrl -Language en | Get-JavlibraryData
}
} | Out-Null
}
if ($JavlibraryJa) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - JavlibraryJa] [Url - $JavlibraryJaUrl]"
Start-ThreadJob -Name "jvdata-JavlibraryJa" -ThrottleLimit 100 -ScriptBlock {
Import-Module $using:jvModulePath
if ($using:JavlibraryJaUrl) {
$using:JavlibraryJaUrl | Get-JavlibraryData
} else {
Get-JavlibraryUrl -Id $using:Id -BaseUrl $using:JavlibraryBaseUrl -Language ja | Get-JavlibraryData
}
} | Out-Null
}
if ($JavlibraryZh) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - JavlibraryZh] [Url - $JavlibraryZhUrl]"
Start-ThreadJob -Name "jvdata-JavlibraryZh" -ThrottleLimit 100 -ScriptBlock {
Import-Module $using:jvModulePath
if ($using:JavlibraryZhUrl) {
$using:JavlibraryZhUrl | Get-JavlibraryData
} else {
Get-JavlibraryUrl -Id $using:Id -BaseUrl $using:JavlibraryBaseUrl -Language zh | Get-JavlibraryData
}
} | Out-Null
}
if ($Dmm) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - Dmm] [Url - $DmmUrl]"
Start-ThreadJob -Name "jvdata-Dmm" -ThrottleLimit 100 -ScriptBlock {
Import-Module $using:jvModulePath
if ($using:DmmUrl) {
$using:DmmUrl | Get-DmmData
} else {
Get-DmmUrl -Id $using:Id | Get-DmmData
}
} | Out-Null
}
if ($Javbus) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - Javbus] [Url - $JavbusUrl]"
Start-ThreadJob -Name "jvdata-Javbus" -ThrottleLimit 100 -ScriptBlock {
Import-Module $using:jvModulePath
if ($using:JavbusUrl) {
$using:JavbusUrl | Get-JavbusData
} else {
Get-JavbusUrl -Id $using:Id -Language en | Get-JavbusData
}
} | Out-Null
}
if ($JavbusJa) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - JavbusJa] [Url - $JavbusJaUrl]"
Start-ThreadJob -Name "jvdata-JavbusJa" -ThrottleLimit 100 -ScriptBlock {
Import-Module $using:jvModulePath
if ($using:JavbusJaUrl) {
$using:JavbusJaUrl | Get-JavbusData
} else {
Get-JavbusUrl -Id $using:Id -Language ja | Get-JavbusData
}
} | Out-Null
}
if ($JavbusZh) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - JavbusZh] [Url - $JavbusZhUrl]"
Start-ThreadJob -Name "jvdata-JavbusZh" -ThrottleLimit 100 -ScriptBlock {
Import-Module $using:jvModulePath
if ($using:JavbusZhUrl) {
$using:JavbusZhUrl | Get-JavbusData
} else {
Get-JavbusUrl -Id $using:Id -Language zh | Get-JavbusData
}
} | Out-Null
}
if ($Jav321) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Search - Jav321] [$Url - $Jav321Url]"
Start-ThreadJob -Name "jvdata-Jav321" -ThrottleLimit 100 -ScriptBlock {
Import-Module $using:jvModulePath
if ($using:Jav321Url) {
$using:Jav321Url | Get-Jav321Data
} else {
Get-Jav321Url -Id $using:Id | Get-Jav321Data
}
} | Out-Null
}
$jobCount = (Get-Job | Where-Object { $_.Name -like 'jvdata-*' }).Count
$jobId = @((Get-Job | Where-Object { $_.Name -like "jvdata-*" } | Select-Object Id).Id)
$jobName = @((Get-Job | Where-Object { $_.Name -like "jvdata-*" } | Select-Object Name).Name)
if ($jobCount -eq 0) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Warning -Message "[$Id] No scrapers were run"
return
} else {
Write-Debug "[$Id] [$($MyInvocation.MyCommand.Name)] [Waiting - Scraper jobs] [$jobName]"
# 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
Wait-Job -Id $jobId | Out-Null
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 -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Success - Scraper jobs] [$hasData]"
$dataObject = [PSCustomObject]@{
Data = $javinizerDataObject
}
if ($null -ne $javinizerDataObject) {
Write-Output $dataObject
}
}
} catch {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -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-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] [Removed - Scraper jobs]"
Get-Job | Remove-Job -Force
}
}
}