-
Notifications
You must be signed in to change notification settings - Fork 61
/
Update-JVThumbCsv.ps1
84 lines (75 loc) · 4.59 KB
/
Update-JVThumbCsv.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
function Update-JVThumbCsv {
[CmdletBinding(DefaultParameterSetName = 'None')]
param(
[Parameter(Mandatory = $true, Position = 0, ParameterSetName = 'Page')]
[Int]$StartPage,
[Parameter(Mandatory = $true, Position = 1, ParameterSetName = 'Page')]
[Int]$EndPage
)
process {
try {
$ProgressPreference = 'SilentlyContinue'
$csvPath = Join-Path -Path ((Get-Item $PSScriptRoot).Parent) -ChildPath 'jvthumbs.csv'
if (!(Test-Path -LiteralPath $csvPath)) {
New-Item -Path $csvPath -ItemType File | Out-Null
}
$actressCsv = Import-Csv -LiteralPath $csvPath
if ($StartPage) {
$pageUrl = 'https://www.r18.com/videos/vod/movies/actress/letter=a/sort=new/page='
} else {
$pageUrl = 'https://www.r18.com/videos/vod/movies/actress/letter=a/sort=new/page='
$StartPage = 1
$webRequest = Invoke-WebRequest -Uri "https://www.r18.com/videos/vod/movies/actress/letter=a/sort=popular/page=1/" -Method Get -Verbose:$false
$EndPage = ((($webRequest.Content -split '<li>\.\.\.<\/li>')[1] -split '<\/a><\/li>')[0] -split '>')[2]
}
for ($x = $StartPage; $x -le $EndPage; $x++) {
Write-Host "[$($MyInvocation.MyCommand.Name)] Scraping actress page [$x]"
$actressObject = @()
$actressObjectJa = @()
$combinedActressObject = @()
$webRequest = Invoke-WebRequest "$pageUrl$x" -Verbose:$false
$matchedActresses = ($webRequest.Content | Select-String -Pattern '<img src="(.*)" width="135" height="135" alt="(.*)">' -AllMatches).Matches
foreach ($match in $matchedActresses) {
$actressObject += [PSCustomObject]@{
Name = $match.Groups[2].Value
ThumbUrl = $match.Groups[1].Value
}
}
$webRequestJa = Invoke-WebRequest "$pageUrl$x/?lg=zh" -Verbose:$false
$matchedActressesJa = ($webRequestJa.Content | Select-String -Pattern '<img src="(.*)" width="135" height="135" alt="(.*)">' -AllMatches).Matches
foreach ($match in $matchedActressesJa) {
$actressObjectJa += [PSCustomObject]@{
Name = $match.Groups[2].Value
ThumbUrl = $match.Groups[1].Value
}
}
$groupedObject = ($actressObject + $actressObjectJa | Group-Object ThumbUrl) | Where-Object { $_.Count -eq 2 }
foreach ($actress in $groupedObject) {
$combinedActressObject += [PSCustomObject]@{
LastName = (($actress.Group[0].Name -replace '\.\.\.', '').Trim() -split ' ')[1]
FirstName = (($actress.Group[0].Name -replace '\.\.\.', '').Trim() -split ' ')[0]
JapaneseName = ($actress.Group[1].Name).Trim() -replace '(.*)', ''
ThumbUrl = $actress.Group[0].ThumbUrl
Alias = $null
}
}
foreach ($actress in $combinedActressObject) {
if ($null -ne $actressCsv) {
if (!(Compare-Object -ReferenceObject $actressCsv -DifferenceObject $actress -IncludeEqual -ExcludeDifferent -Property @('JapaneseName', 'ThumbUrl'))) {
$actressString = "$($actress.LastName) $($actress.FirstName)".Trim()
Write-JLog -Level Info -Message "[$($MyInvocation.MyCommand.Name)] [Page $x] Actress [($actressString - $($actress.JapaneseName)] written to [$csvPath]"
$actress | Export-Csv -LiteralPath $csvPath -Append -Encoding utf8
}
} else {
$actressString = "$($actress.LastName) $($actress.FirstName)".Trim()
Write-JLog -Level Info -Message "[$($MyInvocation.MyCommand.Name)] [Page $x] Actress [($actressString - $($actress.JapaneseName)] written to [$csvPath]"
$actress | Export-Csv -LiteralPath $csvPath -Append -Encoding utf8
}
}
}
} catch {
Write-JLog -Level Error -Message "[$($MyInvocation.MyCommand.Name)] Error occured when updating Javinizer thumb csv at path [$csvPath]: $PSItem"
return
}
}
}