Sign in to follow this  
Followers 0
spymare

Downloader

23 posts in this topic

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

Share this post


Link to post
Share on other sites



is it possible you can modify my code to do that :mellow:? im not sure how to do it :P

Share this post


Link to post
Share on other sites

Take a look at this post for an example and also for a way to increase the connection limit.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

hmm can't get it working

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

i tryed $savepath = $folder & $savefile

but it says savefile not have been declared.

it's not because i don't wanna give info, im very new to autoit, so it's a bit hard to get started :mellow:

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

there's only 2 links in the txt files

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

hi tvern, thanks for you reply.

the code doesent download the links, and neither gives any error :/

Share this post


Link to post
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.

Share this post


Link to post
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
Sign in to follow this  
Followers 0