Jump to content

Downloader


Recommended Posts

Hi i am trying to download more than 1 file at the same time.

I got it to so i don't have to define a filename when it's downloaded, but i need to download a big list of rapidshare links from links.txt, and not only 1 by 1, it should start them all, please help, i tryed making a new process for eath download, but that is not a good solution for me, i know it can be done with background downloading, but it have to get it's default filename.

here's my script:

$file = FileOpen("links.txt", 0)
; Check if file opened for reading OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
; Read in lines of text until the EOF is reached
While 1
$line = FileReadLine($file)
;If @error = -1 Then ExitLoop
$url = ($line) ;source
$folder = @UserProfileDir & "\Downloads\" ;destination folder
InetGet($url,$folder & StringTrimLeft($url,StringInStr($url,"/",Default,-1))) ;stringinstr finds the last "/". Stringtrimleft trims all but the filename    
wend
Link to comment
Share on other sites

i also put this together, but still only downloads one file :P.

there's no problem if i do it like this:

Local $hDownload = InetGet("http://www.autoitscript.com/autoit3/files/beta/update.dat", @TempDir & "\update.dat", 1, 1)
but it have to read the links from a txt file and still be able to download more than 1 file at same time

$file = FileOpen("links.ini", 0)
; Check if file opened for reading OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
; Read in lines of text until the EOF is reached
While 1
$line = FileReadLine($file)
$name = StringMid($line,StringInStr($line,"/",0,-1)+1)

