meterion

Autohotkey Online Reader Autodownload Macro 2.1

May 3rd, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.55 KB | None | 0 0
  1. ; Simply install Autohotkey (https://autohotkey.com/download/), save this file as whatever.ahk, and double click.
  2. ; A macro for when there are no download links available; takes care of opening images in new tabs and downloading them.
  3.  
  4. ; V2.1 Changelog: added changelog. Improved loop consistency through winwaitactive rather than sleep. Improved GUI page number functionality. V2.0 retroactive changelog: stopped being a hot mess.
  5.  
  6. ; README
  7. ; A hacky AutoHotKey macro by meterion for idle downloading
  8. ; To use: Navigate to page 1 of desired gallery. Press Ctrl+q.
  9. ; Follow the prompt, leave computer alone as it does its thing (currently cannot function in background).
  10. ; Speed: ~1.5 minutes per 20 pages
  11. ; Press Ctrl+i for extra beeps lol (don't do this while it's running tho)
  12. ; NOTE: Makes an .ini file in the same directory it's used called "autosaversettings.ini"
  13.  
  14. pageDelay := 2000 ; Conservative ms delay to load pages
  15. saveDelay := 500 ; Faster ms delay when exiting dialogue window
  16. numPages = 0 ; Number of pages set to download: 0 by default
  17. 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]
  18. ; ^Chromatic tones for when it finishes
  19.  
  20. CoordMode, Mouse, Relative
  21. SetMouseDelay, 5
  22. setFormat, IntegerFast, d
  23. SetTitleMatchMode, 1
  24.  
  25. ^q::
  26. Gui, Name: New, , Online Reader Autodownloader by meterion
  27. GUI, Add, Button, x10 w380 h20 gstartButton, Select a folder in which to download images
  28. IniRead, folderStart, autosaversettings.ini, User Settings, iniStart, %A_Space% ; Reads ini file for previously set download location
  29. if(folderStart)
  30. {
  31. GUI, Add, Text, x10 r2 w400 vupdateStart, Images will be downloaded to: `n%folderStart%
  32. }
  33. else
  34. {
  35. GUI, Add, Text, x10 r2 w400 vupdateStart, There is no download folder selected
  36. }
  37.  
  38. Gui, Add, Checkbox, vrenamePages, Check to numerically rename files starting at 001
  39.  
  40. Gui, Add, Edit, x10 w50 vnumPages gPageButton Number ; Set number of pages to download here
  41. Gui, Add, UpDown, gpagebutton, %numPages%
  42.  
  43. Gui, Add, Text, x+m yp+3 w300 vpageText, %numPages% pages to download
  44.  
  45. GUI, Add, Button, x10 w380 h40 gdownloadButton, Begin Downloading
  46.  
  47. GUI, Add, Button, x10 y+20 w380 h20 gfavoriteButton, Select a default folder from which to browse download folder
  48. IniRead, folderFavorite, autosaversettings.ini, User Settings, iniFavorite, %A_Space%
  49. if(folderFavorite) ; Same as above for a set default location
  50. {
  51. GUI, Add, Text, x10 r2 w400 vupdateFavorite, Current default folder is: `n%folderFavorite%
  52. }
  53. else
  54. {
  55. GUI, Add, Text, x10 r2 w400 vupdateFavorite, There is no current default folder selected
  56. }
  57.  
  58. Gui, Show, W400 H250 Center, Online Reader Autodownloader by meterion
  59. return
  60.  
  61. startButton: ; Brings up folder select, saves download folder path to ini file, updates GUI
  62. IniRead, folderFavorite, autosaversettings.ini, User Settings, iniFavorite, %A_Space%
  63. FileSelectFolder, toIniStart, *%folderFavorite%, 3, Choose where to save images
  64. IniWrite, %toIniStart%, autosaversettings.ini, User Settings, iniStart
  65. folderStart := toIniStart
  66. GuiControl, , updateStart, Images will be downloaded to: `n%folderStart%
  67. return
  68.  
  69. pageButton: ; Need to submit value from GUI because the variable isn't being created here
  70. Gui, Submit, noHide
  71. GuiControl, , pageText, %numPages% pages to download
  72. return
  73.  
  74. favoriteButton: ; As above for the default folder path
  75. FileSelectFolder, toIniFavorite, *%folderFavorite%, 3, Choose a Preferred Default Folder
  76. IniWrite, %toIniFavorite%, autosaversettings.ini, User Settings, iniFavorite
  77. folderFavorite := toIniFavorite
  78. Guicontrol, , updateFavorite, Current default folder is: `n%folderFavorite%
  79. return
  80.  
  81. downloadButton: ; Where the magic happens
  82. Gui, Submit
  83. Gui, Destroy ; Ensures proper window is active
  84.  
  85. WinGetActiveStats, Title, Width, Height, X, Y
  86. 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.
  87. winYClick := Height/3
  88. 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.
  89. winYSClick := winYClick + 175
  90.  
  91. loopNumber := numPages - 1 ; Since first page is downloaded out of loop, loopNumber is 1 less than page number
  92. numRename :=0 ; If rename option is selected, this will be used later. If it was used before, it will be reset to 0 now.
  93.  
  94. Sleep, saveDelay ; allow for user to lift hand from keyboard/mouse
  95.  
  96. Click, %winXClick%, %winYClick%, right ; Opening first page
  97. Click, %winXSClick%, %winYSClick% ; Save Image As
  98. WinWaitActive, Save As, , 6 ; Wait for Save window to open (10 second delay to prevent multi-saves)
  99. if ErrorLevel ; If page takes too long to load image, try again
  100. {
  101. Click, %winXClick%, %winYClick%, right
  102. Click, %winXSClick%, %winYSClick%
  103. ErrorLevel = 0
  104. }
  105. WinWaitActive, Save As ; After 3 more seconds image should have loaded
  106. Sleep, 200
  107.  
  108. if renamePages = 1 ; This code renames the image and is reused below, which is why it begins by iterating numRename to 1. It changes to numSend to properly return "009" instead of "9", etc.
  109. {
  110. numRename := ++numRename
  111. numSend := SubStr("00" . numRename, -2)
  112. Send, %numSend%
  113. Sleep, 200
  114. }
  115. Send, {F4} ; This brings you to the filepath edit box in chrome. Might need to be adjusted for other browsers.
  116. Send, ^a
  117. SendRaw, %folderStart% ; Enters directory from initial GUI
  118. loop, 4
  119. {
  120. 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.
  121. sleep, 200
  122. }
  123. Sleep, saveDelay
  124.  
  125. Loop, %loopNumber% ; Now loops the rest of the pages
  126. {
  127. Click, %winXClick%, %winYClick% ; Advance page
  128. Sleep, pageDelay
  129. Click, %winXClick%, %winYClick%, right ; Right Click
  130. Click, %winXSClick%, %winYSClick% ; Save Image As
  131. WinWaitActive, Save As, , 6 ; Wait for Save window to open
  132. if ErrorLevel ; If page takes too long to load image, try again
  133. {
  134. Click, %winXClick%, %winYClick%, right
  135. Click, %winXSClick%, %winYSClick%
  136. ErrorLevel = 0
  137. }
  138. WinWaitActive, Save As ; After 3 more seconds image should have loaded
  139. Sleep, 200 ; Buffer loading time
  140. if renamePages = 1 ; See above note for info
  141. {
  142. numRename := ++numRename
  143. numSend := SubStr("00" . numRename, -2)
  144. Send, %numSend%
  145. Sleep, 200
  146. }
  147. Send, {Enter} ; Save Image
  148. Sleep, saveDelay ; Needs some buffer time for the dialogue to exit before starting loop
  149. }
  150.  
  151. Random, toneStart, 1, 40 ; This part just plays a short chord and loads a dialogue box to show completion
  152. Random, jumpOne, 3, 4
  153. Random, jumpTwo, 3, 4
  154. SoundBeep, tones[ToneStart], 150
  155. SoundBeep, tones[ToneStart + jumpOne], 150
  156. SoundBeep, tones[ToneStart + jumpOne + jumpTwo], 150
  157. MsgBox, 0, Autosave Completed, %numPages% pages downloaded.
  158. return
  159.  
  160. ^i:: ; If you just want to play tones (could probably be compressed in a function but whatever it's only used twice)
  161. Random, toneStart, 1, 40
  162. Random, jumpOne, 3, 4
  163. Random, jumpTwo, 3, 4
  164.  
  165. SoundBeep, tones[ToneStart], 150
  166. SoundBeep, tones[ToneStart + jumpOne], 150
  167. SoundBeep, tones[ToneStart + jumpOne + jumpTwo], 150
  168. return
Add Comment
Please, Sign In to add comment