10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/instagram_crawler/file.rb', line 10
def download(url, dir_name, file_name)
return unless Config.download
binary_data, mime_type = get_binary_data(url)
extname =
case mime_type
when "video/mp4" then ".mp4"
when "image/jpeg" then ".jpeg"
end
dir_path = "#{Config.base_path}/#{dir_name}"
FileUtils.mkdir_p(dir_path) unless Dir.exist?(dir_path)
file_path = "#{dir_path}/#{file_name}#{extname}"
File.open(file_path, 'wb') do |f|
f.write binary_data
end
end
|