-
Notifications
You must be signed in to change notification settings - Fork 61
/
Get-Jav321Url.ps1
71 lines (59 loc) · 2.4 KB
/
Get-Jav321Url.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
function Get-Jav321Url {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)]
[string]$Id
)
process {
$searchUrl = "https://jp.jav321.com/search"
try {
Write-JLog -Level Debug -Message "Performing [GET] on URL [$searchUrl]"
$webRequest = Invoke-WebRequest -Uri $searchUrl -Method Post -Body "sn=$Id" -Verbose:$false
} catch {
Write-JLog -Level Error -Message "Error [GET] on URL [$searchUrl]: $PSItem"
return
}
$Tries = 5
# Get the page search results
$searchResults = $webRequest.Links.OuterHtml | Where-Object { $_ -match 'jav321.com/video/' } |
Select-String -Pattern 'jav321.com/video/(.*)" target' |
ForEach-Object { $_.Matches.Groups[1].Value } |
Select-Object -Unique
$numResults = $searchResults.Count
if ($Tries -gt $numResults) {
$Tries = $numResults
}
if ($numResults -ge 1) {
Write-JLog -Level Debug -Message "Searching [$Tries] of [$numResults] results for [$Id]"
$count = 1
foreach ($result in $searchResults) {
$result = "https://jp.jav321.com/video/$result"
try {
Write-JLog -Level Debug -Message "Performing [GET] on URL [$result]"
$webRequest = Invoke-RestMethod -Uri $result -Method Get -Verbose:$false
} catch {
Write-JLog -Level Error -Message "Error [GET] on URL [$result]: $PSItem"
}
$resultId = Get-Jav321Id -WebRequest $webRequest
if ($resultId -eq $Id) {
$directUrl = $result
break
}
Write-JLog -Level Debug -Message "Result [$count] is [$resultId]"
if ($count -eq $Tries) {
break
}
$count++
}
if ($null -eq $directUrl) {
Write-JLog -Level Warning -Message "Search [$Id] not matched on Jav321"
return
} else {
Write-Output $directUrl
}
} else {
Write-JLog -Level Warning -Message "Search [$Id] not matched on Jav321"
return
}
}
}