Do
Local $hDownload = InetGet($line,@ScriptDir&"\"&$name)
Local $hDownload = InetGet($line,@ScriptDir&"\"&$name)
Sleep(250)
Until InetGetInfo($hDownload, 2)    ; Check if the download is complete.
Local $nBytes = InetGetInfo($hDownload, 0)
InetClose($hDownload)   ; Close the handle to release resourcs.
wend

tyvern, thanks a lot for you post :mellow:

Edited by spymare
Link to comment
Share on other sites

Something along the lines of this

#include <File.au3>

Global $aLinkArray
$file = "links.ini"

_FileReadToArray($file, $aLinkArray)
If IsArray($aLinkArray) Then
    For $i = 1 To $aLinkArray[0]
        InetGet($aLinkArray[$i], @ScriptDir & "\" & $aLinkArray[$i] & ".tmp", 0, 1)
    Next
EndIf

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Well it wont work as it is, if your file is just links and only links per line, and its a text file it should, but if it is in standard ini format of course it wont.

Maybe you should provide a little more info about what exactly you cant get working and provide a sample of your file.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

links.txt contais:

http://rapidshare.com/files/265585704/warez-bb.Sonic.The.Hedgehog.The.Fastest.Thing.In.TimeDVDRiP.part1.rar

http://rapidshare.com/files/265585705/warez-bb.Sonic.The.Hedgehog.The.Fastest.Thing.In.TimeDVDRiP.part2.rar

http://rapidshare.com/files/265585750/warez-bb.Sonic.The.Hedgehog.The.Fastest.Thing.In.TimeDVDRiP.part3.rar

http://rapidshare.com/files/265585546/warez-bb.Sonic.The.Hedgehog.The.Fastest.Thing.In.TimeDVDRiP.part4.rar

and im logged into premium, so it's like a nornam download link

i tryed this, probably totally wrong?:

#include <File.au3>
$file = FileOpen("links.ini", 0)
; Check if file opened for reading OK
If $file = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
; Read in lines of text until the EOF is reached
While 1
$line = FileReadLine($file)
;If @error = -1 Then ExitLoop
$url = ($line) ;source
$folder = @homedrive & "\Downloads\" ;destination folder
InetGet($url,$folder & StringTrimLeft($url,StringInStr($url,"/",Default,-1))) ;stringinstr finds the last "/". Stringtrimleft trims all but the filename    
wend
Edited by spymare
Link to comment
Share on other sites

It might be something to do with the file path, Im not sure your trimleft trims anything, well there is no count anyway, are you getting errors?

try this

#include <File.au3>

Global $aLinkArray
$file = "links.ini"
$folder = @homedrive & "\Downloads\"
_FileReadToArray($file, $aLinkArray)
If IsArray($aLinkArray) Then
    For $i = 1 To $aLinkArray[0]
        $atemp = StringSplit($aLinkArray[$i],"/",2)
        $savefile = $atemp[UBound($atemp) -1]
        $savepath = $folder & $savepath
        InetGet($aLinkArray[$i], $savepath, 0, 1)
    Next
EndIf

I'm also not convinced you can download a rapidshare file in this manner.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

hmm its not working :/:

Global $aLinkArray
$file = "links.ini"
$folder = @homedrive & "\Downloads\"
_FileReadToArray($file, $aLinkArray)
If IsArray($aLinkArray) Then
    For $i = 1 To $aLinkArray[0]
        $atemp = StringSplit($aLinkArray[$i],"/",2)
        $savefile = $atemp[UBound($atemp) -1]
        $savepath = $folder
        InetGet($aLinkArray[$i], $savepath, 0, 1)
    Next
EndIf
Edited by spymare
Link to comment
Share on other sites

like this:

#include <File.au3>

Global $aLinkArray
Global $savefile
Global $savepath
$file = "links.txt"
$folder = @homedrive & "\Downloads\"
_FileReadToArray($file, $aLinkArray)
If IsArray($aLinkArray) Then
    For $i = 1 To $aLinkArray[0]
        $atemp = StringSplit($aLinkArray[$i],"/",2)
        $savefile = $atemp[UBound($atemp) -1]
        $savepath = $folder & $savepath
        InetGet($aLinkArray[$i], $savepath, 0, 1)
    Next
EndIf

error:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\pc\Desktop\New folder\New AutoIt v3 Script.au3"

>Exit code: 0 Time: 0.209

also it comes with : error allocating memory Edited by spymare
Link to comment
Share on other sites

Hmmm

Its might be exiting befor the downloads have completed (not sure) with the downloads being in the background

perhaps a loop of some sort until they have finished, not certain how it works fully. the exit code is normall.

The allocating memory error , Im going to guess its too many downloads at one time.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

The allocating memory error , Im going to guess its too many downloads at one time.

The example I linked attempts 100 (very small) downloads at the same time. I doubt that's the problem.

Its might be exiting befor the downloads have completed (not sure) with the downloads being in the background

That'd be my guess.

Try this:

#include <File.au3>

Global $aLinkArray 
Global $file = "links.txt"
Global $folder = @homedrive & "\Downloads\"

_FileReadToArray($file, $aLinkArray)
_DownloadMultiple($aLinkArray, $folder)

;put it in a function so you can easily run it multiple times
Func _DownloadMultiple($aLinks,$sFolder)
    Local $nComplete, $sSavePath, $sSaveFile, $aTemp, $aActive[Ubound($aLinks)-1]
    ;This is your script
    If IsArray($aLinks) Then
        For $i = 1 To $aLinks[0]
            $aTemp = StringSplit($aLinks[$i],"/",2)
            $sSaveFile = $aTemp[UBound($aTemp) -1]
            $sSavePath = $sFolder & $sSavePath
            $aActive[$i-1] = InetGet($aLinks[$i], $sSavePath, 0, 1)
        Next
    EndIf
    ;I added this part that waits until all downloads are complete
    Do
        For $i = 0 To $aLinks[0]-1
            If InetGetInfo($aActive[$i],2) Then
                $aActive[$i] = False
                $nComplete += 1
            EndIf
        Next
    Until $nComplete = $aLinks[0]
EndFunc
Edited by Tvern
Link to comment
Share on other sites

Yeah I made a cockup when renaming vars. Try the edited code instead(untested).

There won't be any errors returned as you'll have to add errorchecking and timeouts yourself. This is just to show the concept.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...