Advertisement
Guest User

chunks

a guest
Apr 23rd, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;;;loginwall;;;
  2. get_site:= http://archive.org/download/somefiles/file.zip
  3. save= C:\temp\file.zip
  4. filecreatedir, C:\temp
  5. username_str= user@email.com
  6. password_str= archive.org_password
  7. splitpath,save,filename,savetmp
  8. filetmp= %savetmp%\tmp.tmp
  9. fileold= %savetmp%\old.del
  10. filedelete, %filetmp%
  11. filedelete, %fileold%
  12.  
  13. ;;;5mb download chunk initialize;;;;
  14. bgn:= 0
  15. dnd:= 5000000
  16.  
  17. arcfinz=
  18. post_site:="https://archive.org/account/login.php"
  19. post_data:="username=" username_str "&password=" password_str "&remember=CHECKED&referer=https://archive.org&action=login&submit=Log in"
  20. Loop,
  21.     {
  22.         if (arcfinz = 2)
  23.             {
  24.                 break
  25.             }
  26.         WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
  27.         WebRequest.Open("POST", post_site)
  28.         WebRequest.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
  29.         WebRequest.SetRequestHeader("Cookie", "test-cookie=1")
  30.         WebRequest.Send(post_data)
  31.         WebRequest.Open("HEAD",get_site)
  32.         WebRequest.Send()
  33.         arcfz= % WebRequest.GetResponseHeader("Content-Length")
  34.         WebRequest.Open("GET",get_site)
  35.         ;;; set the download chunk range  ;;;;;
  36.         WebRequest.SetRequestHeader("Range", "bytes=" bgn "-" dnd "")
  37.         WebRequest.Send()
  38.         WebRequest.WaitForResponse(5)
  39.         ADODBObj := ComObjCreate( "ADODB.Stream" )
  40.         ADODBObj.Type := 1
  41.         ADODBObj.Open()
  42.         ADODBObj.Position := 0
  43.         ADODBObj.Write( WebRequest.ResponseBody )
  44.         ADODBObj.SaveToFile(filetmp, True ? 2:1)
  45.         ADODBObj.Close()
  46.         ADODBObj:=""
  47.         WebRequest:=""
  48.         if FileExist(filetmp)
  49.                 {
  50.                     filegetsize,fmtmp,%filetmp%
  51.                    
  52.                     ;;;;;  increment chunks  ;;;;;
  53.                     bgn+=5000001
  54.                     dnd+=5000000
  55.                    
  56.                     if ((dnd > arcfz)&&(arcfinz = ""))  ;;if projected download chunk exceeds the actual size, make the projected final download chunk the actual size
  57.                         {
  58.                             arcfinz= 1
  59.                             dnd:= arcfz
  60.                         }
  61.                     finv:= dnd - bgn
  62.                 }
  63.         if FileExist(fileold)
  64.             {
  65.                 RunWait,%comspec% cmd /c copy /b "%fileold%"+"%filetmp%" "%save%",,hide  ;;concatenates tmp files
  66.                 filedelete, "%filetmp%"
  67.                 filedelete, "%fileold%"
  68.                 if (arcfinz = 2)
  69.                     {
  70.                         break
  71.                     }
  72.                 filemove,%save%,%fileold%,1
  73.             }
  74.             else
  75.                 {
  76.                     filemove, %filetmp%,%fileold%,1
  77.                 }
  78.         filegetsize,oldtmp,%fileold%
  79.         if (fmtmp < 20000)
  80.             {
  81.                 if (arcfz <= oldtmp)
  82.                     {
  83.                         filemove,%fileold%,%save%,1
  84.                         break
  85.                     }
  86.                 msgbox,,,failed
  87.                 exitapp
  88.             }
  89.         if (arcfinz <> "")
  90.             {
  91.                 arcfinz+=1
  92.             }
  93.     }
  94. msgbox,,,file downloaded
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement