Skip to content

Commit

Permalink
Fix Javbus url scraper for uncensored (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvlflame committed Oct 11, 2020
1 parent b5720a9 commit 1829215
Showing 1 changed file with 112 additions and 27 deletions.
139 changes: 112 additions & 27 deletions src/Javinizer/Public/Get-JavbusUrl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,14 @@ function Get-JavbusUrl {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Performing [GET] on URL [$searchUrl]"
$webRequest = Invoke-RestMethod -Uri $searchUrl -Method Get -Verbose:$false
} catch {
try {
$searchUrl = "https://www.javbus.com/uncensored/search/$Id&type=0&parent=uc"
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Performing [GET] on URL [$searchUrl]"
$webRequest = Invoke-RestMethod -Uri $searchUrl -Method Get -Verbose:$false
} catch {
try {
$searchUrl = "https://www.javbus.org/search/$Id&type=0&parent=uc"
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Performing [GET] on URL [$searchUrl]"
$webRequest = Invoke-RestMethod -Uri $searchUrl -Method Get -Verbose:$false
} catch {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Warning -Message "[$Id] [$($MyInvocation.MyCommand.Name)] not matched on JavBus"
return
}
}
}

$Tries = 5
# Get the page search results
try {
$searchResults = (($webRequest | ForEach-Object { $_ -split '\n' } | Select-String '<a class="movie-box" href="(.*)">').Matches) | ForEach-Object { $_.Groups[1].Value }
} catch {
return
$searchResults = $null
}
$numResults = $searchResults.Count

Expand All @@ -52,37 +38,136 @@ function Get-JavbusUrl {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Performing [GET] on URL [$result]"
$webRequest = Invoke-RestMethod -Uri $result -Method Get -Verbose:$false
} catch {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Error -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Error occurred on [GET] on URL [$result]: $PSItem" -Action 'Continue'
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Error -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Error occurred on [GET] on URL [$result]" -Action 'Continue'
}
$resultId = Get-JavbusId -WebRequest $webRequest
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "Result [$count] is [$resultId]"
if ($resultId -eq $Id) {
$directUrlZh = "https://" + ($result -split '/')[-2] + "/" + ($result -split '/')[-1]
$directUrlJa = "https://" + ($result -split '/')[-2] + "/ja/" + ($result -split '/')[-1]
$directUrl = "https://" + ($result -split '/')[-2] + "/en/" + ($result -split '/')[-1]
break
}

Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "Result [$count] is [$resultId]"

if ($count -eq $Tries) {
break
}

$count++
}
}

if ($null -eq $directUrl) {
try {
$searchUrl = "https://www.javbus.com/uncensored/search/$Id&type=0&parent=uc"
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Performing [GET] on URL [$searchUrl]"
$webRequest = Invoke-RestMethod -Uri $searchUrl -Method Get -Verbose:$false
} catch {
}

$Tries = 5
# Get the page search results
try {
$searchResults = (($webRequest | ForEach-Object { $_ -split '\n' } | Select-String '<a class="movie-box" href="(.*)">').Matches) | ForEach-Object { $_.Groups[1].Value }
} catch {
$searchResults = $null
}
$numResults = $searchResults.Count

if ($Tries -gt $numResults) {
$Tries = $numResults
}

if ($null -eq $directUrl) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Warning -Message "[$Id] [$($MyInvocation.MyCommand.Name)] not matched on JavBus"
return
} else {
$urlObject = [PSCustomObject]@{
En = $directUrl
Ja = $directUrlJa
Zh = $directUrlZh
if ($numResults -ge 1) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching [$Tries] of [$numResults] results for [$Id]"

$count = 1
foreach ($result in $searchResults) {
try {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Performing [GET] on URL [$result]"
$webRequest = Invoke-RestMethod -Uri $result -Method Get -Verbose:$false
} catch {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Error -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Error occurred on [GET] on URL [$result]" -Action 'Continue'
}
$resultId = Get-JavbusId -WebRequest $webRequest
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "Result [$count] is [$resultId]"
if ($resultId -eq $Id) {
$directUrlZh = "https://" + ($result -split '/')[-2] + "/" + ($result -split '/')[-1]
$directUrlJa = "https://" + ($result -split '/')[-2] + "/ja/" + ($result -split '/')[-1]
$directUrl = "https://" + ($result -split '/')[-2] + "/en/" + ($result -split '/')[-1]
break
}

if ($count -eq $Tries) {
break
}

$count++
}
}
}

if ($null -eq $directUrl) {
try {
$searchUrl = "https://www.javbus.org/search/$Id&type=0&parent=uc"
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Performing [GET] on URL [$searchUrl]"
$webRequest = Invoke-RestMethod -Uri $searchUrl -Method Get -Verbose:$false
} catch {
}

$Tries = 5
# Get the page search results
try {
$searchResults = (($webRequest | ForEach-Object { $_ -split '\n' } | Select-String '<a class="movie-box" href="(.*)">').Matches) | ForEach-Object { $_.Groups[1].Value }
} catch {
$searchResults = $null
}
$numResults = $searchResults.Count

if ($Tries -gt $numResults) {
$Tries = $numResults
}

if ($numResults -ge 1) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Searching [$Tries] of [$numResults] results for [$Id]"

$count = 1
foreach ($result in $searchResults) {
try {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Performing [GET] on URL [$result]"
$webRequest = Invoke-RestMethod -Uri $result -Method Get -Verbose:$false
} catch {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Error -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Error occurred on [GET] on URL [$result]: $PSItem" -Action 'Continue'
}
$resultId = Get-JavbusId -WebRequest $webRequest
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "Result [$count] is [$resultId]"
if ($resultId -eq $Id) {
$directUrlZh = "https://" + ($result -split '/')[-2] + "/" + ($result -split '/')[-1]
$directUrlJa = "https://" + ($result -split '/')[-2] + "/ja/" + ($result -split '/')[-1]
$directUrl = "https://" + ($result -split '/')[-2] + "/en/" + ($result -split '/')[-1]
break
}

if ($count -eq $Tries) {
break
}

$count++
}
}
}

Write-Output $urlObject
if ($null -eq $directUrl) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Warning -Message "[$Id] [$($MyInvocation.MyCommand.Name)] not matched on JavBus"
return
} else {
$urlObject = [PSCustomObject]@{
En = $directUrl
Ja = $directUrlJa
Zh = $directUrlZh
}

Write-Output $urlObject
}
}
}

0 comments on commit 1829215

Please sign in to comment.