Skip to content

Commit

Permalink
Fix mgstage url scraper on not found
Browse files Browse the repository at this point in the history
  • Loading branch information
jvlflame committed Dec 13, 2020
1 parent d94a362 commit 6687804
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Javinizer/Public/Get-MgstageUrl.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,23 @@ function Get-MgstageUrl {
$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 [$directUrl]"
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-WebRequest -Uri $result -WebSession:$Session -UserAgent:$Session.UserAgent -Method Get -Verbose:$false
} catch {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Error -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Error occured on [GET] on URL [$directUrl]: $PSItem" -Action 'Continue'
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Error -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Error occured on [GET] on URL [$result]: $PSItem" -Action 'Continue'
}

$resultId = Get-MgstageId -WebRequest $webRequest

try {
$alternateResultId = ($resultId | Select-String -Pattern '\d*(.*)').Matches.Groups[1].Value
} catch {
return
}

Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Debug -Message "[$Id] [$($MyInvocation.MyCommand.Name)] Result [$count] is [$resultId]"

if ($resultId -eq $Id) {
if ($resultId -eq $Id -or $alternateResultId -eq $Id) {
$mgstageUrlJa = $result
break
}
Expand All @@ -68,7 +75,7 @@ function Get-MgstageUrl {
}
}

if ($null -eq $searchResults) {
if ($null -eq $mgstageUrlJa) {
Write-JVLog -Write:$script:JVLogWrite -LogPath $script:JVLogPath -WriteLevel $script:JVLogWriteLevel -Level Warning -Message "[$Id] [$($MyInvocation.MyCommand.Name)] not matched on Mgstage"
return
} else {
Expand Down

0 comments on commit 6687804

Please sign in to comment.