module MangaFetch::Downloader
Public Instance Methods
download_image(src: nil, prefix: "/tmp", agent: nil)
click to toggle source
Download an image defined with `src` in the directory `prefix`. It uses `@agent` by default
# File lib/manga_fetch/downloader.rb, line 3 def download_image(src: nil, prefix: "/tmp", agent: nil) prefix ||= "/tmp" image = (agent || @agent).get src path = File.expand_path image.uri.to_s.split("/")[-3..-1].join("/"), prefix Dir.mkdir File.expand_path image.uri.to_s.split("/")[-3..-3].join("/"), prefix rescue nil Dir.mkdir File.expand_path image.uri.to_s.split("/")[-3..-2].join("/"), prefix rescue nil File.write path, image.body STDERR.puts "File [".blue + path.yellow + "] saved (".blue + path.yellow + ")".blue end