diff --git a/src/Javinizer/Private/Get-DmmDataObject.ps1 b/src/Javinizer/Private/Get-DmmDataObject.ps1 index f05ef387..a77e0667 100644 --- a/src/Javinizer/Private/Get-DmmDataObject.ps1 +++ b/src/Javinizer/Private/Get-DmmDataObject.ps1 @@ -1,79 +1,51 @@ function Get-DmmDataObject { [CmdletBinding()] - [OutputType([pscustomobject])] param ( - [Parameter(Position = 0)] - [string]$Name, - [Parameter(Position = 1)] - [string]$Url, - [string]$AltName + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] + [string]$Url ) - begin { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function started" + process { $movieDataObject = @() - } + $dmmUrl = $Url - process { - if ($Url) { - $dmmUrl = $Url - } else { - # ! Current limitation: relies on the video being available on R18.com to generate the DMM link - $r18Url = Get-R18Url -Name $Name -AltName $AltName - if ($null -eq $r18Url) { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Search [$Name] not matched; Skipping..." - Write-Verbose "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Search [$Name] not matched on Dmm" - return - } - $r18Id = (($r18Url -split 'id=')[1] -split '\/')[0] - $dmmUrl = 'https://www.dmm.co.jp/digital/videoa/-/detail/=/cid=' + $r18Id - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] R18 ID is: $r18Id" - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] DMM url is: $dmmUrl" + try { + Write-JLog -Level Debug -Message "Performing [GET] on URL [$dmmUrl]" + $webRequest = Invoke-WebRequest -Uri $dmmUrl -Method Get -Verbose:$false + } catch { + Write-JLog -Level Error -Message "Error [GET] on URL [$dmmUrl]: $PSItem" } - if ($null -ne $dmmUrl) { - try { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$dmmUrl]" - $webRequest = Invoke-WebRequest -Uri $dmmUrl -Method Get -Verbose:$false - } catch { - throw $_ - } - - $movieDataObject = [pscustomobject]@{ - Source = 'dmm' - Url = $dmmUrl - ContentId = Get-DmmContentId -WebRequest $webRequest - Title = Get-DmmTitle -WebRequest $webRequest - Description = Get-DmmDescription -WebRequest $webRequest - Date = Get-DmmReleaseDate -WebRequest $webRequest - Year = Get-DmmReleaseYear -WebRequest $webRequest - Runtime = Get-DmmRuntime -WebRequest $webRequest - Director = Get-DmmDirector -WebRequest $webRequest - Maker = Get-DmmMaker -WebRequest $webRequest - Label = Get-DmmLabel -WebRequest $webRequest - Series = Get-DmmSeries -WebRequest $webRequest - Rating = Get-DmmRating -WebRequest $webRequest - RatingCount = Get-DmmRatingCount -WebRequest $webRequest - Actress = Get-DmmActress -WebRequest $webRequest - Genre = Get-DmmGenre -WebRequest $webRequest - CoverUrl = Get-DmmCoverUrl -WebRequest $webRequest - ScreenshotUrl = Get-DmmScreenshotUrl -WebRequest $webRequest - #TrailerUrl = Get-DmmTrailerUrl -WebRequest $webRequest - } + $movieDataObject = [pscustomobject]@{ + Source = 'dmm' + Url = $dmmUrl + ContentId = Get-DmmContentId -WebRequest $webRequest + Title = Get-DmmTitle -WebRequest $webRequest + Description = Get-DmmDescription -WebRequest $webRequest + Date = Get-DmmReleaseDate -WebRequest $webRequest + Year = Get-DmmReleaseYear -WebRequest $webRequest + Runtime = Get-DmmRuntime -WebRequest $webRequest + Director = Get-DmmDirector -WebRequest $webRequest + Maker = Get-DmmMaker -WebRequest $webRequest + Label = Get-DmmLabel -WebRequest $webRequest + Series = Get-DmmSeries -WebRequest $webRequest + Rating = Get-DmmRating -WebRequest $webRequest + RatingCount = Get-DmmRatingCount -WebRequest $webRequest + Actress = Get-DmmActress -WebRequest $webRequest + Genre = Get-DmmGenre -WebRequest $webRequest + CoverUrl = Get-DmmCoverUrl -WebRequest $webRequest + ScreenshotUrl = Get-DmmScreenshotUrl -WebRequest $webRequest + #TrailerUrl = Get-DmmTrailerUrl -WebRequest $webRequest } - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] DMM data object:" - $movieDataObject | Format-List | Out-String | Write-Debug + Write-JLog -Level Debug -Message "DMM data object: $($movieDataObject | ConvertTo-Json -Depth 32 -Compress)" Write-Output $movieDataObject } - - end { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function ended" - } } function Get-DmmContentId { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -86,6 +58,7 @@ function Get-DmmContentId { function Get-DmmTitle { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -98,6 +71,7 @@ function Get-DmmTitle { function Get-DmmDescription { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -118,6 +92,7 @@ function Get-DmmDescription { function Get-DmmReleaseDate { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -132,6 +107,7 @@ function Get-DmmReleaseDate { function Get-DmmReleaseYear { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -144,6 +120,7 @@ function Get-DmmReleaseYear { function Get-DmmRuntime { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -156,6 +133,7 @@ function Get-DmmRuntime { function Get-DmmDirector { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -173,6 +151,7 @@ function Get-DmmDirector { function Get-DmmMaker { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -185,6 +164,7 @@ function Get-DmmMaker { function Get-DmmLabel { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -202,6 +182,7 @@ function Get-DmmLabel { function Get-DmmSeries { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -219,6 +200,7 @@ function Get-DmmSeries { function Get-DmmRating { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -238,6 +220,7 @@ function Get-DmmRating { function Get-DmmRatingCount { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -250,14 +233,12 @@ function Get-DmmRatingCount { function Get-DmmActress { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) - begin { - $actressArray = @() - } - process { + $actressArray = @() $actressHtml = ((($WebRequest.Content -split '出演者:<\/td>')[1] -split '<\/td>')[0] -split '')[1] $actressHtml = $actressHtml -replace '', '' $actressHtml = $actressHtml -split '<\/a>', '' @@ -279,14 +260,12 @@ function Get-DmmActress { function Get-DmmGenre { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) - begin { - $genreArray = @() - } - process { + $genreArray = @() $genre = (((($WebRequest.Content -split 'ジャンル:<\/td>')[1] -split '<\/td>')[0] -split '')[1] -split '">') $genre = ($genre -replace '<\/a>', '') -replace '  ', '' $genre = $genre -replace ' [$directUrl]" + } else { + # Convert the movie Id (ID-###) to content Id (ID00###) to match dmm naming standards + if ($Id -match '([a-zA-Z|tT28|rR18]+-\d+z{0,1}Z{0,1}e{0,1}E{0,1})') { + $splitId = $Id -split '-' + $Id = $splitId[0] + $splitId[1].PadLeft(5, '0') + } + + $searchUrl = "https://www.dmm.co.jp/search/?redirect=1&enc=UTF-8&category=&searchstr=$Id" + + try { + Write-JLog -Level Debug -Message "Performing [GET] on URL [$searchUrl]" + $webRequest = Invoke-WebRequest -Uri $searchUrl -Method Get -Verbose:$false + } catch { + Write-JLog -Level Error -Message "Error [GET] on URL [$searchUrl]" + } + + $retryCount = 5 + $searchResults = ($webrequest.links.href | Where-Object { $_ -like '*digital/videoa/*' }) + $numResults = $searchResults.count + + if ($retryCount -gt $numResults) { + $retryCount = $numResults + } + + if ($numResults -ge 1) { + Write-JLog -Level Debug -Message "Searching [$retryCount] of [$numResults] results for [$Id]" + + $count = 1 + foreach ($result in $searchResults) { + try { + Write-JLog -Level Debug -Message "Performing [GET] on URL [$result]" + $webRequest = Invoke-WebRequest -Uri $result -Method Get -Verbose:$false + } catch { + Write-JLog -Level Error -Message "Error [GET] on URL [$result]: $PSItem" + } + + $resultId = Get-DmmContentId -WebRequest $webRequest + Write-JLog -Level Debug -Message "Result [$count] is [$resultId]" + if ($resultId -match $Id) { + $directUrl = $result + break + } + + if ($count -eq $retryCount) { + break + } + + $count++ + } + } + } + + Write-Output $directUrl + } +} diff --git a/src/Javinizer/Private/Get-Jav321DataObject.ps1 b/src/Javinizer/Private/Get-Jav321DataObject.ps1 index ce493d6e..09c86b0d 100644 --- a/src/Javinizer/Private/Get-Jav321DataObject.ps1 +++ b/src/Javinizer/Private/Get-Jav321DataObject.ps1 @@ -1,71 +1,51 @@ function Get-Jav321DataObject { [CmdletBinding()] - [OutputType([pscustomobject])] param ( - [Parameter(Position = 0)] - [string]$Name, - [Parameter(Position = 1)] + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [string]$Url ) - begin { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function started" - $movieDataObject = @() - } - process { - if ($Url) { - $jav321Url = $Url - } else { - $jav321Url = Get-Jav321Url -Name $Name - } + $movieDataObject = @() - if ($null -ne $jav321Url) { try { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$jav321Url]" - $webRequest = Invoke-RestMethod -Uri $jav321Url -Verbose:$false - $movieDataObject = [pscustomobject]@{ - Source = 'jav321' - Url = $jav321Url - Id = Get-Jav321Id -WebRequest $webRequest - Title = Get-Jav321Title -WebRequest $webRequest - Date = Get-Jav321ReleaseDate -WebRequest $webRequest - Year = Get-Jav321ReleaseYear -WebRequest $webRequest - Runtime = Get-Jav321Runtime -WebRequest $webRequest - Maker = Get-Jav321Maker -WebRequest $webRequest - Actress = (Get-Jav321Actress -WebRequest $webRequest).Name - ActressThumbUrl = (Get-Jav321Actress -WebRequest $webRequest).ThumbUrl - Genre = Get-Jav321Genre -WebRequest $webRequest - CoverUrl = Get-Jav321CoverUrl -WebRequest $webRequest - ScreenshotUrl = Get-Jav321ScreenshotUrl -WebRequest $webRequest - } + Write-JLog -Level Debug -Message "Performing [GET] on URL [$Url]" + $webRequest = Invoke-RestMethod -Uri $Url -Verbose:$false } catch { - throw $_ + Write-JLog -Level Error -Message "Error [GET] on URL [$Url]: $PSItem" } - } else { - Write-Verbose "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Search [$Name] not matched on jav321" - return - } - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] jav321 data object:" - $movieDataObject | Format-List | Out-String | Write-Debug - Write-Output $movieDataObject - } + $movieDataObject = [pscustomobject]@{ + Source = 'jav321' + Url = $Url + Id = Get-Jav321Id -WebRequest $webRequest + Title = Get-Jav321Title -WebRequest $webRequest + Date = Get-Jav321ReleaseDate -WebRequest $webRequest + Year = Get-Jav321ReleaseYear -WebRequest $webRequest + Runtime = Get-Jav321Runtime -WebRequest $webRequest + Maker = Get-Jav321Maker -WebRequest $webRequest + Actress = (Get-Jav321Actress -WebRequest $webRequest).Name + ActressThumbUrl = (Get-Jav321Actress -WebRequest $webRequest).ThumbUrl + Genre = Get-Jav321Genre -WebRequest $webRequest + CoverUrl = Get-Jav321CoverUrl -WebRequest $webRequest + ScreenshotUrl = Get-Jav321ScreenshotUrl -WebRequest $webRequest + } - end { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function ended" + Write-JLog -Level Debug -Message "Jav321 data object: $($movieDataObject | ConvertTo-Json -Depth 32 -Compress)" + Write-Output $movieDataObject } } function Get-Jav321Id { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) process { try { - $id = ((($WebRequest | ForEach-Object { $_ -split '\n' } | - Select-String '品番<\/b>: (.*)
').Matches.Groups[1].Value -split '
')[0]).ToUpper() + $id = ((($WebRequest | ForEach-Object { $_ -split '\n' } | + Select-String '品番<\/b>: (.*)
').Matches.Groups[1].Value -split '
')[0]).ToUpper() } catch { return } @@ -76,12 +56,14 @@ function Get-Jav321Id { function Get-Jav321Title { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) + process { try { - $title = ($WebRequest | ForEach-Object { $_ -split '\n' } | - Select-String '

(.*) ').Matches.Groups[1].Value + $title = ($WebRequest | ForEach-Object { $_ -split '\n' } | + Select-String '

(.*) ').Matches.Groups[1].Value } catch { return } @@ -93,13 +75,14 @@ function Get-Jav321Title { function Get-Jav321ReleaseDate { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) process { try { - $releaseDate = ($WebRequest | ForEach-Object { $_ -split '\n' } | - Select-String '(.*)<\/b>: (\d{4}-\d{2}-\d{2})
').Matches.Groups[2].Value + $releaseDate = ($WebRequest | ForEach-Object { $_ -split '\n' } | + Select-String '(.*)<\/b>: (\d{4}-\d{2}-\d{2})
').Matches.Groups[2].Value } catch { return } @@ -110,6 +93,7 @@ function Get-Jav321ReleaseDate { function Get-Jav321ReleaseYear { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -127,13 +111,14 @@ function Get-Jav321ReleaseYear { function Get-Jav321Runtime { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) process { try { - $length = ($WebRequest | ForEach-Object { $_ -split '\n' } | - Select-String '(.*)<\/b>: (\d{1,3}) minutes
').Matches.Groups[2].Value + $length = ($WebRequest | ForEach-Object { $_ -split '\n' } | + Select-String '(.*)<\/b>: (\d{1,3}) minutes
').Matches.Groups[2].Value } catch { return } @@ -144,6 +129,7 @@ function Get-Jav321Runtime { function Get-Jav321Maker { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -162,18 +148,17 @@ function Get-Jav321Maker { function Get-Jav321Genre { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) - begin { + process { $genre = @() - } - process { try { $genre = ($WebRequest | ForEach-Object { $_ -split '\n' } | Select-String '
(.*)<\/a> ').Matches.Groups[0] -split '<\/a>' | - ForEach-Object { ($_ -split '>')[1] } + ForEach-Object { ($_ -split '>')[1] } } catch { return } @@ -184,24 +169,23 @@ function Get-Jav321Genre { function Get-Jav321Actress { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) - begin { + process { $actress = @() - } - process { try { $actress = ($WebRequest | ForEach-Object { $_ -split '\n' } | Select-String '(.*)<\/a>によって行われる<\/div>').Matches | - ForEach-Object { $_.Groups[3].Value } | - Where-Object { $_ -ne '' } + ForEach-Object { $_.Groups[3].Value } | + Where-Object { $_ -ne '' } $actressThumb = ($WebRequest | ForEach-Object { $_ -split '\n' } | Select-String '
').Matches.Groups[1].Value) + '.jpg' + Select-String -Pattern 'poster="(.*).jpg">').Matches.Groups[1].Value) + '.jpg' } catch { return } @@ -235,25 +220,24 @@ function Get-Jav321CoverUrl { function Get-Jav321ScreenshotUrl { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) - begin { + process { $screenshotUrl = @() - } - process { try { $screenshotUrl = (($WebRequest | ForEach-Object { $_ -split '\n' } | - Select-String -Pattern '").Matches | - ForEach-Object { $_.Groups[1].Value } + Select-String -Pattern '").Matches | + ForEach-Object { $_.Groups[1].Value } } catch { try { $screenshotUrl = (($WebRequest | ForEach-Object { $_ -split '\n' } | - Select-String -Pattern '<\/a><\/p>').Matches | - ForEach-Object { $_.Groups[1].Value } + ForEach-Object { $_.Groups[1].Value } } catch { return } diff --git a/src/Javinizer/Private/Get-Jav321Url.ps1 b/src/Javinizer/Private/Get-Jav321Url.ps1 index 51f13003..5febccdf 100644 --- a/src/Javinizer/Private/Get-Jav321Url.ps1 +++ b/src/Javinizer/Private/Get-Jav321Url.ps1 @@ -1,20 +1,18 @@ function Get-Jav321Url { [CmdletBinding()] param ( - [Parameter(Mandatory = $true, Position = 0)] - [string]$Name + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] + [string]$Id ) - begin { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function started" + process { $searchUrl = "https://jp.jav321.com/search" - } - process { try { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$searchUrl]" - $webRequest = Invoke-WebRequest -Uri $searchUrl -Method Post -Body "sn=$Name" -Verbose:$false + 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 } @@ -22,9 +20,9 @@ function Get-Jav321Url { $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 + Select-String -Pattern 'jav321.com/video/(.*)" target' | + ForEach-Object { $_.Matches.Groups[1].Value } | + Select-Object -Unique $numResults = $searchResults.Count @@ -33,21 +31,25 @@ function Get-Jav321Url { } if ($numResults -ge 1) { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Searching [$Tries] of [$numResults] results for [$Name]" + 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" - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$result]" - $webRequest = Invoke-RestMethod -Uri $result -Method Get -Verbose:$false + 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 $Name) { + if ($resultId -eq $Id) { $directUrl = $result break } - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Result [$count] is [$resultId]" - + Write-JLog -Level Debug -Message "Result [$count] is [$resultId]" if ($count -eq $Tries) { break } @@ -56,15 +58,14 @@ function Get-Jav321Url { } if ($null -eq $directUrl) { - Write-Verbose "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Search [$Name] not matched on Jav321" + Write-JLog -Level Warning -Message "Search [$Id] not matched on Jav321" return } else { Write-Output $directUrl } } else { - Write-Verbose "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Search [$Name] not matched on Jav321" + Write-JLog -Level Warning -Message "Search [$Id] not matched on Jav321" return } } } - diff --git a/src/Javinizer/Private/Get-JavbusDataObject.ps1 b/src/Javinizer/Private/Get-JavbusDataObject.ps1 index 0e7132b4..43c60e7a 100644 --- a/src/Javinizer/Private/Get-JavbusDataObject.ps1 +++ b/src/Javinizer/Private/Get-JavbusDataObject.ps1 @@ -1,80 +1,56 @@ function Get-JavbusDataObject { [CmdletBinding()] - [OutputType([pscustomobject])] param ( - [Parameter(Position = 0)] - [string]$Name, - [Parameter(Position = 1)] - [string]$Url, - [switch]$Ja + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] + [string]$Url ) - begin { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function started" + process { $movieDataObject = @() - } - process { - if ($Url) { - $javbusUrl = $Url - } else { - if ($Ja.IsPresent) { - $javbusUrl = Get-JavbusUrl -Name $Name -Language 'ja' - } else { - $javbusUrl = Get-JavbusUrl -Name $Name -Language 'en' - } + + try { + Write-JLog -Level Debug -Message "Performing [GET] on URL [$Url]" + $webRequest = Invoke-RestMethod -Uri $Url -Verbose:$false + } catch { + Write-JLog -Level Error -Message "Error [GET] on URL [$Url]: $PSItem" } - if ($null -ne $javbusUrl) { - try { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$javbusUrl]" - $webRequest = Invoke-RestMethod -Uri $javbusUrl -Verbose:$false - $movieDataObject = [pscustomobject]@{ - Source = 'javbus' - Url = $javbusUrl - Id = Get-JavbusId -WebRequest $webRequest - Title = Get-JavbusTitle -WebRequest $webRequest - Date = Get-JavbusReleaseDate -WebRequest $webRequest - Year = Get-JavbusReleaseYear -WebRequest $webRequest - Runtime = Get-JavbusRuntime -WebRequest $webRequest - Director = Get-JavbusDirector -WebRequest $webRequest - Maker = Get-JavbusMaker -WebRequest $webRequest - Label = Get-JavbusLabel -WebRequest $webRequest - Series = Get-JavbusSeries -WebRequest $webRequest - Rating = Get-JavbusRating -WebRequest $webRequest - Actress = (Get-JavbusActress -WebRequest $webRequest).Name - ActressThumbUrl = (Get-JavbusActress -WebRequest $webRequest).ThumbUrl - Genre = Get-JavbusGenre -WebRequest $webRequest - CoverUrl = Get-JavbusCoverUrl -WebRequest $webRequest - ScreenshotUrl = Get-JavbusScreenshotUrl -WebRequest $webRequest - } - } catch { - throw $_ - } - } else { - Write-Verbose "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Search [$Name] not matched on Javbus" - return + $movieDataObject = [pscustomobject]@{ + Source = 'javbus' + Url = $Url + Id = Get-JavbusId -WebRequest $webRequest + Title = Get-JavbusTitle -WebRequest $webRequest + Date = Get-JavbusReleaseDate -WebRequest $webRequest + Year = Get-JavbusReleaseYear -WebRequest $webRequest + Runtime = Get-JavbusRuntime -WebRequest $webRequest + Director = Get-JavbusDirector -WebRequest $webRequest + Maker = Get-JavbusMaker -WebRequest $webRequest + Label = Get-JavbusLabel -WebRequest $webRequest + Series = Get-JavbusSeries -WebRequest $webRequest + Rating = Get-JavbusRating -WebRequest $webRequest + Actress = (Get-JavbusActress -WebRequest $webRequest).Name + ActressThumbUrl = (Get-JavbusActress -WebRequest $webRequest).ThumbUrl + Genre = Get-JavbusGenre -WebRequest $webRequest + CoverUrl = Get-JavbusCoverUrl -WebRequest $webRequest + ScreenshotUrl = Get-JavbusScreenshotUrl -WebRequest $webRequest } - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] JavBus data object:" - $movieDataObject | Format-List | Out-String | Write-Debug + Write-JLog -Level Debug -Message "JavBus data object: $($movieDataObject | ConvertTo-Json -Depth 32 -Compress)" Write-Output $movieDataObject } - - end { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function ended" - } } function Get-JavbusId { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) process { try { - $id = ($WebRequest | ForEach-Object { $_ -split '\n' } | - Select-String '(.*?) (.*?) - JavBus<\/title>').Matches.Groups[1].Value + $id = ($WebRequest | ForEach-Object { $_ -split '\n' } | + Select-String '<title>(.*?) (.*?) - JavBus<\/title>').Matches.Groups[1].Value } catch { return } @@ -85,12 +61,13 @@ function Get-JavbusId { function Get-JavbusTitle { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) process { try { - $title = ($WebRequest | ForEach-Object { $_ -split '\n' } | - Select-String '<title>(.*?) (.*?) - JavBus<\/title>').Matches.Groups[2].Value + $title = ($WebRequest | ForEach-Object { $_ -split '\n' } | + Select-String '<title>(.*?) (.*?) - JavBus<\/title>').Matches.Groups[2].Value } catch { return @@ -103,13 +80,14 @@ function Get-JavbusTitle { function Get-JavbusReleaseDate { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) process { try { - $releaseDate = ($WebRequest | ForEach-Object { $_ -split '\n' } | - Select-String '<p><span class="header">(.*):<\/span> (\d{4}-\d{2}-\d{2})<\/p>').Matches.Groups[2].Value + $releaseDate = ($WebRequest | ForEach-Object { $_ -split '\n' } | + Select-String '<p><span class="header">(.*):<\/span> (\d{4}-\d{2}-\d{2})<\/p>').Matches.Groups[2].Value } catch { return } @@ -120,6 +98,7 @@ function Get-JavbusReleaseDate { function Get-JavbusReleaseYear { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -137,13 +116,14 @@ function Get-JavbusReleaseYear { function Get-JavbusRuntime { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) process { try { - $length = ($WebRequest | ForEach-Object { $_ -split '\n' } | - Select-String '<p><span class="header">(.*):<\/span> (\d{1,3})(.*)<\/p>').Matches[1].Groups[2].Value + $length = ($WebRequest | ForEach-Object { $_ -split '\n' } | + Select-String '<p><span class="header">(.*):<\/span> (\d{1,3})(.*)<\/p>').Matches[1].Groups[2].Value } catch { return } @@ -154,13 +134,14 @@ function Get-JavbusRuntime { function Get-JavbusDirector { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) process { try { $director = ($WebRequest | ForEach-Object { $_ -split '\n' } | - Select-String -Pattern '<p><span class="header">(.*)<\/span> <a href="https:\/\/www\.javbus\.(com|org)\/(.*)\/director\/(.*)">(.*)<\/a><\/p>').Matches.Groups[5].Value + Select-String -Pattern '<p><span class="header">(.*)<\/span> <a href="https:\/\/www\.javbus\.(com|org)\/(.*)\/director\/(.*)">(.*)<\/a><\/p>').Matches.Groups[5].Value } catch { return } @@ -174,6 +155,7 @@ function Get-JavbusDirector { function Get-JavbusMaker { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -192,6 +174,7 @@ function Get-JavbusMaker { function Get-JavbusLabel { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -210,12 +193,13 @@ function Get-JavbusLabel { function Get-JavbusSeries { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) process { try { - $series = ($WebRequest | ForEach-Object { $_ -split '\n'} | + $series = ($WebRequest | ForEach-Object { $_ -split '\n' } | Select-String -Pattern '<p><span class="header">(.*)<\/span> <a href="https:\/\/www.javbus.(com|org)/(.*)/series/(.*)">(.*)<\/a>').Matches.Groups[5].Value } catch { return @@ -228,6 +212,7 @@ function Get-JavbusSeries { function Get-JavbusRating { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -238,18 +223,16 @@ function Get-JavbusRating { function Get-JavbusGenre { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) - begin { - $genre = @() - } - process { + $genre = @() try { $genre = ($WebRequest | ForEach-Object { $_ -split '\n' } | Select-String '<span class="genre"><a href="(.*)\/genre\/(.*)">(.*)<\/a><\/span>').Matches | - ForEach-Object { $_.Groups[3].Value } + ForEach-Object { $_.Groups[3].Value } } catch { return } @@ -260,25 +243,24 @@ function Get-JavbusGenre { function Get-JavbusActress { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) - begin { + process { $actress = @() - } - process { try { $actress = ($WebRequest | ForEach-Object { $_ -split '\n' } | Select-String '<a href="(.*)\/star\/(.*)">(.*)<\/a>').Matches | - ForEach-Object { $_.Groups[3].Value } | - Where-Object { $_ -ne '' } | - Select-Object -Unique + ForEach-Object { $_.Groups[3].Value } | + Where-Object { $_ -ne '' } | + Select-Object -Unique $actressThumb = ($WebRequest | ForEach-Object { $_ -split '\n' } | Select-String '<a href="(.*)\/star\/(.*)"><img src="(.*)" title="(.*)"><\/a>').Matches | - ForEach-Object { $_.Groups[3].Value} | - Where-Object { $_ -ne ''} + ForEach-Object { $_.Groups[3].Value } | + Where-Object { $_ -ne '' } $movieActressObject = [pscustomobject]@{ @@ -295,6 +277,7 @@ function Get-JavbusActress { function Get-JavbusCoverUrl { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -312,19 +295,18 @@ function Get-JavbusCoverUrl { function Get-JavbusScreenshotUrl { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) - begin { + process { $screenshotUrl = @() - } - process { try { $screenshotUrl = (($WebRequest | ForEach-Object { $_ -split '\n' } | - Select-String -Pattern 'href="(https:\/\/images\.javbus\.(com|org)\/bigsample\/(.*))">') -split '<a class="sample-box"' | - Select-String -Pattern '(https:\/\/images\.javbus\.(com|org)\/bigsample\/(.*).jpg)">').Matches | - ForEach-Object { $_.Groups[1].Value } + Select-String -Pattern 'href="(https:\/\/images\.javbus\.(com|org)\/bigsample\/(.*))">') -split '<a class="sample-box"' | + Select-String -Pattern '(https:\/\/images\.javbus\.(com|org)\/bigsample\/(.*).jpg)">').Matches | + ForEach-Object { $_.Groups[1].Value } } catch { return } diff --git a/src/Javinizer/Private/Get-JavbusUrl.ps1 b/src/Javinizer/Private/Get-JavbusUrl.ps1 index 9eb4d0a8..298c987c 100644 --- a/src/Javinizer/Private/Get-JavbusUrl.ps1 +++ b/src/Javinizer/Private/Get-JavbusUrl.ps1 @@ -1,30 +1,31 @@ function Get-JavbusUrl { [CmdletBinding()] param ( - [Parameter(Mandatory = $true, Position = 0)] - [string]$Name, + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] + [string]$Id, + [Parameter(Mandatory = $true)] + [ValidateSet('ja', 'en', 'zh')] [string]$Language ) - begin { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function started" - $searchUrl = "https://www.javbus.com/search/$Name&type=0&parent=uc" - } - process { + $searchUrl = "https://www.javbus.com/search/$Id&type=0&parent=uc" + try { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$searchUrl]" + Write-JLog -Level Debug -Message "Performing [GET] on URL [$searchUrl]" $webRequest = Invoke-RestMethod -Uri $searchUrl -Method Get -Verbose:$false } catch { try { - $searchUrl = "https://www.javbus.com/uncensored/search/$Name&type=0&parent=uc" + $searchUrl = "https://www.javbus.com/uncensored/search/$Id&type=0&parent=uc" + Write-JLog -Level Debug -Message "Performing [GET] on URL [$searchUrl]" $webRequest = Invoke-RestMethod -Uri $searchUrl -Method Get -Verbose:$false } catch { try { - $searchUrl = "https://www.javbus.org/search/$Name&type=0&parent=uc" + $searchUrl = "https://www.javbus.org/search/$Id&type=0&parent=uc" + Write-JLog -Level Debug -Message "Performing [GET] on URL [$searchUrl]" $webRequest = Invoke-RestMethod -Uri $searchUrl -Method Get -Verbose:$false } catch { - Write-Verbose "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Search [$Name] not matched on JavBus" + Write-JLog -Level Warning -Message "Search [$Id] not matched on JavBus" return } } @@ -40,19 +41,27 @@ function Get-JavbusUrl { } if ($numResults -ge 1) { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Searching [$Tries] of [$numResults] results for [$Name]" + Write-JLog -Level Debug -Message "Searching [$Tries] of [$numResults] results for [$Id]" $count = 1 foreach ($result in $searchResults) { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$result]" - $webRequest = Invoke-RestMethod -Uri $result -Method Get -Verbose:$false + 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-JavbusId -WebRequest $webRequest - if ($resultId -eq $Name) { - $directUrl = "https://" + ($result -split '/')[-2]+ "/$Language/" + ($result -split '/')[-1] + if ($resultId -eq $Id) { + if ($Language -eq 'zh') { + $directUrl = "https://" + ($result -split '/')[-2] + "/" + ($result -split '/')[-1] + } else { + $directUrl = "https://" + ($result -split '/')[-2] + "/$Language/" + ($result -split '/')[-1] + } break } - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Result [$count] is [$resultId]" + Write-JLog -Level Debug -Message "Result [$count] is [$resultId]" if ($count -eq $Tries) { break @@ -62,7 +71,7 @@ function Get-JavbusUrl { } if ($null -eq $directUrl) { - Write-Verbose "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Search [$Name] not matched on JavBus" + Write-JLog -Level Warning -Message "Search [$Id] not matched on JavBus" return } else { Write-Output $directUrl @@ -70,4 +79,3 @@ function Get-JavbusUrl { } } } - diff --git a/src/Javinizer/Private/Get-JavlibraryDataObject.ps1 b/src/Javinizer/Private/Get-JavlibraryDataObject.ps1 index 8772cbc0..b9dbb667 100644 --- a/src/Javinizer/Private/Get-JavlibraryDataObject.ps1 +++ b/src/Javinizer/Private/Get-JavlibraryDataObject.ps1 @@ -1,82 +1,46 @@ function Get-JavlibraryDataObject { [CmdletBinding()] - [OutputType([pscustomobject])] param ( - [Parameter(Position = 0)] - [string]$Name, - [Parameter(Position = 1)] - [string]$Url, - [string]$ScriptRoot, - [switch]$Zh, - [switch]$Ja + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] + [string]$Url ) - begin { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function started" + process { $movieDataObject = @() - } - process { - if ($Url) { - $javlibraryUrl = $Url - } else { - if ($Zh.IsPresent) { - $javlibraryUrl = Get-JavLibraryUrl -Name $Name -ScriptRoot $ScriptRoot -Zh - } elseif ($Ja.IsPresent) { - $javlibraryUrl = Get-JavLibraryUrl -Name $Name -ScriptRoot $ScriptRoot -Ja - } else { - $javlibraryUrl = Get-JavLibraryUrl -Name $Name -ScriptRoot $ScriptRoot - } + try { + Write-JLog -Level Debug -Message "Performing [GET] on URL [$Url] with Session: [$Session] and UserAgent: [$($Session.UserAgent)]" + $webRequest = Invoke-WebRequest -Uri $Url -Method Get -WebSession $Session -UserAgent $Session.UserAgent -Verbose:$false + } catch { + Write-JLog -Level Error -Message "Error [GET] on URL [$Url]: $PSItem" } - if ($null -ne $javlibraryUrl) { - try { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$javlibraryUrl] with Session: [$Session] and UserAgent: [$($Session.UserAgent)]" - $webRequest = Invoke-WebRequest -Uri $javlibraryUrl -Method Get -WebSession $Session -UserAgent $Session.UserAgent -Verbose:$false - } catch [Microsoft.PowerShell.Commands.HttpResponseException] { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Session to JAVLibrary is unsuccessful, attempting to start a new session with Cloudflare" - try { - New-CloudflareSession -ScriptRoot $ScriptRoot - } catch { - throw $_ - } - - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$javlibraryUrl] with Session: [$Session] and UserAgent: [$($Session.UserAgent)]" - $webRequest = Invoke-WebRequest -Uri $javlibraryUrl -Method Get -WebSession $Session -UserAgent $Session.UserAgent -Verbose:$false - } - - $movieDataObject = [pscustomobject]@{ - Source = 'javlibrary' - Url = $javlibraryUrl - Id = Get-JLId -WebRequest $webRequest - AjaxId = Get-JLAjaxId -WebRequest $webRequest - Title = Get-JLTitle -WebRequest $webRequest - Date = Get-JLReleaseDate -WebRequest $webRequest - Year = Get-JLReleaseYear -WebRequest $webRequest - Runtime = Get-JLRuntime -WebRequest $webRequest - Director = Get-JLDirector -WebRequest $webRequest - Maker = Get-JLMaker -WebRequest $webRequest - Label = Get-JLLabel -WebRequest $webRequest - Rating = Get-JLRating -WebRequest $webRequest - Actress = Get-JLActress -WebRequest $webRequest - Genre = Get-JLGenre -WebRequest $webRequest - CoverUrl = Get-JLCoverUrl -WebRequest $webRequest - ScreenshotUrl = Get-JLScreenshotUrl -WebRequest $webRequest - } + $movieDataObject = [pscustomobject]@{ + Source = 'javlibrary' + Url = $Url + Id = Get-JLId -WebRequest $webRequest + AjaxId = Get-JLAjaxId -WebRequest $webRequest + Title = Get-JLTitle -WebRequest $webRequest + Date = Get-JLReleaseDate -WebRequest $webRequest + Year = Get-JLReleaseYear -WebRequest $webRequest + Runtime = Get-JLRuntime -WebRequest $webRequest + Director = Get-JLDirector -WebRequest $webRequest + Maker = Get-JLMaker -WebRequest $webRequest + Label = Get-JLLabel -WebRequest $webRequest + Rating = Get-JLRating -WebRequest $webRequest + Actress = Get-JLActress -WebRequest $webRequest + Genre = Get-JLGenre -WebRequest $webRequest + CoverUrl = Get-JLCoverUrl -WebRequest $webRequest + ScreenshotUrl = Get-JLScreenshotUrl -WebRequest $webRequest } - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] JAVLibrary data object:" - $movieDataObject | Format-List | Out-String | Write-Debug + Write-JLog -Level Debug -Message "JAVLibrary data object: $($movieDataObject | ConvertTo-Json -Depth 32 -Compress)" Write-Output $movieDataObject } - - end { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function ended" - } } - function Get-JLId { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -88,6 +52,7 @@ function Get-JLId { function Get-JLAjaxId { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -103,9 +68,9 @@ function Get-JLAjaxId { } } -# TODO: Add specific functionality to match video IDs containing trailing alpha characters (e.g. IBW-123z) function Get-JLTitle { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) process { @@ -118,6 +83,7 @@ function Get-JLTitle { function Get-JLReleaseDate { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -129,6 +95,7 @@ function Get-JLReleaseDate { function Get-JLReleaseYear { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -141,6 +108,7 @@ function Get-JLReleaseYear { function Get-JLRuntime { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -152,6 +120,7 @@ function Get-JLRuntime { function Get-JLDirector { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -169,6 +138,7 @@ function Get-JLDirector { function Get-JLMaker { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -181,6 +151,7 @@ function Get-JLMaker { function Get-JLLabel { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -193,6 +164,7 @@ function Get-JLLabel { function Get-JLRating { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -205,14 +177,12 @@ function Get-JLRating { function Get-JLGenre { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) - begin { - $genre = @() - } - process { + $genre = @() $genreHtml = ($WebRequest.Content -split '<div id="video_genres" class="item">')[1] $genreHtml = ($genreHtml -split '<\/td>')[1] $genreHtml = $genreHtml -split 'rel="category tag">' @@ -233,14 +203,12 @@ function Get-JLGenre { function Get-JLActress { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) - begin { - $actress = @() - } - process { + $actress = @() $actressSplitString = '<span class="star">' $actressSplitHtml = $WebRequest.Content -split $actressSplitString @@ -263,6 +231,7 @@ function Get-JLActress { function Get-JLCoverUrl { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -279,14 +248,12 @@ function Get-JLCoverUrl { function Get-JLScreenshotUrl { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) - begin { - $screenshotUrl = @() - } - process { + $screenshotUrl = @() $screenshotHtml = (($WebRequest.Content -split '<div class="previewthumbs" style="display:block; margin:10px auto;">')[1] -split '<\/div>')[0] $screenshotHtml = $screenshotHtml -split '<img src="' foreach ($screenshot in $screenshotHtml) { diff --git a/src/Javinizer/Private/Get-JavlibraryUrl.ps1 b/src/Javinizer/Private/Get-JavlibraryUrl.ps1 index 0a50d72e..7e6440a6 100644 --- a/src/Javinizer/Private/Get-JavlibraryUrl.ps1 +++ b/src/Javinizer/Private/Get-JavlibraryUrl.ps1 @@ -1,44 +1,21 @@ function Get-JavlibraryUrl { [CmdletBinding()] param ( - [Parameter(Mandatory = $true, Position = 0)] - [string]$Name, - [int]$Tries, - [string]$ScriptRoot, - [string]$Language, - [switch]$Zh, - [switch]$Ja + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] + [string]$Id, + [Parameter(Mandatory = $true)] + [ValidateSet('en', 'ja', 'zh')] + [string]$Language ) - begin { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function started" - $searchUrl = "http://www.javlibrary.com/en/vl_searchbyid.php?keyword=$Name" - } - process { - try { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$searchUrl] with Session: [$Session] and UserAgent: [$($Session.UserAgent)]" - $webRequest = Invoke-WebRequest -Uri $searchUrl -Method Get -WebSession $Session -UserAgent $Session.UserAgent -Verbose:$false + $searchUrl = "http://www.javlibrary.com/en/vl_searchbyid.php?keyword=$Id" - if (($null -eq $webRequest) -or ($webRequest -eq '')) { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Session to JAVLibrary is unsuccessful, attempting to start a new session with Cloudflare" - try { - New-CloudflareSession -ScriptRoot $ScriptRoot - } catch { - throw $_ - } - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$searchUrl] with Session: [$Session] and UserAgent: [$($Session.UserAgent)]" - $webRequest = Invoke-WebRequest -Uri $searchUrl -Method Get -WebSession $Session -UserAgent $Session.UserAgent -Verbose:$false - } - } catch [Microsoft.PowerShell.Commands.HttpResponseException] { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Session to JAVLibrary is unsuccessful, attempting to start a new session with Cloudflare" - try { - New-CloudflareSession -ScriptRoot $ScriptRoot - } catch { - throw $_ - } - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$searchUrl] with Session: [$Session] and UserAgent: [$($Session.UserAgent)]" + try { + Write-JLog -Level Debug -Message "Performing [GET] on URL [$searchUrl] with Session: [$Session] and UserAgent: [$($Session.UserAgent)]" $webRequest = Invoke-WebRequest -Uri $searchUrl -Method Get -WebSession $Session -UserAgent $Session.UserAgent -Verbose:$false + } catch { + Write-JLog -Level Error -Message "Error [GET] on URL [$searchUrl] with Session: [$Session] and UserAgent: [$($Session.UserAgent)]: $PSItem" } # Check if the search uniquely matched a video page @@ -46,15 +23,15 @@ function Get-JavlibraryUrl { $searchResultUrl = $webRequest.BaseResponse.RequestMessage.RequestUri.AbsoluteUri if ($searchResultUrl -match 'http:\/\/www\.javlibrary\.com\/en\/\?v=') { try { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$searchResultUrl] with Session: [$Session] and UserAgent: [$($Session.UserAgent)]" + Write-JLog -Level Debug -Message "Performing [GET] on URL [$searchResultUrl] with Session: [$Session] and UserAgent: [$($Session.UserAgent)]" $webRequest = Invoke-WebRequest -Uri $searchResultUrl -Method Get -WebSession $Session -UserAgent $Session.UserAgent -Verbose:$false } catch { - throw $_ + Write-JLog -Level Error -Message "Error [GET] on URL [$searchResultUrl] with Session: [$Session] and UserAgent: [$($Session.UserAgent)]: $PSItem" } $resultId = Get-JLId -WebRequest $webRequest - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Result is [$resultId]" - if ($resultId -eq $Name) { + Write-JLog -Level Debug -Message "Result is [$resultId]" + if ($resultId -eq $Id) { $javlibraryUrl = $searchResultUrl } } @@ -74,12 +51,17 @@ function Get-JavlibraryUrl { $videoId = ($result -split '=')[1] $directUrl = "http://www.javlibrary.com/en/?v=$videoId" - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$directUrl] with Session: [$Session] and UserAgent: [$($Session.UserAgent)]" - $webRequest = Invoke-WebRequest -Uri $directUrl -Method Get -WebSession $Session -UserAgent $Session.UserAgent -Verbose:$false + try { + Write-JLog -Level Debug -Message "Performing [GET] on URL [$directUrl] with Session: [$Session] and UserAgent: [$($Session.UserAgent)]" + $webRequest = Invoke-WebRequest -Uri $directUrl -Method Get -WebSession $Session -UserAgent $Session.UserAgent -Verbose:$false + } catch { + Write-JLog -Level Error -Message "Error [GET] on URL [$directUrl] with Session: [$Session] and UserAgent: [$($Session.UserAgent)]: $PSItem" + } + $resultId = Get-JLId -WebRequest $webRequest - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Result [$count] is [$resultId]" + Write-JLog -Level Debug -Message "Result [$count] is [$resultId]" - if ($resultId -eq $Name) { + if ($resultId -eq $Id) { $javlibraryUrl = (Test-UrlLocation -Url $webRequest.BaseResponse.RequestMessage.RequestUri.AbsoluteUri).Url break } @@ -94,21 +76,16 @@ function Get-JavlibraryUrl { } if ($null -eq $javlibraryUrl) { - Write-Verbose "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Search [$Name] not matched on JAVLibrary" + Write-JLog -Level Warning -Message "Search [$Id] not matched on JAVLibrary" return } else { - if ($Ja.IsPresent) { + if ($Language -eq 'ja') { $javlibraryUrl = $javlibraryUrl -replace '/en/', '/ja/' - } elseif ($Zh.IsPresent) { + } elseif ($Language -eq 'zh') { $javlibraryUrl = $javlibraryUrl -replace '/en/', '/cn/' } Write-Output $javlibraryUrl } } - - end { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function ended" - } } - diff --git a/src/Javinizer/Private/Get-R18DataObject.ps1 b/src/Javinizer/Private/Get-R18DataObject.ps1 index 249a93d7..03055753 100644 --- a/src/Javinizer/Private/Get-R18DataObject.ps1 +++ b/src/Javinizer/Private/Get-R18DataObject.ps1 @@ -1,17 +1,11 @@ function Get-R18DataObject { [CmdletBinding()] - [OutputType([pscustomobject])] param ( - [Parameter(Position = 0)] - [string]$Name, - [Parameter(Position = 1)] - [string]$Url, - [string]$AltName, - [switch]$Zh + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] + [string]$Url ) - begin { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function started" + process { $movieDataObject = @() $replaceHashTable = @{ 'S********l' = 'Schoolgirl' @@ -61,67 +55,45 @@ function Get-R18DataObject { 'K**l' = 'Kill' 'A***e' = 'Abuse' } - } - process { - if ($Url) { - $r18Url = $Url - } else { - if ($Zh.IsPresent) { - $r18Url = Get-R18Url -Name $Name -AltName $AltName -Zh - } else { - $r18Url = Get-R18Url -Name $Name -AltName $AltName - } + try { + Write-JLog -Level Debug -Message "Performing [GET] on URL [$Url]" + $webRequest = Invoke-WebRequest -Uri $Url -Method Get -Verbose:$false + } catch { + Write-JLog -Level Error -Message "Error [GET] on URL [$Url]: $PSItem" } - if ($null -ne $r18Url) { - try { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing GET on Uri [$r18Url]" - $webRequest = Invoke-WebRequest -Uri $r18Url -Method Get -Verbose:$false - - $movieDataObject = [pscustomobject]@{ - Source = 'r18' - Url = $r18Url - ContentId = Get-R18ContentId -WebRequest $webRequest - Id = Get-R18Id -WebRequest $webRequest - Title = Get-R18Title -WebRequest $webRequest - Description = Get-R18Description -WebRequest $webRequest - Date = Get-R18ReleaseDate -WebRequest $webRequest - Year = Get-R18ReleaseYear -WebRequest $webRequest - Runtime = Get-R18Runtime -WebRequest $webRequest - Director = Get-R18Director -WebRequest $webRequest - Maker = Get-R18Maker -WebRequest $webRequest - Label = Get-R18Label -WebRequest $webRequest - Series = Get-R18Series -WebRequest $webRequest - Rating = Get-R18Rating -WebRequest $webRequest - Actress = (Get-R18Actress -WebRequest $webRequest).Name - Genre = Get-R18Genre -WebRequest $webRequest - ActressThumbUrl = (Get-R18Actress -WebRequest $webRequest).ThumbUrl - CoverUrl = Get-R18CoverUrl -WebRequest $webRequest - ScreenshotUrl = Get-R18ScreenshotUrl -WebRequest $webRequest - TrailerUrl = Get-R18TrailerUrl -WebRequest $webRequest - } - } catch { - throw $_ - } - } else { - Write-Verbose "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Search [$Name] not matched on R18" - return + $movieDataObject = [pscustomobject]@{ + Source = 'r18' + Url = $Url + ContentId = Get-R18ContentId -WebRequest $webRequest + Id = Get-R18Id -WebRequest $webRequest + Title = Get-R18Title -WebRequest $webRequest + Description = Get-R18Description -WebRequest $webRequest + Date = Get-R18ReleaseDate -WebRequest $webRequest + Year = Get-R18ReleaseYear -WebRequest $webRequest + Runtime = Get-R18Runtime -WebRequest $webRequest + Director = Get-R18Director -WebRequest $webRequest + Maker = Get-R18Maker -WebRequest $webRequest + Label = Get-R18Label -WebRequest $webRequest + Series = Get-R18Series -WebRequest $webRequest + Rating = Get-R18Rating -WebRequest $webRequest + Actress = (Get-R18Actress -WebRequest $webRequest).Name + Genre = Get-R18Genre -WebRequest $webRequest + ActressThumbUrl = (Get-R18Actress -WebRequest $webRequest).ThumbUrl + CoverUrl = Get-R18CoverUrl -WebRequest $webRequest + ScreenshotUrl = Get-R18ScreenshotUrl -WebRequest $webRequest + TrailerUrl = Get-R18TrailerUrl -WebRequest $webRequest } - - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] R18 data object:" - $movieDataObject | Format-List | Out-String | Write-Debug + Write-JLog -Level Debug -Message "R18 data object: $($movieDataObject | ConvertTo-Json -Depth 32 -Compress)" Write-Output $movieDataObject } - - end { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function ended" - } } function Get-R18ContentId { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -139,6 +111,7 @@ function Get-R18ContentId { function Get-R18Id { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -156,6 +129,7 @@ function Get-R18Id { function Get-R18Title { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -172,6 +146,7 @@ function Get-R18Title { function Get-R18Description { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -189,6 +164,7 @@ function Get-R18Description { function Get-R18ReleaseDate { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -237,6 +213,7 @@ function Get-R18ReleaseDate { function Get-R18ReleaseYear { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -249,6 +226,7 @@ function Get-R18ReleaseYear { function Get-R18Runtime { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -261,6 +239,7 @@ function Get-R18Runtime { function Get-R18Director { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -277,6 +256,7 @@ function Get-R18Director { function Get-R18Maker { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -294,6 +274,7 @@ function Get-R18Maker { function Get-R18Label { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -311,21 +292,26 @@ function Get-R18Label { function Get-R18Series { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) process { $series = ((($WebRequest.Content -split 'type=series')[1] -split '<\/a><br>')[0] -split '>')[1] $series = Convert-HtmlCharacter -String $series - $series = $series -replace '\n', ' ' + $series = $series -replace '\n', ' ' -replace "`t", '' $lang = ((($Webrequest.Content -split '\n')[1] -split '"')[1] -split '"')[0] $seriesUrl = ($WebRequest.links.href | Where-Object { $_ -like '*type=series*' }[0]) + '?lg=' + $lang if ($series -like '*...') { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing GET on Uri [$seriesUrl]" - $seriesSearch = Invoke-WebRequest -Uri $seriesUrl -Method Get -Verbose:$false - $series = Convert-HtmlCharacter -String ((((($seriesSearch.Content -split '<div class="breadcrumbs">')[1]) -split '<\/span>')[0]) -split '<span>')[1] + try { + Write-JLog -Level Debug -Message "Performing [GET] on URL [$seriesUrl]" + $seriesSearch = Invoke-WebRequest -Uri $seriesUrl -Method Get -Verbose:$false + } catch { + Write-JLog -Level ERROR -Message "Error [GET] on URL [$seriesUrl]: $PSItem" + } + $series = (Convert-HtmlCharacter -String ((((($seriesSearch.Content -split '<div class="breadcrumbs">')[1]) -split '<\/span>')[0]) -split '<span>')[1]) -replace "`t", '' } foreach ($string in $replaceHashTable.GetEnumerator()) { @@ -342,6 +328,7 @@ function Get-R18Series { function Get-R18Rating { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -353,14 +340,12 @@ function Get-R18Rating { function Get-R18Genre { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) - begin { - $genreArray = @() - } - process { + $genreArray = @() $genreHtml = ((($WebRequest.Content -split '<div class="pop-list">')[1] -split '<\/div>')[0] -split '<\/a>') -split '>' foreach ($genre in $genreHtml) { @@ -384,18 +369,15 @@ function Get-R18Genre { function Get-R18Actress { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) - begin { + process { $movieActressHtml = @() $movieActressExtract = @() $movieActress = @() $movieActressThumb = @() - } - - process { - #$movieActressHtml = ($WebRequest.Content -split '<p><img')[1] $movieActressHtml = $WebRequest.Content -split '\n' foreach ($line in $movieActressHtml) { if ($line -match '<p><img alt') { @@ -427,6 +409,7 @@ function Get-R18Actress { function Get-R18CoverUrl { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) @@ -439,14 +422,12 @@ function Get-R18CoverUrl { function Get-R18ScreenshotUrl { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) - begin { - $screenshotUrl = @() - } - process { + $screenshotUrl = @() $screenshotHtml = (($WebRequest.Content -split '<ul class="js-owl-carousel clearfix">')[1] -split '<\/ul>')[0] $screenshotHtml = $screenshotHtml -split '<li>' foreach ($screenshot in $screenshotHtml) { @@ -462,15 +443,12 @@ function Get-R18ScreenshotUrl { function Get-R18TrailerUrl { param ( + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] [object]$WebRequest ) - begin { - $trailerUrl = @() - } - process { - # $trailerHtml = $WebRequest.Content -split '\n' + $trailerUrl = @() $trailerUrl += (($WebRequest.Content -split 'data-video-low="')[1] -split '"')[0] $trailerUrl += (($WebRequest.Content -split 'data-video-med="')[1] -split '"')[0] $trailerUrl += (($WebRequest.Content -split 'data-video-high="')[1] -split '"')[0] @@ -479,14 +457,6 @@ function Get-R18TrailerUrl { $trailerUrl = $null } - <# $trailerHtml = $trailerHtml | Select-String -Pattern 'https:\/\/awscc3001\.r18\.com\/litevideo\/freepv' -AllMatches - - foreach ($trailer in $trailerHtml) { - $trailer = (($trailer -split '"')[1] -split '"')[0] - $trailerUrl += $trailer - } #> - - Write-Debug "Trailer Url is $trailerUrl" Write-Output $trailerUrl } } diff --git a/src/Javinizer/Private/Get-R18Url.ps1 b/src/Javinizer/Private/Get-R18Url.ps1 index 367cb89f..62055500 100644 --- a/src/Javinizer/Private/Get-R18Url.ps1 +++ b/src/Javinizer/Private/Get-R18Url.ps1 @@ -1,52 +1,72 @@ function Get-R18Url { [CmdletBinding()] param ( - [Parameter(Mandatory = $true, Position = 0)] - [string]$Name, - [string]$AltName, - [int]$Tries, - [switch]$Zh + [Parameter(Mandatory = $true, Position = 0, ValueFromPipeline = $true)] + [string]$Id, + [Parameter(Mandatory = $true)] + [ValidateSet('en', 'zh')] + [string]$Language ) - begin { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function started" + process { $searchResults = @() $altSearchResults = @() - $searchUrl = "https://www.r18.com/common/search/searchword=$Name/" - } + $searchUrl = "https://www.r18.com/common/search/searchword=$Id/" + + # If contentId is given, convert it back to standard movie ID to validate + if ($Id -match '([a-zA-Z|tT28|rR18]{1,10})\d{1,5}') { + Write-JLog -Level Debug -Message "Content ID [$Id] detected" + $splitId = $Id | Select-String -Pattern '([a-zA-Z|tT28|rR18]{1,10})(\d{1,5})' + $studioName = $splitId.Matches.Groups[1].Value + $rawStudioId = $splitId.Matches.Groups[2].Value + $studioIdIndex = ($rawStudioId | Select-String -Pattern '[1-9]').Matches.Index + $studioId = ($rawStudioId[$studioIdIndex..($rawStudioId.Length - 1)] -join '').PadLeft(3, '0') + + $Id = "$($studioName.ToUpper())-$studioId" + } + + # Convert the movie Id (ID-###) to content Id (ID00###) to match dmm naming standards + if ($Id -match '([a-zA-Z|tT28|rR18]+-\d+z{0,1}Z{0,1}e{0,1}E{0,1})') { + $splitId = $Id -split '-' + $contentId = $splitId[0] + $splitId[1].PadLeft(5, '0') + } - process { # Try matching the video with Video ID try { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$searchUrl]" + Write-JLog -Level Debug -Message "Performing [GET] on Uri [$searchUrl]" $webRequest = Invoke-WebRequest -Uri $searchUrl -Method Get -Verbose:$false } catch { - throw $_ + Write-JLog -Level Error -Message "Error [GET] on URL [$searchUrl]: $PSItem" } - $Tries = 5 + $retryCount = 5 $searchResults = (($webRequest.Links | Where-Object { $_.href -like "*/videos/vod/*/detail/-/id=*" }).href) $numResults = $searchResults.count - if ($Tries -gt $numResults) { - $Tries = $numResults + if ($retryCount -gt $numResults) { + $retryCount = $numResults } if ($numResults -ge 1) { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Searching [$Tries] of [$numResults] results for [$Name]" + Write-JLog -Level Debug -Message "Searching [$retryCount] of [$numResults] results for [$Id]" $count = 1 foreach ($result in $searchResults) { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$result]" - $webRequest = Invoke-WebRequest -Uri $result -Method Get -Verbose:$false + try { + Write-JLog -Level Debug -Message "Performing [GET] on URL [$result]" + $webRequest = Invoke-WebRequest -Uri $result -Method Get -Verbose:$false + } catch { + Write-JLog -Level Error -Message "Error [GET] on URL [$result]: $PSItem" + } + $resultId = Get-R18Id -WebRequest $webRequest - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Result [$count] is [$resultId]" - if ($resultId -eq $Name) { + Write-JLog -Level Debug -Message "Result [$count] is [$resultId]" + if ($resultId -eq $Id) { $directUrl = $result break } - if ($count -eq $Tries) { + if ($count -eq $retryCount) { break } @@ -56,40 +76,40 @@ function Get-R18Url { # If not matched by Video ID, try matching the video with Content ID if ($null -eq $directUrl) { - if ($AltName -eq '' -or $null -eq $AltName) { - $splitAltName = $Name -split '-' - $AltName = $splitAltName[0] + '00' + $splitAltName[1] - } - - $searchUrl = "https://www.r18.com/common/search/searchword=$AltName/" + $searchUrl = "https://www.r18.com/common/search/searchword=$contentId/" try { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$searchUrl]" + Write-JLog -Level Debug -Message "Performing [GET] on URL [$searchUrl]" $webRequest = Invoke-WebRequest -Uri $searchUrl -Method Get -Verbose:$false } catch { - throw $_ + Write-JLog -Level Error -Message "Error [GET] on URL [$searchUrl]: $PSItem" } - $Tries = 5 + $retryCount = 5 $altSearchResults = (($webRequest.Links | Where-Object { $_.href -like "*/videos/vod/movies/detail/-/id=*" }).href) $numResults = $altSearchResults.count - if ($Tries -gt $numResults) { - $Tries = $numResults + if ($retryCount -gt $numResults) { + $retryCount = $numResults } $count = 1 foreach ($result in $altSearchResults) { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$result]" - $webRequest = Invoke-WebRequest -Uri $result -Method Get -Verbose:$false + try { + Write-JLog -Level Debug -Message "Performing [GET] on URL [$result]" + $webRequest = Invoke-WebRequest -Uri $result -Method Get -Verbose:$false + } catch { + Write-JLog -Level Error -Message "Error [GET] on URL [$result]: $PSItem" + } + $resultId = Get-R18Id -WebRequest $webRequest - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Result [$count] is [$resultId]" - if ($resultId -eq $Name) { + Write-JLog -Level Debug -Message "Result [$count] is [$resultId]" + if ($resultId -eq $Id) { $directUrl = $result break } - if ($count -eq $Tries) { + if ($count -eq $retryCount) { break } @@ -99,10 +119,10 @@ function Get-R18Url { # If not matched by Video ID or Content ID, try matching the video with generic R18 URL if ($null -eq $directUrl) { - $testUrl = "https://www.r18.com/videos/vod/movies/detail/-/id=$AltName/" + $testUrl = "https://www.r18.com/videos/vod/movies/detail/-/id=$contentId/" try { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Performing [GET] on Uri [$testUrl]" + Write-JLog -Level Debug -Message "Performing [GET] on Uri [$testUrl]" $webRequest = Invoke-WebRequest -Uri $testUrl -Method Get -Verbose:$false } catch { $webRequest = $null @@ -110,25 +130,21 @@ function Get-R18Url { if ($null -ne $webRequest) { $resultId = Get-R18Id -WebRequest $webRequest - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Result is [$resultId]" - if ($resultId -eq $Name) { + Write-JLog -Level Debug -Message "Result is [$resultId]" + if ($resultId -eq $Id) { $directUrl = $testUrl } } } if ($null -eq $directUrl) { - # Write-Verbose "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Search [$Name] not matched on R18/Dmm" + Write-JLog -Level Warning -Message "Search [$Id] not matched on R18" return } else { - if ($Zh.IsPresent) { + if ($Language -eq 'zh') { $directUrl = $directUrl + '&lg=zh' } Write-Output $directUrl } } - - end { - Write-Debug "[$(Get-TimeStamp)][$($MyInvocation.MyCommand.Name)] Function ended" - } }