From f6d957a25c007a1ab6de2144ee110d8b1d905dcb Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Thu, 29 May 2014 13:27:02 -0400 Subject: [PATCH] downloading file from vidpush to local box. --- Gemfile | 4 ++++ Gemfile.lock | 21 +++++++++++++++++++++ app/controllers/videolistings_controller.rb | 6 ++++++ app/models/amazon_copy.rb | 20 ++++++++++++++++++++ config.ru | 2 +- config/environment.rb | 2 ++ config/routes.rb | 2 ++ 7 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 app/models/amazon_copy.rb diff --git a/Gemfile b/Gemfile index 90c7c74..8cdb31e 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,8 @@ ruby '2.1.0' gem 'airbrake' gem 'coffee-rails' gem 'delayed_job_active_record', '>= 4.0.0' +gem 'delayed_job_web' +gem 'daemons' gem 'email_validator' gem 'flutie' gem 'high_voltage' @@ -27,6 +29,8 @@ gem 'zeroclipboard-rails' gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git' gem 'asset_sync' gem 'angularjs-rails' +gem 'undertaker' # Thanks Brian +gem 'httparty' group :development do gem 'foreman' diff --git a/Gemfile.lock b/Gemfile.lock index 5791661..c93f421 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -90,6 +90,7 @@ GEM coffee-script-source (1.7.0) crack (0.4.2) safe_yaml (~> 1.0.0) + daemons (1.1.9) database_cleaner (1.2.0) debug_inspector (0.0.2) delayed_job (4.0.1) @@ -97,6 +98,10 @@ GEM delayed_job_active_record (4.0.1) activerecord (>= 3.0, < 4.2) 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) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -143,6 +148,9 @@ GEM formatador (0.2.4) high_voltage (2.1.0) hike (1.2.3) + httparty (0.13.1) + json (~> 1.8) + multi_xml (>= 0.5.2) i18n (0.6.9) jbuilder (2.0.6) activesupport (>= 3.0.0, < 5) @@ -162,6 +170,7 @@ GEM mini_portile (0.5.3) minitest (5.3.3) multi_json (1.9.3) + multi_xml (0.5.5) net-scp (1.2.1) net-ssh (>= 2.6.5) net-ssh (2.9.0) @@ -206,6 +215,9 @@ GEM rake (10.3.1) recipient_interceptor (0.1.2) mail + redis (3.0.7) + redis-namespace (1.4.1) + redis (~> 3.0.4) rspec-core (2.14.8) rspec-expectations (2.14.5) diff-lcs (>= 1.1.3, < 2.0) @@ -248,6 +260,7 @@ GEM actionpack (>= 3.0) activesupport (>= 3.0) sprockets (~> 2.8) + terminal-table (1.4.5) thor (0.19.1) thread_safe (0.3.3) tilt (1.4.1) @@ -263,6 +276,10 @@ GEM uglifier (2.5.0) execjs (>= 0.3.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) kgio (~> 2.6) rack @@ -293,8 +310,10 @@ DEPENDENCIES capybara-webkit (>= 1.0.0) cocoon! coffee-rails + daemons database_cleaner delayed_job_active_record (>= 4.0.0) + delayed_job_web devise dotenv-rails email_validator @@ -302,6 +321,7 @@ DEPENDENCIES flutie foreman high_voltage + httparty jbuilder jquery-rails launchy @@ -322,6 +342,7 @@ DEPENDENCIES timecop title uglifier + undertaker unicorn webmock zeroclipboard-rails diff --git a/app/controllers/videolistings_controller.rb b/app/controllers/videolistings_controller.rb index e5874f2..b067617 100644 --- a/app/controllers/videolistings_controller.rb +++ b/app/controllers/videolistings_controller.rb @@ -9,12 +9,18 @@ class VideolistingsController < ApplicationController @videolisting.published = true @videolisting.save @message = "Campaign Published Successfully." + + download_video @videolisting else @message = "Error: Campaign Not Published." end end + + + + def show @videolisting end diff --git a/app/models/amazon_copy.rb b/app/models/amazon_copy.rb new file mode 100644 index 0000000..c30b18d --- /dev/null +++ b/app/models/amazon_copy.rb @@ -0,0 +1,20 @@ +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 + ensure + file.close + end + + + file.unlink + + end + handle_asynchronously :download_video +end \ No newline at end of file diff --git a/config.ru b/config.ru index 5bc2a61..c7d79bd 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,4 @@ # This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) -run Rails.application +run Rails.application \ No newline at end of file diff --git a/config/environment.rb b/config/environment.rb index ed437e9..1e1b810 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -1,6 +1,8 @@ # Load the Rails application. require File.expand_path('../application', __FILE__) +Encoding.default_external = Encoding::UTF_8 +Encoding.default_internal = Encoding::UTF_8 # Initialize the Rails application. Vidpush::Application.initialize! diff --git a/config/routes.rb b/config/routes.rb index 242f49c..02fb50f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -13,4 +13,6 @@ Vidpush::Application.routes.draw do end end end + + match "/djweb" => DelayedJobWeb, :anchor => false, via: [:get, :post] end