2014-05-29 17:27:02 +00:00
|
|
|
require 'httparty'
|
|
|
|
require 'tempfile'
|
|
|
|
|
|
|
|
class AmazonCopy
|
|
|
|
def download_video videolisting
|
|
|
|
file = Tempfile.new ["video_",".mp4"], "#{Rails.root}/tmp"
|
|
|
|
begin
|
|
|
|
file.write HTTParty.get(videolisting.get_video_url).parsed_response.force_encoding("utf-8")
|
|
|
|
file.flush
|
2014-05-29 17:56:37 +00:00
|
|
|
puts "File #{videolisting.videocode} downloaded."
|
|
|
|
|
|
|
|
s3 = AWS::S3.new
|
2014-05-29 18:04:39 +00:00
|
|
|
obj = s3.buckets['digitalmarketingvideos'].objects["bvideos/#{videolisting.videocode}.mp4"]
|
2014-05-29 17:56:37 +00:00
|
|
|
obj.write(file)
|
|
|
|
puts "File #{videolisting.videocode} uploaded."
|
2014-05-29 17:27:02 +00:00
|
|
|
ensure
|
|
|
|
file.close
|
2014-05-29 17:56:37 +00:00
|
|
|
file.unlink
|
2014-05-29 17:27:02 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
handle_asynchronously :download_video
|
|
|
|
end
|