Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 6f25a908581ebdf17635a1f53e351d7c9f148bb1 @amardaxini committed Mar 7, 2011
Showing with 11,754 additions and 0 deletions.
  1. +10 −0 .gitignore
  2. +36 −0 Gemfile
  3. +110 −0 Gemfile.lock
  4. +15 −0 README
  5. +7 −0 Rakefile
  6. +4 −0 app/controllers/application_controller.rb
  7. +6 −0 app/controllers/home_controller.rb
  8. +57 −0 app/controllers/videos_controller.rb
  9. +36 −0 app/helpers/application_helper.rb
  10. +2 −0 app/helpers/home_helper.rb
  11. +2 −0 app/helpers/videos_helper.rb
  12. +28 −0 app/models/encoder_job.rb
  13. +9 −0 app/models/user.rb
  14. +42 −0 app/models/video.rb
  15. +12 −0 app/views/devise/confirmations/new.html.erb
  16. +5 −0 app/views/devise/mailer/confirmation_instructions.html.erb
  17. +8 −0 app/views/devise/mailer/reset_password_instructions.html.erb
  18. +7 −0 app/views/devise/mailer/unlock_instructions.html.erb
  19. +16 −0 app/views/devise/passwords/edit.html.erb
  20. +12 −0 app/views/devise/passwords/new.html.erb
  21. +28 −0 app/views/devise/registrations/edit.html.erb
  22. +19 −0 app/views/devise/registrations/new.html.erb
  23. +17 −0 app/views/devise/sessions/new.html.erb
  24. +19 −0 app/views/devise/shared/_links.erb
  25. +12 −0 app/views/devise/unlocks/new.html.erb
  26. +8 −0 app/views/home/index.html.erb
  27. +92 −0 app/views/layouts/application.html.erb
  28. +20 −0 app/views/videos/_form.html.erb
  29. +19 −0 app/views/videos/index.html.erb
  30. +5 −0 app/views/videos/new.html.erb
  31. +4 −0 config.ru
  32. +42 −0 config/application.rb
  33. +13 −0 config/boot.rb
  34. +39 −0 config/database.yml
  35. +6 −0 config/environment.rb
  36. +28 −0 config/environments/development.rb
  37. +49 −0 config/environments/production.rb
  38. +35 −0 config/environments/test.rb
  39. +7 −0 config/initializers/backtrace_silencers.rb
  40. +142 −0 config/initializers/devise.rb
  41. +10 −0 config/initializers/inflections.rb
  42. +15 −0 config/initializers/mime_types.rb
  43. +7 −0 config/initializers/secret_token.rb
  44. +8 −0 config/initializers/session_store.rb
  45. +39 −0 config/locales/devise.en.yml
  46. +5 −0 config/locales/en.yml
  47. +69 −0 config/routes.rb
  48. +26 −0 db/migrate/20110304073725_devise_create_users.rb
  49. +9 −0 db/migrate/20110304083728_add_name_to_users.rb
  50. +17 −0 db/migrate/20110304084617_create_videos.rb
  51. +45 −0 db/schema.rb
  52. +7 −0 db/seeds.rb
  53. +2 −0 doc/README_FOR_APP
  54. 0 lib/tasks/.gitkeep
  55. +26 −0 nginx.conf.sample
  56. +26 −0 public/404.html
  57. +26 −0 public/422.html
  58. +26 −0 public/500.html
  59. 0 public/favicon.ico
  60. BIN public/images/rails.png
  61. 0 public/javascripts/.gitkeep
  62. +3 −0 public/javascripts/application.js
  63. +7,179 −0 public/javascripts/jquery.js
  64. +169 −0 public/javascripts/rails.js
  65. +1,758 −0 public/javascripts/video.js
  66. +5 −0 public/robots.txt
  67. 0 public/stylesheets/.gitkeep
  68. +258 −0 public/stylesheets/application.css
  69. +89 −0 public/stylesheets/base.css
  70. +429 −0 public/stylesheets/grid.css
  71. +47 −0 public/stylesheets/reset.css
  72. +56 −0 public/stylesheets/scaffold.css
  73. +242 −0 public/stylesheets/video-js.css
  74. +6 −0 script/rails
  75. +11 −0 test/fixtures/users.yml
  76. +7 −0 test/fixtures/videos.yml
  77. +9 −0 test/functional/home_controller_test.rb
  78. +49 −0 test/functional/videos_controller_test.rb
  79. +9 −0 test/performance/browsing_test.rb
  80. +13 −0 test/test_helper.rb
  81. +4 −0 test/unit/helpers/home_helper_test.rb
  82. +4 −0 test/unit/helpers/videos_helper_test.rb
  83. +8 −0 test/unit/user_test.rb
  84. +8 −0 test/unit/video_test.rb
  85. 0 tmp/restart.txt
  86. 0 vendor/plugins/.gitkeep
@@ -0,0 +1,10 @@
+.bundle
+db/*.sqlite3
+log/*.log
+tmp/**/*
+.idea/
+.idea/*
+attachments/
+attachments/*
+temp_files/
+temp_files/*
36 Gemfile
@@ -0,0 +1,36 @@
+source 'http://rubygems.org'
+
+gem 'rails', '3.0.3'
+gem 'devise'
+gem 'paperclip'
+gem 'mimetype-fu',:require=>'mimetype_fu'
+
+# Bundle edge Rails instead:
+# gem 'rails', :git => 'git://github.com/rails/rails.git'
+
+gem 'mysql2'
+gem 'stalker'
+
+# Use unicorn as the web server
+# gem 'unicorn'
+
+# Deploy with Capistrano
+# gem 'capistrano'
+
+# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
+# gem 'ruby-debug'
+# gem 'ruby-debug19'
+
+# Bundle the extra gems:
+# gem 'bj'
+# gem 'nokogiri'
+# gem 'sqlite3-ruby', :require => 'sqlite3'
+# gem 'aws-s3', :require => 'aws/s3'
+
+# Bundle gems for the local environment. Make sure to
+# put test-only gems in this group so their generators
+# and rake tasks are available in development mode:
+group :development do
+ gem 'ruby-debug'
+ gem 'mongrel'
+end
@@ -0,0 +1,110 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.3)
+ actionpack (= 3.0.3)
+ mail (~> 2.2.9)
+ actionpack (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.4)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.13)
+ rack-test (~> 0.5.6)
+ tzinfo (~> 0.3.23)
+ activemodel (3.0.3)
+ activesupport (= 3.0.3)
+ builder (~> 2.1.2)
+ i18n (~> 0.4)
+ activerecord (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.3)
+ activemodel (= 3.0.3)
+ activesupport (= 3.0.3)
+ activesupport (3.0.3)
+ arel (2.0.6)
+ bcrypt-ruby (2.1.2)
+ beanstalk-client (1.1.0)
+ builder (2.1.2)
+ cgi_multipart_eof_fix (2.5.0)
+ columnize (0.3.2)
+ daemons (1.1.0)
+ devise (1.1.5)
+ bcrypt-ruby (~> 2.1.2)
+ warden (~> 1.0.2)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ fastthread (1.0.7)
+ gem_plugin (0.2.3)
+ i18n (0.5.0)
+ json_pure (1.5.1)
+ linecache (0.43)
+ mail (2.2.14)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.16)
+ mimetype-fu (0.1.2)
+ mongrel (1.1.5)
+ cgi_multipart_eof_fix (>= 2.4)
+ daemons (>= 1.0.3)
+ fastthread (>= 1.0.1)
+ gem_plugin (>= 0.2.3)
+ mysql2 (0.2.6)
+ paperclip (2.3.8)
+ activerecord
+ activesupport
+ polyglot (0.3.1)
+ rack (1.2.1)
+ rack-mount (0.6.13)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.3)
+ actionmailer (= 3.0.3)
+ actionpack (= 3.0.3)
+ activerecord (= 3.0.3)
+ activeresource (= 3.0.3)
+ activesupport (= 3.0.3)
+ bundler (~> 1.0)
+ railties (= 3.0.3)
+ railties (3.0.3)
+ actionpack (= 3.0.3)
+ activesupport (= 3.0.3)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.8.7)
+ ruby-debug (0.10.4)
+ columnize (>= 0.1)
+ ruby-debug-base (~> 0.10.4.0)
+ ruby-debug-base (0.10.4)
+ linecache (>= 0.3)
+ stalker (0.6.1)
+ beanstalk-client
+ json_pure
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.23)
+ warden (1.0.3)
+ rack (>= 1.0.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ devise
+ mimetype-fu
+ mongrel
+ mysql2
+ paperclip
+ rails (= 3.0.3)
+ ruby-debug
+ stalker
15 README
@@ -0,0 +1,15 @@
+# uploading file using nginx paperclip protected
+
+# sudo chown -R www-data:www-data
+
+Nginx with passenger with upload module
+# http://www.grid.net.ru/nginx/upload.en.html download upload module for nginx
+ on installing passenger-install-nginx-module add upload module path
+
+ if you are configure with sorce code you can refer http://www.grid.net.ru/nginx/upload.en.html
+check my nginx.conf.sample
+
+
+# For converting into mp4
+start beanstalkd
+start stalk app/models/encode_job.rb
@@ -0,0 +1,7 @@
+# Add your own tasks in files placed in lib/tasks ending in .rake,
+# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
+
+require File.expand_path('../config/application', __FILE__)
+require 'rake'
+
+VideoShare::Application.load_tasks
@@ -0,0 +1,4 @@
+class ApplicationController < ActionController::Base
+ protect_from_forgery
+ before_filter :authenticate_user!
+end
@@ -0,0 +1,6 @@
+class HomeController < ApplicationController
+ skip_before_filter :authenticate_user!,:only=>[:index]
+ def index
+ end
+
+end
@@ -0,0 +1,57 @@
+class VideosController < ApplicationController
+ # GET /videos
+ # GET /videos.xml
+ def index
+ @videos = Video.all
+ respond_to do |format|
+ format.html # index.html.erb
+ format.xml { render :xml => @videos }
+ end
+ end
+
+ def new
+ @video = Video.new
+ respond_to do |format|
+ format.html # new.html.erb
+ format.xml { render :xml => @video }
+ end
+ end
+
+ def create
+
+ @video = Video.new
+ # FOR NGINX
+ @video.set_nginx_video(params[:video])
+ respond_to do |format|
+ if @video.save
+ puts @video.temp_file_path
+ @video.move_to_path
+ format.html { redirect_to(videos_path, :notice => 'Video was successfully created.') }
+ format.xml { render :xml => @video, :status => :created, :location => @video }
+ else
+ format.html { render :action => "new" }
+ format.xml { render :xml => @video.errors, :status => :unprocessable_entity }
+ end
+ end
+ end
+
+ # DELETE /videos/1
+ # DELETE /videos/1.xml
+ def destroy
+ @video = Video.find(params[:id])
+ @video.destroy
+
+ respond_to do |format|
+ format.html { redirect_to(videos_url) }
+ format.xml { head :ok }
+ end
+ end
+
+ def download
+ @video = Video.find(params[:id])
+ response.headers['X-Accel-Redirect'] = "/attachments"+@video.asset.url.split("?").first
+ response.headers['Content-Type'] = @video.asset_content_type
+ response.headers['Content-Disposition'] = "attachment;filename=#{@video.asset_file_name}"
+ redirect_to video_url(@video)
+ end
+end
@@ -0,0 +1,36 @@
+module ApplicationHelper
+ def clearing_span
+ content_tag(:span, '', :class => 'clear')
+ end
+ def title(text)
+ content_tag(:h1,text,:class=>'page-title')
+ end
+ # Returns true if sidebar disabled for current page/controller
+ def sidebar_enabled?
+ current_page = "#{controller.controller_name}.#{controller.action_name}"
+ current_controller = controller.controller_name
+ pages = %w()
+
+ return pages.include?(current_page) || pages.include?(current_controller)
+ end
+ def main_content_css_class
+ sidebar_enabled? ? "grid_12" : "grid_16"
+ end
+
+ # Returns the CSS class for the 'sidebar' div depending on sidebar requirement
+ def sidebar_css_class
+ sidebar_enabled? ? "grid_4" : "dont-show"
+ end
+
+ def active_class
+ classes = {
+ 'home' => 'home',
+ "registrations.edit" =>'home',
+ "registrations.new" =>'register',
+ "sessions.new"=>"login",
+ "videos"=>"video"
+ }
+
+ classes[controller.controller_name + '.' + controller.action_name] || classes[controller.controller_name] || ''
+ end
+end
@@ -0,0 +1,2 @@
+module HomeHelper
+end
@@ -0,0 +1,2 @@
+module VideosHelper
+end
@@ -0,0 +1,28 @@
+#start beanstalkd using beanstalkd
+require 'rubygems'
+require 'stalker'
+class EncodeVideo
+ FFMPEG_PATH = 'ffmpeg'
+ FFMPEGTHEORA_PATH = 'fmpeg2theora'
+
+ def self.convert_to_mp4(file_name)
+ #command ="#{FFMPEG_PATH} -i #{file_name} -vcodec libx264 -vpre hq -vpre ipod640 -b 250k -bt 50k -acodec libfaac -ab 56k -ac 2 -s 480x320 #{file_name}.mp4"
+#ffmpeg -i 002_dynamic_find_by_methods.mov -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre slow -crf 22 test.mp4
+ #ffmpeg -i input.wmv -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre slow -crf 22 -threads 0 output.mp4
+ command ="#{FFMPEG_PATH} -i #{file_name} -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre slow -crf 22 -threads 0 #{file_name}.mp4"
+ system(command)
+ end
+
+ def self.convert_to_ogg(file_name)
+ #filename is abc.mp4
+ command ="#{FFMPEGTHEORA_PATH} #{file_name} #{file_name}.ogv"
+ end
+
+end
+include Stalker
+
+job 'convert_video.to_mp4' do |args|
+ EncodeVideo.convert_to_mp4(args['file'])
+end
+
+#Stalker.enqueue('convert_video.to_mp4', :file => "path_of_file")
@@ -0,0 +1,9 @@
+class User < ActiveRecord::Base
+ # Include default devise modules. Others available are:
+ # :token_authenticatable, :confirmable, :lockable and :timeoutable
+ devise :database_authenticatable, :registerable,
+ :recoverable, :rememberable, :trackable, :validatable
+
+ # Setup accessible (or protected) attributes for your model
+ attr_accessible :email, :password, :password_confirmation, :remember_me,:name
+end
@@ -0,0 +1,42 @@
+class Video < ActiveRecord::Base
+ has_attached_file :asset,
+ :url => '/:class/:id/:basename.:extension',
+ :path => ':rails_root/attachments/:class/:id/:basename.:extension'
+# validates_attachment_presence :video
+ #validates_attachment_content_type :video,
+ # :content_type => ['application/x-shockwave-flash', 'application/x-shockwave-flash', 'application/flv', 'video/x-flv','video/quicktime','video/mp4']
+ #after_create :move_to_path
+ attr_accessor :temp_file_path
+
+ def convert_to_mp4
+ if self.asset_content_type != "video/mp4"
+ Stalker.enqueue('convert_video.to_mp4', :file => self.asset.path)
+ end
+ end
+
+ # handle new param
+ def set_nginx_video(video)
+
+ asset = video['asset']
+ if asset && asset.respond_to?('[]')
+ self.asset = File.new(asset['filepath'])
+ self.temp_file_path =asset['filepath']
+ self.asset_file_name = asset["original_name"]
+ self.asset_content_type = asset["content_type"]
+ self.name = video["name"]
+ end
+ end
+
+ # clean tmp directory used and set new param
+ def move_to_path
+ if File.exist?(self.asset.path)
+ #MOve to path
+ paper_clip_path = "#{Rails.root}/attachments/videos/#{self.id}/"
+ FileUtils.mkdir_p(paper_clip_path)
+ actual_path = paper_clip_path+self.name
+ FileUtils.mv(self.temp_file_path,actual_path)
+ self.asset = File.new(actual_path)
+ self.save!
+ end
+ end
+end
@@ -0,0 +1,12 @@
+<h2>Resend confirmation instructions</h2>
+
+<%= form_for(resource, :as => resource_name, :url => confirmation_path(resource_name), :html => { :method => :post }) do |f| %>
+ <%= devise_error_messages! %>
+
+ <p><%= f.label :email %><br />
+ <%= f.text_field :email %></p>
+
+ <p><%= f.submit "Resend confirmation instructions" %></p>
+<% end %>
+
+<%= render :partial => "devise/shared/links" %>
@@ -0,0 +1,5 @@
+<p>Welcome <%= @resource.email %>!</p>
+
+<p>You can confirm your account through the link below:</p>
+
+<p><%= link_to 'Confirm my account', confirmation_url(@resource, :confirmation_token => @resource.confirmation_token) %></p>
Oops, something went wrong.

0 comments on commit 6f25a90

Please sign in to comment.