class Subfinder::Parser::Download
Download
subtitle files from Internet
Public Class Methods
new(url)
click to toggle source
# File lib/subfinder/parser/download.rb, line 7 def initialize(url) @url = url end
Public Instance Methods
response_is_healthy?(res)
click to toggle source
# File lib/subfinder/parser/download.rb, line 25 def response_is_healthy?(res) if res.code != 200 Logger.info "Error when downloading '#{@url}'\n resposnse code: #{res.code}\n".red return false elsif res.body.include? 'An error occurred while processing your request.' Logger.info "Error downloading '#{@url}'. Try Again in few seconds".red return false else true end end
save()
click to toggle source
# File lib/subfinder/parser/download.rb, line 11 def save res = RestClient.get @url return false unless @url =~ URI::DEFAULT_PARSER.make_regexp return false unless response_is_healthy? res file_name = res.headers[:content_disposition].split('=')[1] File.write("#{Config.working_dir}/#{file_name}", res.body) Logger.info "Downloaded to #{Config.working_dir}/#{file_name}" true rescue StandardError => e Logger.info "Error when downloading '#{@url}'\n Error message: #{e}\n".red false end