View difference between Paste ID: mLrFWahg and HeSfaiL9
SHOW: | | - or go back to the newest paste.
1
# 2ch.hk image dumper
2
# Usage: execute in PowerShell by right click or pass thread URLs as arguments
3
# (multiple threads allowed); passing args require execution policy
4
5
function Get-2chimages ($threadurl) {
6
  if ( -not ($threadurl -match "^http[s]{0,1}://2ch\.(hk|pm)/[a-z]+/res/[0-9]+\.html$") ) {
7
    echo "URL is not valid!"
8
    return 1
9
  }
10
  
11
  $threadid = $threadurl.Substring($threadurl.LastIndexOf("/") + 1)
12
13
  echo 'Downloading thread $threadid...'
14
  $pagedata = wget $threadurl
15
  if (-not $?) {
16
    echo "Can't donwload $threadurl!"
17
    return 2
18
  }
19
20
  echo 'Finding images...'
21
  $imgs = echo $pagedata.Links | where href -match "^/[a-z]?/src/.*\.(jpg|png|gif|webm)" | select href
22
23
  md imgs$threadid
24
25
  echo 'Downloading images...'
26
  foreach ($img in $imgs) {
27
    $dld = "http://2ch.pm" + $img.href
28-
    $filename = "imgs" + $threadid + $dld.Substring($dld.LastIndexOf("/") + 1)
28+
    $filename = "imgs$threadid" + "\" + $dld.Substring($dld.LastIndexOf("/") + 1)
29
    wget $dld -OutFile $filename
30
  }
31
}
32
33
if (-not $args) {
34
  $threadurl = Read-Host 'Enter full thread URL'
35
  Get-2chimages $threadurl
36
}
37
else {
38
  foreach ($threadurl in $args) {
39
    Get-2chimages $threadurl
40
  }
41
}