Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Simply install Autohotkey (https://autohotkey.com/download/), save this file as whatever.ahk, and double click.
- ; A macro for when there are no download links available; takes care of opening images in new tabs and downloading them.
- ; V2.2 Changelog: Put reused code in functions, added a double-check for trying to access save dialogue, added GUI instructions
- ; README
- ; A hacky AutoHotKey macro by meterion for idle downloading
- ; To use: Navigate to page 1 of desired gallery. Press Ctrl+q.
- ; Follow the prompt, leave computer alone as it does its thing (currently cannot function in background).
- ; Speed: ~1.5 minutes per 20 pages
- ; Press Ctrl+i for extra beeps lol (don't do this while it's running tho)
- ; NOTE: Makes an .ini file in the same directory it's used called "autosaversettings.ini"
- pageDelay := 2000 ; Conservative ms delay to load pages
- saveDelay := 500 ; Faster ms delay when exiting dialogue window
- numPages = 0 ; Number of pages set to download: 0 by default
- CoordMode, Mouse, Relative
- SetMouseDelay, 5
- setFormat, IntegerFast, d
- SetTitleMatchMode, 1
- ^q::
- Gui, Name: New, , Online Reader Autodownloader by meterion
- GUI, Add, Button, x10 w380 h20 gstartButton, Select a folder in which to download images
- IniRead, folderStart, autosaversettings.ini, User Settings, iniStart, %A_Space% ; Reads ini file for previously set download location
- if(folderStart)
- {
- GUI, Add, Text, x10 r2 w400 vupdateStart, Images will be downloaded to: `n%folderStart%
- }
- else
- {
- GUI, Add, Text, x10 r2 w400 vupdateStart, There is no download folder selected
- }
- Gui, Add, Checkbox, vrenamePages, Check to numerically rename files starting at 001
- Gui, Add, Edit, x10 w50 vnumPages gPageButton Number ; Set number of pages to download here
- Gui, Add, UpDown, gpagebutton, %numPages%
- Gui, Add, Text, x+m yp+3 w300 vpageText, %numPages% pages to download
- GUI, Add, Button, x10 w380 h40 gdownloadButton, Begin Downloading
- GUI, Add, Button, x10 y+20 w380 h20 gfavoriteButton, Select a default folder from which to browse download folder
- IniRead, folderFavorite, autosaversettings.ini, User Settings, iniFavorite, %A_Space%
- if(folderFavorite) ; Same as above for a set default location
- {
- GUI, Add, Text, x10 r2 w400 vupdateFavorite, Current default folder is: `n%folderFavorite%
- }
- else
- {
- GUI, Add, Text, x10 r2 w400 vupdateFavorite, There is no current default folder selected
- }
- GUI, Add, Text, w400 y+10 Center, NOTE: make sure you are on page 1 of desired gallery before starting.
- Gui, Show, W400 H250 Center, Online Reader Autodownloader by meterion
- return
- startButton: ; Brings up folder select, saves download folder path to ini file, updates GUI
- IniRead, folderFavorite, autosaversettings.ini, User Settings, iniFavorite, %A_Space%
- FileSelectFolder, toIniStart, *%folderFavorite%, 3, Choose where to save images
- IniWrite, %toIniStart%, autosaversettings.ini, User Settings, iniStart
- folderStart := toIniStart
- GuiControl, , updateStart, Images will be downloaded to: `n%folderStart%
- return
- pageButton: ; Need to submit value from GUI because the variable isn't being created here
- Gui, Submit, noHide
- GuiControl, , pageText, %numPages% pages to download
- return
- favoriteButton: ; As above for the default folder path
- FileSelectFolder, toIniFavorite, *%folderFavorite%, 3, Choose a Preferred Default Folder
- IniWrite, %toIniFavorite%, autosaversettings.ini, User Settings, iniFavorite
- folderFavorite := toIniFavorite
- Guicontrol, , updateFavorite, Current default folder is: `n%folderFavorite%
- return
- downloadButton: ; Where the magic happens
- Gui, Submit
- Gui, Destroy ; Ensures proper window is active
- WinGetActiveStats, Title, Width, Height, X, Y
- winXClick := Width/2 ; X/Y coords for where image probably is (top 1/3 of screen in the middle). If you have a lot of toolbars this probably has to be adjusted.
- winYClick := Height/3
- winXSClick := winXClick + 50 ; X/Y coords for where relative "Save Image As..." right-click dialogue is on Chrome. Probably has to be adjusted for other browsers/extensions installed.
- winYSClick := winYClick + 175
- loopNumber := numPages - 1 ; Since first page is downloaded out of loop, loopNumber is 1 less than page number
- numRename :=0 ; If rename option is selected, this will be used later. If it was used before, it will be reset to 0 now.
- Sleep, saveDelay ; allow for user to lift hand from keyboard/mouse
- pageSaveCheck()
- Send, {F4} ; This brings you to the filepath edit box in chrome. Might need to be adjusted for other browsers.
- Send, ^a
- SendRaw, %folderStart% ; Enters directory from initial GUI
- loop, 4
- {
- Send, {Enter} ; It takes many enters to go from filepath edit to confirming image save. Might need to be adjusted for other browsers. Can cause issues without the delay.
- sleep, 200
- }
- Sleep, saveDelay
- Loop, %loopNumber% ; Now loops the rest of the pages
- {
- Click, %winXClick%, %winYClick% ; Advance page
- Sleep, pageDelay
- pageSaveCheck()
- Send, {Enter} ; Save Image
- Sleep, saveDelay ; Needs some buffer time for the dialogue to exit before starting loop
- }
- playTune()
- MsgBox, 0, Autosave Completed, %numPages% pages downloaded.
- return
- pageSaveCheck() ; Does save image dialogue and any renaming
- {
- global ; setting scope to access/write global variables
- Click, %winXClick%, %winYClick%, right ; Opening first page
- Click, %winXSClick%, %winYSClick% ; Save Image As
- WinWaitActive, Save As, , 6 ; Wait for Save window to open (10 second delay to prevent multi-saves)
- if ErrorLevel ; If page takes too long to load image, try again
- {
- Click, %winXClick%, %winYClick%, right
- Click, %winXSClick%, %winYSClick%
- ErrorLevel = 0
- }
- WinWaitActive, Save As ; After 3 more seconds image should have loaded
- Sleep, 200
- if renamePages = 1
- {
- numRename := ++numRename
- numSend := SubStr("00" . numRename, -2)
- Send, %numSend%
- Sleep, 200
- }
- }
- playTune()
- {
- tones := [131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247, 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988, 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976]
- Random, toneStart, 1, 40 ; This part just plays a short chord and loads a dialogue box to show completion
- Random, jumpOne, 3, 4
- Random, jumpTwo, 3, 4
- SoundBeep, tones[ToneStart], 150
- SoundBeep, tones[ToneStart + jumpOne], 150
- SoundBeep, tones[ToneStart + jumpOne + jumpTwo], 150
- }
- ^i:: ; If you just want to play tones
- playTune()
- return
Add Comment
Please, Sign In to add comment