Skip to content

Instantly share code, notes, and snippets.

@hansgafriedzal
Created July 9, 2020 23:02
Show Gist options
  • Save hansgafriedzal/ab3c575a1c8c374d834a72ace077661d to your computer and use it in GitHub Desktop.
Save hansgafriedzal/ab3c575a1c8c374d834a72ace077661d to your computer and use it in GitHub Desktop.
$userid = '1234567'
$uri = "https://cy.cyworld.com/home/$userid/posts"
$timestamp = Get-Date -format "yyyyMMddHHmmss"
$outputPath = "$([Environment]::GetFolderPath("Desktop"))\$userid\$timestamp\"
mkdir $outputPath -ErrorAction SilentlyContinue > $null
$origin = ([datetime]'1/1/1970')
$headers = @{
"Accept"="application/json, text/javascript, */*; q=0.01"
}
$body = @{
airecase = ''
airelastdate = ''
airepageno = ''
folderid = ''
homeId = $userid
lastdate = ''
lastid = ''
listsize = 20
searchType= ''
search = ''
tagname = ''
}
$postList = @()
do
{
$response = Invoke-WebRequest `
-Uri "$uri$queryParams" `
-Body $body `
-Headers $headers | %{$_.Content} | ConvertFrom-Json
$response.postList | %{
$postList += [pscustomobject] @{
imageUrl = $_.summaryModel.image
createdDate = ($origin.AddMilliseconds($_.createdDate)).ToString('yyyyMMddHHmmss')
}
}
$lastid = $response.postList | select -Last 1 | %{$_.identity}
$lastdate = $response.lastdate
$body.airecase = 'D'
$body.airelastdate = ''
$body.airepageno = '0'
$body.folderid = ''
$body.lastid = $lastid
$body.lastdate = $lastdate
$body.searchType = 'R'
$body.tagname = ''
}
#while ($count -lt 20)
while ($postList.count -lt $response.totalCount)
$wc = New-Object System.Net.WebClient
$postList | %{
$url = $_.imageUrl
if ($url -and $url -notlike '*ALBUM*' -and $url -notlike '*.swf')
{
$filename = $_.createdDate + '_'
if ($url -like '*%2f*')
{
$filename += (Split-Path $url -Leaf) -split '%2F' | select -last 1
}
else
{
$filename += (Split-Path $url -Leaf) -split '=' | select -last 1
$filename += '.jpg'
}
$i = $url.LastIndexOf('/') + 1
if ($url.Substring($i,3) -ne 'vm_' -and $url.Substring($i,4) -ne 'enc_')
{
$url = $url.Insert($i, 'vm_')
}
$url
$wc.DownloadFile($url, "$outputPath$filename")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment