added preview video on s3

This commit is contained in:
Tyrel Souza 2014-05-29 14:34:52 -04:00
parent 784b083c05
commit eda5c25af2
5 changed files with 39 additions and 5 deletions

View File

@ -10,13 +10,33 @@ class AmazonCopy
puts "File #{videolisting.videocode} downloaded."
s3 = AWS::S3.new
obj = s3.buckets['digitalmarketingvideos'].objects["bvideos/#{videolisting.videocode}.mp4"]
obj = s3.buckets[ENV['VIDEO_BUCKET']].objects["bvideos/#{videolisting.videocode}.mp4"]
obj.write(file)
puts "File #{videolisting.videocode} uploaded."
ensure
file.close
file.unlink
end
file = Tempfile.new ["video_",".jpg"], "#{Rails.root}/tmp"
begin
file.write HTTParty.get(videolisting.get_preview_url).parsed_response.force_encoding("utf-8")
file.flush
puts "File #{videolisting.videocode} preview downloaded."
s3 = AWS::S3.new
obj = s3.buckets[ENV['VIDEO_BUCKET']].objects["bvideos_previews/#{videolisting.videocode}.jpg"]
obj.write(file)
puts "File #{videolisting.videocode} preview uploaded."
ensure
file.close
file.unlink
end
videolisting.on_s3 = true
videolisting.save
end
handle_asynchronously :download_video
end

View File

@ -9,11 +9,19 @@ class Videolisting < ActiveRecord::Base
after_initialize :set_defaults
def get_video_url
"http://video2.bettervideo.com/video/pro/MP4640x360/720.#{videocode}.mp4"
if on_s3
"http://s3.amazonaws.com/#{ENV['VIDEO_BUCKET']}/bvideos/#{videocode}.mp4"
else
"http://video2.bettervideo.com/video/pro/MP4640x360/720.#{videocode}.mp4"
end
end
def get_preview_url
"http://video2.bettervideo.com/video/pro/jpg640x360/720.#{videocode}.jpg"
if on_s3
"http://s3.amazonaws.com/#{ENV['VIDEO_BUCKET']}/bvideos_preview/#{videocode}.jpg"
else
"http://video2.bettervideo.com/video/pro/jpg640x360/720.#{videocode}.jpg"
end
end
def asseturls_array

View File

@ -25,7 +25,7 @@
<div class="video-js-responsive-container">
<video class="video-js vjs-blue-skin" id="bvVideo1" preload="auto" controls>
<source src="//video2.bettervideo.com/video/PRO/MP4640x360/720.<%= @videolisting.videocode %>.mp4" type="video/mp4"></source> <!-- Video URL goes here" -->
<source src="<%= @videolisting.get_video_url %>" type="video/mp4"></source> <!-- Video URL goes here" -->
</video>
</div>

View File

@ -0,0 +1,5 @@
class AddOnS3ToVideolisting < ActiveRecord::Migration
def change
add_column :videolistings, :on_s3, :boolean, default: nil
end
end

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140505153412) do
ActiveRecord::Schema.define(version: 20140529180650) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -113,6 +113,7 @@ ActiveRecord::Schema.define(version: 20140505153412) do
t.integer "campaign_id"
t.string "toneofvideo"
t.boolean "published"
t.boolean "on_s3"
end
end