lib/subtitle.rb in undertexter-0.1.8 vs lib/subtitle.rb in undertexter-0.1.9
- old
+ new
@@ -8,11 +8,15 @@
def initialize(args)
args.keys.each { |name| instance_variable_set "@" + name.to_s, args[name] }
end
def url
- @language == :english ? "http://eng.undertexter.se/subtitle.php?id=#{id}" : "http://undertexter.se/laddatext.php?id=#{id}"
+ if @language == :english
+ "http://eng.undertexter.se/subtitle.php?id=#{id}"
+ else
+ "http://undertexter.se/laddatext.php?id=#{id}"
+ end
end
# Downloading the file and saves it disk
def download!(args = {})
if args[:to].nil?
@@ -21,11 +25,11 @@
else
dir = generate_custom_file_path(args)
file_name = "#{dir}/#{generate_file_name}"
end
- data = RestClient.get(self.url, :timeout => 10) rescue nil
+ data = RestClient.get(self.url, :timeout => 10)
file = File.new(file_name, 'w')
file.write(data)
file.close
type = Mimer.identify(file_name)
@@ -47,10 +51,10 @@
return new_file_name
end
private
def id
- @details.match(/id=(\d+)/)[1]
+ @details.match(/^http:\/\/www\.undertexter\.se\/(\d+)\/$/)[1]
end
def generate_file_name
(0...30).map{65.+(rand(25)).chr}.join.downcase
end
\ No newline at end of file