Guest User

img2ch.ps1

a guest
Aug 5th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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|re|tf|wf|yt)/[a-z]+/res/[0-9]+\.html$") ) {
  7.     echo "URL ""$threadurl"" 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 "Thread ""$threadurl"" not found!"
  17.     return 2
  18.   }
  19.  
  20.   $urlbase = $threadurl.Substring(0, $threadurl.IndexOf(".") + 4)
  21.  
  22.   echo 'Finding images...'
  23.   $imgs = echo $pagedata.Links | where href -match "^/[a-z]+/src/[0-9]+\.(jpg|png|gif|webm)" | select href
  24.  
  25.   md imgs$threadid
  26.  
  27.   echo 'Downloading images...'
  28.   foreach ($img in $imgs) {
  29.     $dld = $urlbase + $img.href
  30.     $filename = "imgs$threadid" + "\" + $dld.Substring($dld.LastIndexOf("/") + 1)
  31.     wget $dld -OutFile $filename
  32.   }
  33. }
  34.  
  35. if (-not $args) {
  36.   $threadurl = Read-Host 'Enter full thread URL'
  37.   Get-2chimages $threadurl
  38. }
  39. else {
  40.   foreach ($threadurl in $args) { Get-2chimages $threadurl }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment