Jump to content

Google Image Save


Danyfirex
 Share

Recommended Posts

Hi Mates. Recently  I was needing to download some images from google images. but I got tired,frustrated when I had to click in the imagen then click again to be able to download the image with its real size. so For That I write this small code.

For downloading just simple go over the image in google image page., then press CTRL+MOUSE(just a little move is enowgh) that make a drag&drop so in that moment the code show a little window(5*5 LOL + transparency) so when realease the  mouse (mouse up event) the code start new process(itself) to download the image. 

 

For well in Google Chrome Broswer.

For Firefox almost always fails. 

Feactures.

  • Allow choose a folder for download save.
  • Allow Open the downloadfolder.

 

#NoTrayIcon
#include <GuiRichEdit.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <TrayConstants.au3>
#include <File.au3>
#include <InetConstants.au3>

Opt("GUIOnEventMode", 1)
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 3)

Local $AppExist = 0
If $CmdLine[0] = 0 Then
    If _Singleton('Danyfirex', 1) = 0 Then
        MsgBox(64, "", "Aplication is Already Running")
        Exit
    EndIf
EndIf

If $CmdLine[0] = 2 Then ;Downloader to Folder
    Local $sSaveFolder = $CmdLine[2] ;URL
    Local $sURL = $CmdLine[1] ;Folder
    Download($sURL, $sSaveFolder)
    Exit
EndIf


If Not @Compiled Then
    MsgBox(64, "", "Must be Compile For Download")
EndIf


HotKeySet("{ESC}", "Terminate")

Global $sFolderPath = @UserProfileDir & "\Pictures\"

Local $hDLL = DllOpen("user32.dll")
Local $hGUI, $hRichEdit = 0

$hGUI = GUICreate("Google Image Save", 5, 5, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
$hRichEdit = _GUICtrlRichEdit_Create($hGUI, "", 0, 0, 5, 5, -1)

TrayCreateItem("Set Folder to Save")
TrayItemSetOnEvent(-1, "SetFolder")
TrayCreateItem("")
TrayCreateItem("Open Folder")
TrayItemSetOnEvent(-1, "OpenFolder")
TrayCreateItem("")
TrayCreateItem("About...")
TrayItemSetOnEvent(-1, "About")
TrayCreateItem("")
TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "Terminate")

TraySetState($TRAY_ICONSTATE_SHOW)

WinSetTrans($hGUI, '', 1)
GUISetState(@SW_HIDE)

Local $aMouse = 0
Local $bCheck = False
Local $sDecode = ""
Local $i = 0
While True

    If _IsPressed("11", $hDLL) And _IsPressed("01", $hDLL) Then
        GUISetState(@SW_SHOW)
        $aMouse = MouseGetPos()
        WinMove($hGUI, '', $aMouse[0] - 2, $aMouse[1] - 2)
        $bCheck = True
    EndIf


    If _GUICtrlRichEdit_GetText($hRichEdit) <> '' And $bCheck Then
        $sDecode = GetURL(_GUICtrlRichEdit_GetText($hRichEdit))
        If $sDecode = "" Then
            $i += 1
            TrayTip($i & " Oops :(", 'Not Valid URL', 5)

        Else
            $i += 1
            TrayTip("[" & $i & "] Downloading :)", $sDecode, 5)
            If Not @Compiled Then
                MsgBox(64, "", "Must be Compile For Download")
            Else
                ShellExecute("GoogleImageSave.exe", $sDecode & " " & $sFolderPath)
            EndIf

        EndIf
        ConsoleWrite($sDecode & @CRLF)
        _GUICtrlRichEdit_SetText($hRichEdit, '')
        GUISetState(@SW_HIDE)
        $bCheck = False;
    EndIf

Sleep(100)


WEnd

Func GetURL($BADURL)
    Local $GoodURL = StringRegExp($BADURL, 'imgurl=(.*)\.(jpg|png|gif|bmp)', 3)
    If @error Then Return ''
    Return $GoodURL[0] & '.' & $GoodURL[1]
EndFunc   ;==>GetURL


Func Terminate()
    If MsgBox($MB_YESNO, "Exit", "¿Do You Want to Exit") = 6 Then Exit
EndFunc   ;==>Terminate

Func SetFolder()
    $sFolderPath = FileSelectFolder('Select a Folder', "")
    If $sFolderPath <> "" Then $sFolderPath &= '\'
    If $sFolderPath = "" Then $sFolderPath = @UserProfileDir & "\Pictures\"

EndFunc   ;==>SetFolder

Func OpenFolder()
    ShellExecute($sFolderPath)
EndFunc   ;==>OpenFolder


Func About()
    MsgBox(0, "Autoit Forum :)", "Written by Danyfirex")
EndFunc   ;==>About

Func _GetName($psFilename)
    Local $szDrive, $szDir, $szFName, $szExt
    _PathSplit($psFilename, $szDrive, $szDir, $szFName, $szExt)
    Return $szFName & $szExt
EndFunc   ;==>_GetName


Func Download($Url, $sSaveFolder)
    Local $sImageName = _GetName($Url)
    InetGet($Url, $sSaveFolder & $sImageName, $INET_FORCERELOAD)
    TraySetState($TRAY_ICONSTATE_SHOW)
    TrayTip("Downloaded :)", "", 0)
    TrayTip("Downloaded :)", $Url, 5)
    Sleep(5000)
EndFunc   ;==>Download

Saludos

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

×
×
  • Create New...