Jump to content
Sign in to follow this  
lagoon

InetGet mass image downloader

Recommended Posts

lagoon

First of all I want to say that I don't understand autoit at all! In that sense, I couldn't even be regarded as a beginner. So I hope you can make things in this topic understandable even for someone like me. Thank you :)

So the thing is I looked around google for a simple little script to mass download galleries of images and what I found was InetGet. Even I could understand that simple command.

Now I've got this:

InetGet("http://xyz.com/xyz.php?id=1&imgname=001.jpg","C:\001.jpeg")
InetGet("http://xyz.com/xyz.php?id=1&imgname=002.jpg","C:\002.jpeg")
InetGet("http://xyz.com/xyz.php?id=1&imgname=003.jpg","C:\003.jpeg")

And that goes on for another ~150 lines. It all works fine however there's one annoying thing:

When I want to download another "gallery" of images I'd have to change the "id=1" to, let's say "id=2" or "id=3" ...

Sounds simple but it's really a pain in the ass to do it for almost 200 lines ^^

So.. I think you understand with that. I'd thought of some way to automatically or easily replace the "1" with another number. But of course, if you know of some completely different way to mass download images like this that I could use, feel free to tell me about it!

.. I really wrote quite a lot about such a "simple" problem, didn't I? :sweating:

I really really hope someone can help me on this.

Thank you for reading!

Share this post


Link to post
Share on other sites
FireFox

Hi,

Welcome to the autoit forum :)

;this script will download the 100 first images of the 5 first galleries
;e.g: gallery 1: img: 1, 2, 3... 100
;gallery 2: img: 1... 100
;...
;gallery 5: ... 100

Local $hDl = 0, $sImgName = ""

For $iGallery = 1 To 5 ;will loop from 1 to 5, incrementing the variable iGallery
    For $iImg = 1 To 100 ;will loop from 1 to 100, incrementing the variable iImg
        $sImgName = StringFormat("%.3d", $iImg) ;will fill the number to 3 digits (e.g: 5 will be 005)

        $hDl = InetGet("http://xyz.com/xyz.php?id=" & $iGallery & "&imgname=" & $sImgName & ".jpg","C:\" & $sImgName & ".jpeg")
        InetClose($hDl) ;releases the resources
    Next
Next

I hope this is clear for you ;)

Edit: There is a VERY useful helpfile for each function, press F1 in SciTE and voila !

Br, FireFox.

Edited by FireFox

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
lagoon

What a fast reply!

I just tested it out and it works perfectly! This is exactly what I have been looking for

A thousand thanks to you! :lol:

Edit: There is a VERY useful helpfile for each function, press F1 in SciTE and voila !

Br, FireFox.

Thanks, I didn't see that before. I will use it when I ever need any help again! :)

Share this post


Link to post
Share on other sites
guinness

First of all I want to say that I don't understand autoit at all! In that sense, I couldn't even be regarded as a beginner. So I hope you can make things in this topic understandable even for someone like me. Thank you :)

My advice, if you're new to something don't try to run before you can walk" FireFox was kind enough to help you, but accepting free code isn't going to improve your learning curve, that comes from you talking the help file and their code and breaking down what they and why they did it. This is how I learnt and many before me.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
lagoon

Oookay, it seems like I'm stuck again >_<

I tried to change the code a little bit:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form2 = GUICreate("Downloader", 405, 294, 264, 168)
$Input1 = GUICtrlCreateInput("", 32, 48, 153, 21)
$Downloadstart = GUICtrlCreateButton("Download", 232, 48, 145, 33, $WS_GROUP)
$hDl = 0

GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Downloadstart
            $read = GUICtrlRead($Input1) 
            $hDl = InetGet("address" & $Input1,"directory" & ".png")
            InetClose($hdl)
            For $iImg = 2 To 240 ;will loop from 1 to 100, incrementing the variable iImg
               $sImgName = StringFormat("%.3d", $iImg) ;will fill the number to 3 digits (e.g: 5 will be 005)
               
               $hDl = InetGet("address" & $Input1 & "&imgname=" & $sImgName & ".jpg","directory" & StringFormat("%.3d", $sImgName) & ".jpg")
               InetClose($hDl) ;releases the resources
     Next
   EndSwitch
WEnd

I guess you people can see what I tried to do just by this ^^

I wanted it to open a window where I can input the ID and then click the download button to download the images

It doesn't seem to be working though. I simply get "empty" images. Like, images with 0 bytes that don't show anything.

I'd also like to try adding 2 other things later on (the program automatically recognizing when the gallery ends // when restarting the program not having to reload images that have already been downloaded) but fixing this problem comes first.

I tried using the help file.. to no avail :sweating:

Edited by lagoon

Share this post


Link to post
Share on other sites
lagoon

Such a simple thing..

Well it works now :P

One thing though: It seems like I can't stop the program normally by pressing the X, how do I fix that?

Also, it'd be nice if someone could "push me in the right direction" for the earlier mentioned 2 improvements.

Share this post


Link to post
Share on other sites
lagoon

Tried looking for what that eventmode is in the first place and implementing it with the help of this and other sites but no idea.. Doesn't work for me ;(

Share this post


Link to post
Share on other sites
lagoon

Yeah, as I said in my previous comment I already know of that site

Well, I tried it again anyway. This is what I got:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
$mainwindow = GUICreate("Downloader", 405, 294, 264, 168)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$Downloadstart = GUICtrlCreateButton("Download", 232, 48, 145, 33, $WS_GROUP)
GUICtrlSetOnEvent($Downloadstart, "Downloadstart")
$Input1 = GUICtrlCreateInput("", 32, 48, 153, 21)
$hDl = 0
GUISetState(@SW_SHOW)

While 1
  Sleep(1000)  ; Idle around
WEnd

Func Downloadstart()
   $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Downloadstart
            $read = GUICtrlRead($Input1) 
            $hDl = InetGet("address" & $read,"directory" & ".png")
            InetClose($hdl)
            For $iImg = 2 To 240 ;will loop from 1 to 100, incrementing the variable iImg
               $sImgName = StringFormat("%.3d", $iImg) ;will fill the number to 3 digits (e.g: 5 will be 005)
               
               $hDl = InetGet("address" & $read & "&imgname=" & $sImgName & ".jpg","directory" & StringFormat("%.3d", $sImgName) & ".jpg")
               InetClose($hDl) ;releases the resources
            Next
   EndSwitch
EndFunc

Func CLOSEClicked()
  ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
  ;and @GUI_WINHANDLE would equal $mainwindow
  MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
  Exit
EndFunc

Problem: The download won't start

Share this post


Link to post
Share on other sites
lagoon

Okay I got it to work (more or less, it downloads the images now :P)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode
$mainwindow = GUICreate("Downloader", 405, 294, 264, 168)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$Downloadstart = GUICtrlCreateButton("Download", 232, 48, 145, 33, $WS_GROUP)
GUICtrlSetOnEvent($Downloadstart, "Downloadstart")
$Input1 = GUICtrlCreateInput("", 32, 48, 153, 21)
$hDl = 0
GUISetState(@SW_SHOW)

While 1
  Sleep(1000)  ; Idle around
WEnd

Func Downloadstart()
   $read = GUICtrlRead($Input1) 
   $hDl = InetGet("address" & $read,"directory" & ".png")
   InetClose($hdl)
   For $iImg = 2 To 240 ;will loop from 1 to 100, incrementing the variable iImg
      $sImgName = StringFormat("%.3d", $iImg) ;will fill the number to 3 digits (e.g: 5 will be 005)
      $hDl = InetGet("address" & $read & "&imgname=" & $sImgName & ".jpg","directory" & StringFormat("%.3d", $sImgName) & ".jpg")
      InetClose($hDl) ;releases the resources
      Next
EndFunc

Func CLOSEClicked()
  ;Note: at this point @GUI_CTRLID would equal $GUI_EVENT_CLOSE,
  ;and @GUI_WINHANDLE would equal $mainwindow
  MsgBox(0, "GUI Event", "You clicked CLOSE! Exiting...")
  Exit
EndFunc

Yet, closing the program by clicking on the X still won't work

Also, the program is very laggy and will not react after downloading ~30 or so images :/

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  

×