Advertisement
Wyvern67

Télécharger un album imgur

Mar 31st, 2015
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.43 KB | None | 0 0
  1. #include <Array.au3>
  2. #include <String.au3>
  3.  
  4. $title = "Imgur Downloader"
  5. $folder = InputBox($title, "Folder", "Folder")
  6. $url = InputBox($title, "Thread url", "http://imgur.com/a/abcde")
  7. $choice = False
  8.  
  9. If Not ($folder Or $url) Then
  10.     ConsoleWrite("Canceling"&@CRLF)
  11.     Exit
  12. EndIf
  13.  
  14. If $choice = 6 Then
  15.     $spamit = True
  16. Else
  17.     $spamit = False
  18. EndIf
  19.  
  20. If StringInStr($url, "#") > 0 Then
  21.     $url = _StringBetween($url, "", "#")
  22.     $url = $url[0]
  23. EndIf
  24. $albumID = _StringBetween($url, "/a/", "")
  25. $albumID = $albumID[0]
  26. $url = $url&"/all"
  27.  
  28. ConsoleWrite("$url: "&$url&@CRLF)
  29. ConsoleWrite("$albumID: "&$albumID&@CRLF)
  30.  
  31. If Not FileExists($folder) Then
  32.     DirCreate($folder)
  33. EndIf
  34.  
  35.  
  36. $picture_old = 0
  37. Dim $empty[1]
  38. Dim $picture[2]
  39.  
  40.  
  41. Func getFileName($string)
  42.     $string = _StringReverse($string)
  43.     Return _StringReverse(StringMid($string, 1, StringInStr($string, "/")-1))&".jpg"
  44. EndFunc
  45.  
  46. Func displayDownloading($bool)
  47.     If $bool Then
  48.         TraySetState(4)
  49.         TraySetIcon("downloading.png")
  50.     Else
  51.         TraySetState(8)
  52.         TraySetIcon("stopped.png")
  53.     EndIf
  54. EndFunc
  55.  
  56. Func FindString($str)
  57.     If StringInStr($page, $str) > 0 Then
  58.         return True
  59.     Else
  60.         return False
  61.     EndIf
  62. EndFunc
  63.  
  64. Func DownloadPics()
  65.     $id = 0
  66.     For $i=0 To UBound($picture)-1
  67. ;~      $filename = getFileName($picture[$i])
  68.         $id = $id+1
  69.         $filename = $albumID&"_"&$id&".jpg"
  70.         ConsoleWrite($picture[$i]&" ==> "&$filename&@CRLF)
  71.         If FileExists($folder&"\"&$filename) Then
  72.             ConsoleWrite("Name conflict"&@CRLF)
  73.             If FileGetSize($folder&"\"&$filename) = InetGetSize($picture[$i]) Then
  74.                 ConsoleWrite("-> Same size"&@CRLF)
  75.             Else
  76.                 displayDownloading(True)
  77.                 InetGet($picture[$i], $folder&"\"&$filename)
  78.                 displayDownloading(False)
  79.             EndIf
  80.         Else
  81.             displayDownloading(True)
  82.             InetGet($picture[$i], $folder&"\"&$filename)
  83.             displayDownloading(False)
  84.         EndIf
  85.     Next
  86.     $picture = $empty
  87. EndFunc
  88.  
  89. Func GetPicsUrl()
  90.     $picture = _StringBetween($page, '<a href="/a/'&$albumID&"#", '">')
  91.     For $i=0 To UBound($picture)-1
  92.         $picture[$i] = "http://imgur.com/download/"&$picture[$i]
  93.     Next
  94. EndFunc
  95.  
  96.  
  97. $pagename = Random(0, 2147483647, 1)
  98. InetGet($url, $pagename, 1)
  99. $h = FileOpen($pagename, 0)
  100. $page = FileRead($h)
  101. FileClose($h)
  102.  
  103. If FindString("<h1>Zoinks! You've taken a wrong turn.</h1>") Then
  104.     MsgBox(0, "", "The page has 404'd")
  105.     Exit
  106. EndIf
  107.  
  108. GetPicsUrl()
  109. DownloadPics()
  110.  
  111. Func quitting()
  112.     FileDelete($pagename)
  113. EndFunc
  114. OnAutoItExitRegister("quitting")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement