meterion

Autohotkey Online Reader Autodownload Macro 2.6

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