meterion

Autohotkey Online Reader Autodownload Macro 2.3

May 13th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.88 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.3 Changelog: Changed pageSaveCheck to continually re-check if right-click is too early (no save image as dialogue selectable). Adjusted tempo to be faster. Possible problems with save image as dialogue being selected multiple times--this will be corrected in the future, likely through use of grabbing the page's name and hitting escape until you return to it after saving an image. This would also potentially bring a significant reduction in download times when first right-click is slightly too early.
  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 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. pageSaveCheck()
  105. Send, {Enter} ; Save Image
  106. Sleep, saveDelay ; Needs some buffer time for the dialogue to exit before starting loop
  107. }
  108. playTune()
  109. MsgBox, 0, Autosave Completed, %numPages% pages downloaded.
  110. return
  111.  
  112. pageSaveCheck() ; Does save image dialogue and any renaming
  113. {
  114. global ; setting scope to access/write global variables
  115. loop, 10 ; every page should load after 70 seconds
  116. {
  117. Click, %winXClick%, %winYClick%, right ; Opening first page
  118. Click, %winXSClick%, %winYSClick% ; Save Image As
  119. WinWaitActive, Save As, , 7 ; Wait for Save window to open (10 second delay to prevent multi-saves)
  120. if ErrorLevel = 0 ; If dialogue successfully loads, exit loop
  121. break
  122. }
  123. if renamePages = 1
  124. {
  125. numRename := ++numRename
  126. numSend := SubStr("00" . numRename, -2)
  127. Send, %numSend%
  128. Sleep, 200
  129. }
  130. }
  131.  
  132. playTune()
  133. {
  134. 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]
  135. Random, toneStart, 1, 40 ; This part just plays a short chord and loads a dialogue box to show completion
  136. Random, jumpOne, 3, 4
  137. Random, jumpTwo, 3, 4
  138. SoundBeep, tones[ToneStart], 150
  139. SoundBeep, tones[ToneStart + jumpOne], 150
  140. SoundBeep, tones[ToneStart + jumpOne + jumpTwo], 150
  141. }
  142.  
  143. ^i:: ; If you just want to play tones
  144. playTune()
  145. return
Add Comment
Please, Sign In to add comment