-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathappleISO-downloader
executable file
·194 lines (147 loc) · 7.13 KB
/
appleISO-downloader
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/ruby
#
# ############################################################################
# Project: scripts (none)
# File...: appleISO-downloader
# Created: Wednesday, 2021/02/10-16:05:35
# Author.: @fbnmtz, ([email protected])
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Last Modified: Wednesday, 2023/04/19 - 04:30:08
# Modified By..: @fbnmtz, ([email protected])
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Version: 0.1.5.3
# ~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~·~·~·~·~·~·~·~~·~·~·~·~·~~·~·~·~·~·~·~·~
# Description:
# >
# ############################################################################
# HISTORY:
#
# ruby 2.7.1
# mechanize 2.7.6
require 'mechanize'
require 'colorize'
# use dots on Hashs
require 'hash_dot'
Hash.use_dot_syntax = true
# catalog with all apptle images (redirector to apple cdn)
URL="https://ipsw.me"
IDs = Hash.new
# browser agent
agent = Mechanize.new
# main page content
page = agent.get(URL)
# get all apple products
products = Array.new
page.search('.products').search(".product").each do |p|
data = Hash.new
data.link = p['href']
data.name = data.link.gsub("/product/","")
products.push(data)
end
products.each_with_index do |product, pi|
# open each product page
page = agent.get("#{URL}#{product.link}")
# save all models for this product
models = Array.new
page.search('.products').search(".product").each do |p|
data = Hash.new
data.link = p['href']
data.id = data.link.gsub('/',"")
data.name = p.text.strip.gsub(" ",".").gsub("(","").gsub(")","").gsub("/","")
IDs[ data.link.gsub('/',"").to_sym ] = data.name
# data[:link] = p['href']
# data[:id] = data[:link].gsub('/',"")
# data[:name] = p.text.strip.gsub(" ",".").gsub("(","").gsub(")","").gsub("/","")
# IDs[ data[:link].gsub('/',"").to_sym ] = data[:name]
models.push(data)
end
models.each_with_index do |model, mi|
# open each model page
images = Array.new
page = agent.get("#{URL}#{model[:link]}")
page.search('.table').search("tr").each do |p|
# save all information about restore images for this model/product
data = Hash.new
data.link = p['onclick'].split("=").last.gsub("'","").gsub(" ","").gsub(";","")
data.name = p.search('td')[1].text.strip.gsub(" ",".").gsub("(","").gsub(")","").gsub("/","")
data.size = p.search('td')[3].text.strip.gsub(" ","").gsub("B","").gsub(".",",")
data.filename = p.search('td')[4].text.gsub("(","-").gsub(")","-")
data.ios = data.filename.split("_")[1]
data.codename = data.filename.split("_")[2]
# data[:link] = p['onclick'].split("=").last.gsub("'","").gsub(" ","").gsub(";","")
# data[:name] = p.search('td')[1].text.strip.gsub(" ",".").gsub("(","").gsub(")","").gsub("/","")
# data[:size] = p.search('td')[3].text.strip.gsub(" ","").gsub("B","").gsub(".",",")
# data[:filename] = p.search('td')[4].text.gsub("(","-").gsub(")","-")
images.push(data)
end
puts "products:", products
puts "models:", models
puts "images:", images
images.each_with_index do |image, ii|
# API links
ipsw_download_link = 'https://api.ipsw.me/v4/ipsw'
device_pic_link = "https://ipsw.me/assets/devices/"
output_dir = "apple/#{product.name}/#{model.name}"
download_dir = "apple/#{product.name}/v#{image.ios}"
localFilename = image.filename.to_s.split("_").first
IDs.keys.each do |id|
localFilename = localFilename.gsub(id.to_s,"#{IDs[id]}")
end
localFilename = "#{localFilename}-#{image.ios}-#{image.codename}.ipsw"
# set linux cmds
mkdir_out = "mkdir -p #{output_dir}/"
wget_pic = "wget #{device_pic_link}#{model.link}.png -O #{output_dir}/#{model.name}.png"
wget_image2 = "wget #{ipsw_download_link}#{image.link} -O #{output_dir}/#{image.filename}"
wget_image = "wget #{ipsw_download_link}#{image.link} -O #{download_dir}/#{localFilename}"
# inspect cmds
# puts "\n\nproduct: #{product.name}\n#{mkdir_out}\n#{wget_image2}\n#{wget_pic }\noutput_dir:#{output_dir}\n\n".yellow
# create directories
`#{mkdir_out}`
# download device image 1
if ! File.file?(output_dir + "/#{model.name}.png" )
puts "\ndownloading device picture: #{model.name}\n".magenta
`#{wget_pic }`
end
# exit
print "\nproduct:#{product.name} (#{pi+1}/#{products.count}) -> model:#{model.name} (#{mi+1}/#{models.count}) image:#{image.name} (#{ii+1}/#{images.count}) ".blue
# download image
if ! File.file?("#{output_dir}/#{image.filename}")
# save link in text file
`echo "#{model.name}:#{image.name}:#{ipsw_download_link}#{image.link}" >> apple/#{product.name}/links.txt`
puts "downloading image (#{image.size})\n".green
`#{wget_image2}`
# `#{wget_image}`
else
print "\nremote-filename:#{image.filename} ".magenta
# print "\n",IDs
if ! File.file?("#{download_dir}/#{localFilename}")
print "\nlocal-filename.:#{localFilename}\n".yellow
mkdir_new = "mkdir -p #{download_dir}"
rename_file = "mv #{output_dir}/#{image.filename} #{download_dir}/#{localFilename}"
echo_file = "echo '#{ipsw_download_link}#{image.link}:#{image.filename}' >> #{download_dir}/#{localFilename}.txt"
commands = [ mkdir_new, rename_file, echo_file ]
commands.each do |cmd|
puts cmd
# `#{cmd}`
end
else
puts "\nimage #{model.name} already downloaded.\n".red
end
# size = `du -h #{output_dir}/#{image.filename}| aw 1`
# puts "image_size: #{image.size} == local_size: #{size}".blue
# ifs size == image.size
# else
# puts "\ndownloading image #{model.name} (#{image.name})\n".green
# `#{wget_image2}`
# end
puts "\nimage #{model.name} already downloaded.\n".red
end
puts "\nnext image..."
sleep 2
end
puts "\nnext model..."
sleep 2
end
puts "\nnext product..."
sleep 2
end