meterion

Autohotkey Online Reader Autodownload Macro 2.0

May 1st, 2017
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.77 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. ; README
  5. ; A hacky AutoHotKey macro by meterion for idle downloading
  6. ; To use: Navigate to page 1 of desired gallery. Press Ctrl+q.
  7. ; Follow the prompt, leave computer alone as it does its thing (currently cannot function in background).
  8. ; Speed: ~1.5 minutes per 20 pages
  9. ; Press Ctrl+i for extra beeps lol (don't do this while it's running tho)
  10. ; NOTE: Makes an .ini file in the same directory it's used called "autosaversettings.ini"
  11.  
  12. pageDelay := 3000 ; Conservative ms delay to load pages
  13. saveDelay := 1000 ; Faster ms delay when entering/exiting dialogue window
  14. numPages = 0 ; Number of pages set to download: 0 by default
  15. 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]
  16. ; ^Chromatic tones for when it finishes
  17.  
  18. CoordMode, Mouse, Relative
  19. SetMouseDelay, 5
  20. setFormat, IntegerFast, d
  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.  
  35. Gui, Add, Checkbox, vrenamePages, Check to numerically rename files starting at 001
  36.  
  37. Gui, Add, Edit, x10 w50 vnumPages Number ; Set number of pages to download here
  38. Gui, Add, UpDown, gPagebutton, %numPages%
  39.  
  40. Gui, Add, Button, x+m yp w320 h20 gpageButton, Enter number of pages to download
  41. Gui, Add, Text, x10 w300 vpageText, %numPages% pages to download
  42.  
  43. GUI, Add, Button, x10 w380 h40 gdownloadButton, Begin Downloading
  44.  
  45. GUI, Add, Button, x10 y+20 w380 h20 gfavoriteButton, Select a default folder from which to browse download folder
  46. IniRead, folderFavorite, autosaversettings.ini, User Settings, iniFavorite, %A_Space%
  47. if(folderFavorite) ; Same as above for a set default location
  48. {
  49. GUI, Add, Text, x10 r2 w400 vupdateFavorite, Current default folder is: `n%folderFavorite%
  50. }
  51. else
  52. {
  53. GUI, Add, Text, x10 r2 w400 vupdateFavorite, There is no current default folder selected
  54. }
  55.  
  56. Gui, Show, W400 H250 Center, Online Reader Autodownloader by meterion
  57. return
  58.  
  59. startButton: ; Brings up folder select, saves download folder path to ini file, updates GUI
  60. IniRead, folderFavorite, autosaversettings.ini, User Settings, iniFavorite, %A_Space%
  61. FileSelectFolder, toIniStart, *%folderFavorite%, 3, Choose where to save images
  62. IniWrite, %toIniStart%, autosaversettings.ini, User Settings, iniStart
  63. folderStart := toIniStart
  64. GuiControl, , updateStart, Images will be downloaded to: `n%folderStart%
  65. return
  66.  
  67. pageButton: ; Need to submit value from GUI because the variable isn't being created here
  68. Gui, Submit, noHide
  69. GuiControl, , pageText, %numPages% pages to download
  70. return
  71.  
  72. favoriteButton: ; As above for the default folder path
  73. FileSelectFolder, toIniFavorite, *%folderFavorite%, 3, Choose a Preferred Default Folder
  74. IniWrite, %toIniFavorite%, autosaversettings.ini, User Settings, iniFavorite
  75. folderFavorite := toIniFavorite
  76. Guicontrol, , updateFavorite, Current default folder is: `n%folderFavorite%
  77. return
  78.  
  79. downloadButton: ; Where the magic happens
  80. Gui, Submit
  81. Gui, Destroy ; Ensures proper window is active
  82.  
  83. WinGetActiveStats, Title, Width, Height, X, Y
  84. 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.
  85. winYClick := Height/3
  86. 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.
  87. winYSClick := winYClick + 175
  88.  
  89. loopNumber := numPages - 1 ; Since first page is downloaded out of loop, loopNumber is 1 less than page number
  90. numRename :=0 ; If rename option is selected, this will be used later. If it was used before, it will be reset to 0 now.
  91.  
  92. Sleep, saveDelay ; allow for user to lift hand from keyboard/mouse
  93.  
  94. Click, %winXClick%, %winYClick%, right ; Opening first page
  95. Click, %winXSClick%, %winYSClick% ; Save Image As
  96. Sleep, saveDelay
  97.  
  98. 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.
  99. {
  100. numRename := ++numRename
  101. numSend := SubStr("00" . numRename, -2)
  102. Send, %numSend%
  103. Sleep, 100
  104. }
  105. Send, {F4} ; This brings you to the filepath edit box in chrome. Might need to be adjusted for other browsers.
  106. Send, ^a
  107. SendRaw, %folderStart% ; Enters directory from initial GUI
  108. loop, 4
  109. {
  110. 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.
  111. sleep, 100
  112. }
  113. Sleep, saveDelay
  114.  
  115. Loop, %loopNumber% ; Now loops the rest of the pages
  116. {
  117. Click, %winXClick%, %winYClick% ; Advance page
  118. Sleep, pageDelay ; Page Loading Time
  119. Click, %winXClick%, %winYClick%, right ; Right Click
  120. Click, %winXSClick%, %winYSClick% ; Save Image As
  121. Sleep, saveDelay ; Save dialogue loading time
  122. if renamePages = 1 ; See above note for info
  123. {
  124. numRename := ++numRename
  125. numSend := SubStr("00" . numRename, -2)
  126. Send, %numSend%
  127. Sleep, 100
  128. }
  129. Send, {Enter} ; Save Image
  130. Sleep, saveDelay ; Needs some buffer time for the dialogue to exit before starting loop
  131. }
  132.  
  133. Random, toneStart, 1, 40 ; This part just plays a short chord and loads a dialogue box to show completion
  134. Random, jumpOne, 3, 4
  135. Random, jumpTwo, 3, 4
  136. SoundBeep, tones[ToneStart], 150
  137. SoundBeep, tones[ToneStart + jumpOne], 150
  138. SoundBeep, tones[ToneStart + jumpOne + jumpTwo], 150
  139. MsgBox, 0, Autosave Completed, %numPages% pages downloaded.
  140. return
  141.  
  142. ^i:: ; If you just want to play tones (could probably be compressed in a function but whatever it's only used twice)
  143. Random, toneStart, 1, 40
  144. Random, jumpOne, 3, 4
  145. Random, jumpTwo, 3, 4
  146.  
  147. SoundBeep, tones[ToneStart], 150
  148. SoundBeep, tones[ToneStart + jumpOne], 150
  149. SoundBeep, tones[ToneStart + jumpOne + jumpTwo], 150
  150. return
Add Comment
Please, Sign In to add comment