Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi! I cleaned up your code for you! #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ Portfolio: http://www.ralphedge.com
Video-App is a YouTube-like site written in rails. It converts video to flash(ffmpeg) and plays videos using FlowPlayer(an open-source flash video player). Has Pagination(will_paginate), Tagging/Tag Cloud(acts_as_taggable_on_steroids), User Authentication(authlogic), Video Replies, and Video Thumbnails. Video conversion is done in a seperate process, using the Spawn plugin. Uses Rails Version 2.2.2...you can change the Rails version it uses in config/environment.rb

To Install: (let me know if I need to add anything to this)
*Download the code:
*Download the code:

git clone git://github.com/balgarath/video-app.git
cd video-app

*(Optional) switch to branch 0.2:
*(Optional) switch to branch 0.2:

git fetch origin 0.2:0.2
git checkout 0.2

*Edit your config/databases.yml

*Install will_paginate - if you don't have it already
sudo gem install will_paginate

*install ffmpeg - you may need to download and compile from source - http://www.ffmpeg.org/download.html

In Ubuntu:
sudo apt-get install ffmpeg

*create and migrate database
rake db:create
rake db:migrate

*launch server
./script/server



12 changes: 6 additions & 6 deletions app/controllers/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ class ApplicationController < ActionController::Base
# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
protect_from_forgery # :secret => '8406dc20b6131ea8a90ec68109f869b1'
# See ActionController::Base for details

# See ActionController::Base for details
# Uncomment this to filter the contents of submitted sensitive data parameters
# from your application log (in this case, all fields with names like "password").
# from your application log (in this case, all fields with names like "password").
# filter_parameter_logging :password

before_filter :get_tag_cloud


filter_parameter_logging :password, :password_confirmation
helper_method :current_user_session, :current_user
Expand Down Expand Up @@ -53,5 +53,5 @@ def redirect_back_or_default(default)
session[:return_to] = nil
end


end
2 changes: 1 addition & 1 deletion app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class TagsController < ApplicationController
def index
@tags = Tag.find :all
end

def show
@tag = Tag.find_by_name(params[:id])
@videos = Video.paginate_by_id(Video.find_tagged_with(@tag), :page => params[:page], :per_page => 10)
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class UsersController < ApplicationController

before_filter :require_user, :only => [:show, :edit, :update]
before_filter :require_user, :only => [:show, :edit, :update]

# GET /users
# GET /users.xml
def index
Expand Down Expand Up @@ -63,5 +63,5 @@ def destroy

redirect_to(users_url)
end

end
6 changes: 3 additions & 3 deletions app/controllers/video_replies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def create
redirect_to @reply.video
else
render @reply.video

end

end

def delete
Expand All @@ -20,5 +20,5 @@ def delete
@reply.destroy
redirect_to @video
end

end
6 changes: 3 additions & 3 deletions app/controllers/videos_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class VideosController < ApplicationController

before_filter :require_user, :only => [:new, :delete, :create]

def index
@videos = Video.paginate :page => params[:page], :order => 'created_at DESC', :per_page => 10
end
Expand All @@ -26,7 +26,7 @@ def show
@video = Video.find(params[:id])
@reply = VideoReply.new
end

def delete
@video = Video.find(params[:id])
@video.destroy
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/videos_controller.rb~
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class VideosController < ApplicationController

before_filter :require_user, :only => [:new, :delete, :create]

def index
@videos = Video.paginate :page => params[:page], :order => 'created_at DESC', :per_page => 10
end
Expand All @@ -25,7 +25,7 @@ class VideosController < ApplicationController
@video = Video.find(params[:id])
@reply = VideoReply.new
end

def delete
@video = Video.find(params[:id])
@video.destroy
Expand Down
8 changes: 4 additions & 4 deletions app/models/thumbnail.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class Thumbnail < ActiveRecord::Base
has_attachment :content_type => :image,
:storage => :file_system
has_attachment :content_type => :image,
:storage => :file_system
has_one :video

def self.create!(vpath)
tpath = vpath + ".jpg"
system "ffmpeg -i #{vpath} -ss 20 -s 150x100 -vframes 1 -f image2 -an #{tpath}"
t = Thumbnail.new(:filename => File.basename(tpath), :content_type => 'image/jpeg', :temp_path => tpath)
t.save ? t : false
t.save ? t : false
end
end
20 changes: 10 additions & 10 deletions app/models/video.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class Video < ActiveRecord::Base

acts_as_taggable

belongs_to :thumbnail
belongs_to :user
has_many :replies, :class_name => 'VideoReply'

before_create :save_thumbnail

has_attachment :content_type => :video,
:storage => :file_system,
has_attachment :content_type => :video,
:storage => :file_system,
:max_size => 300.megabytes

#acts as state machine plugin
Expand All @@ -30,7 +30,7 @@ class Video < ActiveRecord::Base
event :failure do
transitions :from => :converting, :to => :error
end

def rename_file
true
end
Expand Down Expand Up @@ -61,18 +61,18 @@ def save_thumbnail


protected

def convert_command

#construct new file extension
flv = "." + id.to_s + ".flv"

#build the command to execute ffmpeg
command = <<-end_command
ffmpeg -i #{ RAILS_ROOT + '/public' + public_filename } -ar 22050 -s 720x480 -f flv -y #{ RAILS_ROOT + '/public' + public_filename + flv }

end_command

logger.debug "Converting video...command: " + command
command
end
Expand Down
20 changes: 10 additions & 10 deletions app/models/video.rb~
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
class Video < ActiveRecord::Base

acts_as_taggable

belongs_to :thumbnail
belongs_to :user
has_many :replies, :class_name => 'VideoReply'

before_create :save_thumbnail

has_attachment :content_type => :video,
:storage => :file_system,
has_attachment :content_type => :video,
:storage => :file_system,
:max_size => 300.megabytes

#acts as state machine plugin
Expand All @@ -30,7 +30,7 @@ class Video < ActiveRecord::Base
event :failure do
transitions :from => :converting, :to => :error
end

def rename_file
true
end
Expand Down Expand Up @@ -61,18 +61,18 @@ class Video < ActiveRecord::Base


protected

def convert_command

#construct new file extension
flv = "." + id.to_s + ".flv"

#build the command to execute ffmpeg
command = <<-end_command
ffmpeg -i #{ RAILS_ROOT + '/public' + public_filename } -ar 22050 -s 720x480 -f flv -y #{ RAILS_ROOT + '/public' + public_filename + flv }

end_command

logger.debug "Converting video...command: " + command
command
end
Expand Down
16 changes: 8 additions & 8 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
<title>Video App</title>
<%= stylesheet_link_tag 'style' %>

<%= javascript_include_tag 'flowplayer', 'jquery' %>
<%= javascript_include_tag 'flowplayer', 'jquery' %>
</head>

<body>


<div id = "body">
<div id = "header">
<input id = "search" type = "text" value = "Search"/>
<div id = "logo"><a href = "/">video_app</a></div>
</div>


<div id = "main">
<div id = "main_col">
<div class = "innertube">
<div class = "innertube">
<% flash.each do |key,value| %>

<div id="flash" class="flash_<%= key %>" >
Expand All @@ -31,14 +31,14 @@
<% end -%>

<%= yield :layout %>

</div><!-- /innertube -->

</div><!-- /main_col -->
</div><!-- /main -->

<div id = "sidebar">
<div class = "innertube">
<div class = "innertube">
<%= link_to 'New Video', new_video_url, :class => 'new' %><br /><br />
<% if !current_user %>
<%= link_to "Register", new_account_path %><br />
Expand All @@ -65,7 +65,7 @@
Portfolio: <a href = "http://www.ralphedge.com/" target = "_new">http://www.ralphedge.com</a>
</div>
</div><!-- /#body -->

</body>

</html>
Expand Down
16 changes: 8 additions & 8 deletions app/views/layouts/application.html.erb~
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
<title>Video App</title>
<%= stylesheet_link_tag 'style' %>

<%= javascript_include_tag 'flowplayer', 'jquery' %>
<%= javascript_include_tag 'flowplayer', 'jquery' %>
</head>

<body>


<div id = "body">
<div id = "header">
<input id = "search" type = "text" value = "Search"/>
<div id = "logo"><a href = "/">video_app</a></div>
</div>


<div id = "main">
<div id = "main_col">
<div class = "innertube">
<div class = "innertube">
<% flash.each do |key,value| %>

<div id="flash" class="flash_<%= key %>" >
Expand All @@ -31,14 +31,14 @@
<% end -%>

<%= yield :layout %>

</div><!-- /innertube -->

</div><!-- /main_col -->
</div><!-- /main -->

<div id = "sidebar">
<div class = "innertube">
<div class = "innertube">
<%= link_to 'New Video', new_video_url, :class => 'new' %><br /><br />
<% if !current_user %>
<%= link_to "Register", new_account_path %><br />
Expand All @@ -65,7 +65,7 @@
Portfolio: <a href = "http://www.ralphedge.com/" target = "_new">http://www.ralphedge.com</a>
</div>
</div><!-- /#body -->

</body>

</html>
Expand Down
Loading