meterion

Autohotkey Online Reader Autodownload Macro 2.4

May 23rd, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.86 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.4 Changelog: pageSaveCheck now checks every second--main loop has been adjusted to compensate for having to escape out of multiple "Save as" dialogues. Download button made default (enter presses it)
  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 50 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 := 1000 ; Conservative ms delay to load pages
  15. saveDelay := 200 ; Faster ms delay when exiting dialogue window
  16. numPages = 0 ; Number of pages set to download: 0 by default
  17. CoordMode, Mouse, Relative
  18. SetMouseDelay, 2
  19. setFormat, IntegerFast, d
  20. SetTitleMatchMode, 1
  21.  
  22. ^q::
  23. Gui, Name: New, , Online Reader Autodownloader by meterion
  24. GUI, Add, Button, x10 w380 h20 gstartButton, Select a folder in which to download images
  25. IniRead, folderStart, autosaversettings.ini, User Settings, iniStart, %A_Space% ; Reads ini file for previously set download location
  26. if(folderStart)
  27. {
  28. GUI, Add, Text, x10 r2 w400 vupdateStart, Images will be downloaded to: `n%folderStart%
  29. }
  30. else
  31. {
  32. GUI, Add, Text, x10 r2 w400 vupdateStart, There is no download folder selected
  33. }
  34. Gui, Add, Checkbox, vrenamePages, Check to numerically rename files starting at 001
  35.  
  36. Gui, Add, Edit, x10 w50 vnumPages gPageButton Number ; Set number of pages to download here
  37. Gui, Add, UpDown, gpagebutton, %numPages%
  38. Gui, Add, Text, x+m yp+3 w300 vpageText, %numPages% pages to download
  39.  
  40. GUI, Add, Button, x10 w380 h40 Default gdownloadButton, Begin Downloading
  41.  
  42. GUI, Add, Button, x10 y+20 w380 h20 gfavoriteButton, Select a default folder from which to browse download folder
  43. IniRead, folderFavorite, autosaversettings.ini, User Settings, iniFavorite, %A_Space%
  44. if(folderFavorite) ; Same as above for a set default location
  45. {
  46. GUI, Add, Text, x10 r2 w400 vupdateFavorite, Current default folder is: `n%folderFavorite%
  47. }
  48. else
  49. {
  50. GUI, Add, Text, x10 r2 w400 vupdateFavorite, There is no current default folder selected
  51. }
  52.  
  53. GUI, Add, Text, w400 y+10 Center, NOTE: make sure you are on page 1 of desired gallery before starting.
  54.  
  55. Gui, Show, W400 H250 Center, Online Reader Autodownloader by meterion
  56. return
  57.  
  58. startButton: ; Brings up folder select, saves download folder path to ini file, updates GUI
  59. IniRead, folderFavorite, autosaversettings.ini, User Settings, iniFavorite, %A_Space%
  60. FileSelectFolder, toIniStart, *%folderFavorite%, 3, Choose where to save images
  61. IniWrite, %toIniStart%, autosaversettings.ini, User Settings, iniStart
  62. folderStart := toIniStart
  63. GuiControl, , updateStart, Images will be downloaded to: `n%folderStart%
  64. return
  65.  
  66. pageButton: ; Need to submit value from GUI because the variable isn't being created here
  67. Gui, Submit, noHide
  68. GuiControl, , pageText, %numPages% pages to download
  69. return
  70.  
  71. favoriteButton: ; As above for the default folder path
  72. FileSelectFolder, toIniFavorite, *%folderFavorite%, 3, Choose a Preferred Default Folder
  73. IniWrite, %toIniFavorite%, autosaversettings.ini, User Settings, iniFavorite
  74. folderFavorite := toIniFavorite
  75. Guicontrol, , updateFavorite, Current default folder is: `n%folderFavorite%
  76. return
  77.  
  78. downloadButton: ; Where the magic happens
  79. Gui, Submit
  80. Gui, Destroy ; Ensures proper window is active
  81.  
  82. WinGetActiveStats, Title, Width, Height, X, Y
  83. 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.
  84. winYClick := Height/3
  85. 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.
  86. winYSClick := winYClick + 175
  87. loopNumber := numPages - 1 ; Since first page is downloaded out of loop, loopNumber is 1 less than page number
  88. numRename :=0 ; If rename option is selected, this will be used later. If it was used before, it will be reset to 0 now.
  89.  
  90. Sleep, 500 ; allow for user to lift hand from keyboard/mouse
  91. pageSaveCheck()
  92. Send, {F4} ; This brings you to the filepath edit box in chrome. Might need to be adjusted for other browsers.
  93. Send, ^a
  94. SendRaw, %folderStart% ; Enters directory from initial GUI
  95. loop, 4
  96. {
  97. 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.
  98. sleep, 200
  99. }
  100. Loop, %loopNumber% ; Now loops the rest of the pages
  101. {
  102. Click, %winXClick%, %winYClick% ; Advance page
  103. Sleep, pageDelay
  104. WinGetTitle, pageTitle, A ; used to escape "save as" from pagesavecheck loop
  105. pageSaveCheck()
  106. Send, {Enter} ; Save Image
  107. Sleep, saveDelay ; Needs some buffer time for the dialogue to exit before starting loop
  108. pageTitleCheck()
  109. }
  110. playTune()
  111. MsgBox, 0, Autosave Completed, %numPages% pages downloaded.
  112. return
  113.  
  114. pageSaveCheck() ; Does save image dialogue and any renaming
  115. {
  116. global ; setting scope to access/write global variables
  117. Loop ; infinfite loop until broken
  118. {
  119. Click, %winXClick%, %winYClick%, right ; Opening first page
  120. Click, %winXSClick%, %winYSClick% ; Save Image As
  121. WinWaitActive, Save As, , 1 ; Wait for Save window to open, attempt every second
  122. if ErrorLevel = 0 ; If dialogue successfully loads, exit loop
  123. break
  124. }
  125. if renamePages = 1
  126. {
  127. numRename := ++numRename
  128. numSend := SubStr("00" . numRename, -2)
  129. Send, %numSend%
  130. Sleep, saveDelay
  131. }
  132. }
  133. pageTitleCheck()
  134. {
  135. global
  136. Loop ; escape possible multiple save dialogues
  137. {
  138. WinGetTitle, matchTitle, A
  139. if (pageTitle = matchTitle)
  140. break
  141. Send, {Esc}
  142. Sleep, 100
  143. }
  144. }
  145. playTune()
  146. {
  147. 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]
  148. Random, toneStart, 1, 40 ; This part just plays a short chord and loads a dialogue box to show completion
  149. Random, jumpOne, 3, 4
  150. Random, jumpTwo, 3, 4
  151. SoundBeep, tones[ToneStart], 150
  152. SoundBeep, tones[ToneStart + jumpOne], 150
  153. SoundBeep, tones[ToneStart + jumpOne + jumpTwo], 150
  154. }
  155.  
  156. ^i:: ; If you just want to play tones
  157. playTune()
  158. return
Add Comment
Please, Sign In to add comment