Merge pull request #1 from propelmarketing/download_files
Download files and upload to S3
This commit is contained in:
commit
834648bd57
5
Gemfile
5
Gemfile
@ -5,6 +5,8 @@ ruby '2.1.0'
|
|||||||
gem 'airbrake'
|
gem 'airbrake'
|
||||||
gem 'coffee-rails'
|
gem 'coffee-rails'
|
||||||
gem 'delayed_job_active_record', '>= 4.0.0'
|
gem 'delayed_job_active_record', '>= 4.0.0'
|
||||||
|
gem 'delayed_job_web'
|
||||||
|
gem 'daemons'
|
||||||
gem 'email_validator'
|
gem 'email_validator'
|
||||||
gem 'flutie'
|
gem 'flutie'
|
||||||
gem 'high_voltage'
|
gem 'high_voltage'
|
||||||
@ -27,6 +29,9 @@ gem 'zeroclipboard-rails'
|
|||||||
gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'
|
gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'
|
||||||
gem 'asset_sync'
|
gem 'asset_sync'
|
||||||
gem 'angularjs-rails'
|
gem 'angularjs-rails'
|
||||||
|
gem 'undertaker' # Thanks Brian
|
||||||
|
gem 'httparty'
|
||||||
|
gem 'aws-sdk'
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
gem 'foreman'
|
gem 'foreman'
|
||||||
|
25
Gemfile.lock
25
Gemfile.lock
@ -60,6 +60,9 @@ GEM
|
|||||||
activemodel
|
activemodel
|
||||||
fog (>= 1.8.0)
|
fog (>= 1.8.0)
|
||||||
awesome_print (1.2.0)
|
awesome_print (1.2.0)
|
||||||
|
aws-sdk (1.41.0)
|
||||||
|
json (~> 1.4)
|
||||||
|
nokogiri (>= 1.4.4)
|
||||||
bcrypt (3.1.7)
|
bcrypt (3.1.7)
|
||||||
better_errors (1.1.0)
|
better_errors (1.1.0)
|
||||||
coderay (>= 1.0.0)
|
coderay (>= 1.0.0)
|
||||||
@ -90,6 +93,7 @@ GEM
|
|||||||
coffee-script-source (1.7.0)
|
coffee-script-source (1.7.0)
|
||||||
crack (0.4.2)
|
crack (0.4.2)
|
||||||
safe_yaml (~> 1.0.0)
|
safe_yaml (~> 1.0.0)
|
||||||
|
daemons (1.1.9)
|
||||||
database_cleaner (1.2.0)
|
database_cleaner (1.2.0)
|
||||||
debug_inspector (0.0.2)
|
debug_inspector (0.0.2)
|
||||||
delayed_job (4.0.1)
|
delayed_job (4.0.1)
|
||||||
@ -97,6 +101,10 @@ GEM
|
|||||||
delayed_job_active_record (4.0.1)
|
delayed_job_active_record (4.0.1)
|
||||||
activerecord (>= 3.0, < 4.2)
|
activerecord (>= 3.0, < 4.2)
|
||||||
delayed_job (>= 3.0, < 4.1)
|
delayed_job (>= 3.0, < 4.1)
|
||||||
|
delayed_job_web (1.2.9)
|
||||||
|
activerecord (> 3.0.0)
|
||||||
|
delayed_job (> 2.0.3)
|
||||||
|
sinatra (>= 1.4.4)
|
||||||
devise (3.2.4)
|
devise (3.2.4)
|
||||||
bcrypt (~> 3.0)
|
bcrypt (~> 3.0)
|
||||||
orm_adapter (~> 0.1)
|
orm_adapter (~> 0.1)
|
||||||
@ -143,6 +151,9 @@ GEM
|
|||||||
formatador (0.2.4)
|
formatador (0.2.4)
|
||||||
high_voltage (2.1.0)
|
high_voltage (2.1.0)
|
||||||
hike (1.2.3)
|
hike (1.2.3)
|
||||||
|
httparty (0.13.1)
|
||||||
|
json (~> 1.8)
|
||||||
|
multi_xml (>= 0.5.2)
|
||||||
i18n (0.6.9)
|
i18n (0.6.9)
|
||||||
jbuilder (2.0.6)
|
jbuilder (2.0.6)
|
||||||
activesupport (>= 3.0.0, < 5)
|
activesupport (>= 3.0.0, < 5)
|
||||||
@ -162,6 +173,7 @@ GEM
|
|||||||
mini_portile (0.5.3)
|
mini_portile (0.5.3)
|
||||||
minitest (5.3.3)
|
minitest (5.3.3)
|
||||||
multi_json (1.9.3)
|
multi_json (1.9.3)
|
||||||
|
multi_xml (0.5.5)
|
||||||
net-scp (1.2.1)
|
net-scp (1.2.1)
|
||||||
net-ssh (>= 2.6.5)
|
net-ssh (>= 2.6.5)
|
||||||
net-ssh (2.9.0)
|
net-ssh (2.9.0)
|
||||||
@ -206,6 +218,9 @@ GEM
|
|||||||
rake (10.3.1)
|
rake (10.3.1)
|
||||||
recipient_interceptor (0.1.2)
|
recipient_interceptor (0.1.2)
|
||||||
mail
|
mail
|
||||||
|
redis (3.0.7)
|
||||||
|
redis-namespace (1.4.1)
|
||||||
|
redis (~> 3.0.4)
|
||||||
rspec-core (2.14.8)
|
rspec-core (2.14.8)
|
||||||
rspec-expectations (2.14.5)
|
rspec-expectations (2.14.5)
|
||||||
diff-lcs (>= 1.1.3, < 2.0)
|
diff-lcs (>= 1.1.3, < 2.0)
|
||||||
@ -248,6 +263,7 @@ GEM
|
|||||||
actionpack (>= 3.0)
|
actionpack (>= 3.0)
|
||||||
activesupport (>= 3.0)
|
activesupport (>= 3.0)
|
||||||
sprockets (~> 2.8)
|
sprockets (~> 2.8)
|
||||||
|
terminal-table (1.4.5)
|
||||||
thor (0.19.1)
|
thor (0.19.1)
|
||||||
thread_safe (0.3.3)
|
thread_safe (0.3.3)
|
||||||
tilt (1.4.1)
|
tilt (1.4.1)
|
||||||
@ -263,6 +279,10 @@ GEM
|
|||||||
uglifier (2.5.0)
|
uglifier (2.5.0)
|
||||||
execjs (>= 0.3.0)
|
execjs (>= 0.3.0)
|
||||||
json (>= 1.8.0)
|
json (>= 1.8.0)
|
||||||
|
undertaker (0.1.0)
|
||||||
|
json (>= 1.4.6)
|
||||||
|
redis-namespace (>= 0.10.0)
|
||||||
|
terminal-table (>= 1.4.2)
|
||||||
unicorn (4.8.2)
|
unicorn (4.8.2)
|
||||||
kgio (~> 2.6)
|
kgio (~> 2.6)
|
||||||
rack
|
rack
|
||||||
@ -286,6 +306,7 @@ DEPENDENCIES
|
|||||||
annotate!
|
annotate!
|
||||||
asset_sync
|
asset_sync
|
||||||
awesome_print
|
awesome_print
|
||||||
|
aws-sdk
|
||||||
better_errors
|
better_errors
|
||||||
binding_of_caller
|
binding_of_caller
|
||||||
bootstrap-sass (< 3.1)
|
bootstrap-sass (< 3.1)
|
||||||
@ -293,8 +314,10 @@ DEPENDENCIES
|
|||||||
capybara-webkit (>= 1.0.0)
|
capybara-webkit (>= 1.0.0)
|
||||||
cocoon!
|
cocoon!
|
||||||
coffee-rails
|
coffee-rails
|
||||||
|
daemons
|
||||||
database_cleaner
|
database_cleaner
|
||||||
delayed_job_active_record (>= 4.0.0)
|
delayed_job_active_record (>= 4.0.0)
|
||||||
|
delayed_job_web
|
||||||
devise
|
devise
|
||||||
dotenv-rails
|
dotenv-rails
|
||||||
email_validator
|
email_validator
|
||||||
@ -302,6 +325,7 @@ DEPENDENCIES
|
|||||||
flutie
|
flutie
|
||||||
foreman
|
foreman
|
||||||
high_voltage
|
high_voltage
|
||||||
|
httparty
|
||||||
jbuilder
|
jbuilder
|
||||||
jquery-rails
|
jquery-rails
|
||||||
launchy
|
launchy
|
||||||
@ -322,6 +346,7 @@ DEPENDENCIES
|
|||||||
timecop
|
timecop
|
||||||
title
|
title
|
||||||
uglifier
|
uglifier
|
||||||
|
undertaker
|
||||||
unicorn
|
unicorn
|
||||||
webmock
|
webmock
|
||||||
zeroclipboard-rails
|
zeroclipboard-rails
|
||||||
|
@ -9,12 +9,18 @@ class VideolistingsController < ApplicationController
|
|||||||
@videolisting.published = true
|
@videolisting.published = true
|
||||||
@videolisting.save
|
@videolisting.save
|
||||||
@message = "Campaign Published Successfully."
|
@message = "Campaign Published Successfully."
|
||||||
|
|
||||||
|
download_video @videolisting
|
||||||
else
|
else
|
||||||
@message = "Error: Campaign Not Published."
|
@message = "Error: Campaign Not Published."
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@videolisting
|
@videolisting
|
||||||
end
|
end
|
||||||
|
40
app/models/amazon_copy.rb
Normal file
40
app/models/amazon_copy.rb
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
require 'httparty'
|
||||||
|
require 'tempfile'
|
||||||
|
|
||||||
|
class AmazonCopy
|
||||||
|
def download_video videolisting
|
||||||
|
if not videolisting.on_s3
|
||||||
|
download_file_and_upload_to_s3 videolisting.get_video_url,
|
||||||
|
videolisting.videocode,
|
||||||
|
"mp4",
|
||||||
|
"bvideos"
|
||||||
|
|
||||||
|
download_file_and_upload_to_s3 videolisting.get_preview_url,
|
||||||
|
videolisting.videocode,
|
||||||
|
"mp4",
|
||||||
|
"bvideos_preview"
|
||||||
|
|
||||||
|
videolisting.on_s3 = true
|
||||||
|
videolisting.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
handle_asynchronously :download_video
|
||||||
|
|
||||||
|
|
||||||
|
def download_file_and_upload_to_s3 url, videocode, extension, prefix
|
||||||
|
file = Tempfile.new ["video_", ".#{extension}"], "#{Rails.root}/tmp"
|
||||||
|
begin
|
||||||
|
file.write HTTParty.get(url).parsed_response.force_encoding("utf-8")
|
||||||
|
file.flush
|
||||||
|
|
||||||
|
s3 = AWS::S3.new
|
||||||
|
obj = s3.buckets[ENV['VIDEO_BUCKET']].objects["#{prefix}/#{videocode}.mp4"]
|
||||||
|
obj.write(file)
|
||||||
|
|
||||||
|
ensure
|
||||||
|
file.close
|
||||||
|
file.unlink
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -9,11 +9,19 @@ class Videolisting < ActiveRecord::Base
|
|||||||
after_initialize :set_defaults
|
after_initialize :set_defaults
|
||||||
|
|
||||||
def get_video_url
|
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
|
end
|
||||||
|
|
||||||
def get_preview_url
|
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
|
end
|
||||||
|
|
||||||
def asseturls_array
|
def asseturls_array
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
<div class="video-js-responsive-container">
|
<div class="video-js-responsive-container">
|
||||||
<video class="video-js vjs-blue-skin" id="bvVideo1" preload="auto" controls>
|
<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>
|
</video>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# This file is used by Rack-based servers to start the application.
|
# This file is used by Rack-based servers to start the application.
|
||||||
|
|
||||||
require ::File.expand_path('../config/environment', __FILE__)
|
require ::File.expand_path('../config/environment', __FILE__)
|
||||||
run Rails.application
|
run Rails.application
|
@ -1,6 +1,8 @@
|
|||||||
# Load the Rails application.
|
# Load the Rails application.
|
||||||
require File.expand_path('../application', __FILE__)
|
require File.expand_path('../application', __FILE__)
|
||||||
|
|
||||||
|
Encoding.default_external = Encoding::UTF_8
|
||||||
|
Encoding.default_internal = Encoding::UTF_8
|
||||||
# Initialize the Rails application.
|
# Initialize the Rails application.
|
||||||
Vidpush::Application.initialize!
|
Vidpush::Application.initialize!
|
||||||
|
|
||||||
|
@ -13,4 +13,6 @@ Vidpush::Application.routes.draw do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
match "/djweb" => DelayedJobWeb, :anchor => false, via: [:get, :post]
|
||||||
end
|
end
|
||||||
|
5
db/migrate/20140529180650_add_on_s3_to_videolisting.rb
Normal file
5
db/migrate/20140529180650_add_on_s3_to_videolisting.rb
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class AddOnS3ToVideolisting < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
add_column :videolistings, :on_s3, :boolean, default: nil
|
||||||
|
end
|
||||||
|
end
|
@ -11,7 +11,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@ -113,6 +113,7 @@ ActiveRecord::Schema.define(version: 20140505153412) do
|
|||||||
t.integer "campaign_id"
|
t.integer "campaign_id"
|
||||||
t.string "toneofvideo"
|
t.string "toneofvideo"
|
||||||
t.boolean "published"
|
t.boolean "published"
|
||||||
|
t.boolean "on_s3"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user