-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNexusMods.rb
More file actions
87 lines (79 loc) · 2.65 KB
/
NexusMods.rb
File metadata and controls
87 lines (79 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
class NexusMods
@profile = Selenium::WebDriver::Firefox::Profile.new
class << self
def open_browser(link, download_directory)
init_browser(download_directory)
browser = Watir::Browser.new :firefox, profile: @profile
browser.goto(link)
return browser
end
def init_browser(download_directory)
@profile['browser.download.dir'] = download_directory
@profile['browser.download.folderList'] = 2
@profile['browser.download.manager.showWhenStarting'] = false
@profile['browser.helperApps.neverAsk.saveToDisk'] = 'application/x-rar-compressed, application/x-7z-compressed, application/zip'
end
def login(download_directory)
browser = open_browser("nexusmods.com", download_directory)
puts "Press Enter when logged in"
gets
return browser
end
def find_download_button (browser)
browser.li.wait_until_present
urls = browser.lis.to_a
urls.each do |url|
if url.id.include?'action-manual'
download_button = url.children[0].children[0]
return download_button
end
end
end
def get_latest_file(download_directory)
Dir.chdir(download_directory)
while !Dir.glob(download_directory + "/*.part").empty?
sleep(5)
end
file_directory = Dir.glob(download_directory + "/*.*").max_by {|f| File.mtime(f)}
return file_directory
end
def append_file(number, download_directory)
file_directory = get_latest_file(download_directory)
directory_parts = file_directory.split('/')
filename = number.to_s + "_" + directory_parts.last
begin
File.rename(directory_parts.last, filename)
rescue
binding.pry
end
end
def download(links, link_numbers, download_directory)
browser = login(download_directory)
combined_links = links.zip(link_numbers)
combined_links.each do |link, link_number|
begin
browser.goto(link)
rescue Net::ReadTimeout
puts "page taking too long to load, please check and press enter to continue"
gets
end
download_button = find_download_button(browser)
begin
download_button.click
rescue
puts "Cant click/find the download button. Usually making your browser fullscreen resolves this. Press enter to retry and s to skip"
tmp = gets
tmp.chomp
if tmp != 's'
retry
else
next #fucking hipster ruby with no continue keyword
end
end
sleep(5)
puts link_number
append_file(link_number, download_directory)
end
end
end
end