chili_videos 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. data.tar.gz.sig +1 -0
  2. data/.autotest +5 -0
  3. data/Gemfile +13 -0
  4. data/Gemfile.lock +33 -0
  5. data/History.txt +4 -0
  6. data/LICENSE +20 -0
  7. data/Manifest.txt +63 -0
  8. data/README.md +169 -0
  9. data/Rakefile +45 -0
  10. data/app/controllers/videos_controller.rb +72 -0
  11. data/app/helpers/videos_helper.rb +34 -0
  12. data/app/models/assembly.rb +62 -0
  13. data/app/models/assembly_observer.rb +6 -0
  14. data/app/models/assembly_processor.rb +16 -0
  15. data/app/models/video.rb +24 -0
  16. data/app/views/settings/_settings.html.erb +13 -0
  17. data/app/views/videos/edit.html.erb +32 -0
  18. data/app/views/videos/index.html.erb +37 -0
  19. data/app/views/videos/new.html.erb +41 -0
  20. data/app/views/videos/plugin_not_configured.html.erb +6 -0
  21. data/app/views/videos/show.html.erb +40 -0
  22. data/app/views/videos/upload_complete.html.erb +7 -0
  23. data/assets/player.swf +0 -0
  24. data/assets/readme.html +84 -0
  25. data/assets/stylesheets/forms.css +7 -0
  26. data/assets/stylesheets/videos.css +76 -0
  27. data/assets/swfobject.js +8 -0
  28. data/assets/yt.swf +0 -0
  29. data/autotest/discover.rb +4 -0
  30. data/bin/delayed_job +23 -0
  31. data/config/locales/en.yml +15 -0
  32. data/config/routes.rb +3 -0
  33. data/db/migrate/20110301025054_create_videos.rb +15 -0
  34. data/db/migrate/20110309060901_create_assemblies.rb +14 -0
  35. data/db/migrate/20110314022354_create_delayed_jobs.rb +21 -0
  36. data/db/migrate/20110402043115_create_slugs.rb +18 -0
  37. data/db/migrate/20110402053931_add_slug_cache_to_videos.rb +11 -0
  38. data/init.rb +63 -0
  39. data/lang/en.yml +16 -0
  40. data/lib/chili_videos.rb +18 -0
  41. data/lib/chili_videos/config.rb +40 -0
  42. data/lib/chili_videos/error.rb +5 -0
  43. data/lib/tasks/chili_videos_tasks.rb +112 -0
  44. data/lib/tasks/contributor_tasks.rb +64 -0
  45. data/lib/tasks/delayed_job.rake +6 -0
  46. data/lib/tasks/friendly_id.rake +19 -0
  47. data/lib/video_project_patch.rb +10 -0
  48. data/lib/video_user_patch.rb +10 -0
  49. data/lib/video_version_patch.rb +9 -0
  50. data/rails/delayed_job +25 -0
  51. data/rails/init.rb +1 -0
  52. data/test/fixtures/incomplete_assembly.json +9 -0
  53. data/test/fixtures/single_video_processed_assembly.json +9 -0
  54. data/test/fixtures/standard_transloadit_response.json +6 -0
  55. data/test/functional/videos_controller_test.rb +232 -0
  56. data/test/integration/project_video_list_test.rb +104 -0
  57. data/test/integration/project_video_uploading_test.rb +56 -0
  58. data/test/integration/viewing_project_video_test.rb +74 -0
  59. data/test/test_helper.rb +77 -0
  60. data/test/unit/assembly_processor_test.rb +57 -0
  61. data/test/unit/assembly_test.rb +95 -0
  62. data/test/unit/chili_video_plugin/config_test.rb +49 -0
  63. data/test/unit/chili_video_plugin_test.rb +30 -0
  64. data/test/unit/video_test.rb +26 -0
  65. metadata +279 -0
  66. metadata.gz.sig +0 -0
@@ -0,0 +1,62 @@
1
+ class Encoding < Hashie::Mash
2
+ end
3
+
4
+ class Assembly < ActiveRecord::Base
5
+ unloadable
6
+
7
+ ASSEMBLY_STATUS_KEY = "ok"
8
+ ASSEMBLY_COMPLETE_VALUE = "ASSEMBLY_COMPLETED"
9
+
10
+ attr_accessible :project_id, :assembly_id, :assembly_url, :user_id
11
+
12
+ belongs_to :project
13
+ belongs_to :user
14
+
15
+ named_scope :processed, :conditions => {:processed => true}
16
+ named_scope :unprocessed, :conditions => {:processed => false}
17
+
18
+ before_create :set_processed_to_false
19
+
20
+ def completed?
21
+ raw_assembly(:reload)[ASSEMBLY_STATUS_KEY] == ASSEMBLY_COMPLETE_VALUE
22
+ end
23
+
24
+ def custom_fields
25
+ HashWithIndifferentAccess.new(raw_assembly["fields"])
26
+ end
27
+
28
+ def encodings
29
+ raise ChiliVideos::Error::IncompleteAssembly unless completed?
30
+
31
+ raw_assembly["results"]["encode"].map do |raw_encoding|
32
+ Encoding.new(raw_encoding)
33
+ end
34
+ end
35
+
36
+ # Retrieves and caches the content of .assembly_url. If you pass
37
+ # in :reload as an argument, it will visit the URL again and replace
38
+ # the existing values.
39
+ #
40
+ # reload_or_not - determines whether the method call should use a cached
41
+ # version of the content or not. :reload is the only value
42
+ # which will have an impact on the method call.
43
+ #
44
+ # Returns the HTTP response as a Hash
45
+ def raw_assembly(symbol = nil)
46
+ return @raw_assembly if @raw_assembly && symbol != :reload
47
+ @raw_assembly = Retriever.get(assembly_url)
48
+ end
49
+
50
+ class << self
51
+ class ::Retriever
52
+ include HTTParty
53
+ format :json
54
+ end
55
+ end
56
+
57
+ private
58
+ def set_processed_to_false
59
+ self.processed = false
60
+ true
61
+ end
62
+ end
@@ -0,0 +1,6 @@
1
+ class AssemblyObserver < ActiveRecord::Observer
2
+ def after_create(assembly)
3
+ Rails.logger.info "Queing up assembly #{assembly.assembly_url} (id ##{assembly.id})..."
4
+ AssemblyProcessor.delay.process(assembly)
5
+ end
6
+ end
@@ -0,0 +1,16 @@
1
+ class AssemblyProcessor
2
+ class << self
3
+ def process(assembly)
4
+ project = assembly.project
5
+ assembly.encodings.each do |encoding|
6
+ project.videos.create!({:title => assembly.custom_fields[:title],
7
+ :description => assembly.custom_fields[:description],
8
+ :version_id => assembly.custom_fields[:version_id],
9
+ :duration => encoding.meta.duration.to_i,
10
+ :user_id => assembly.user_id,
11
+ :url => encoding.url})
12
+ end
13
+ assembly.update_attribute(:processed, true)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ class Video < ActiveRecord::Base
2
+ unloadable
3
+
4
+ has_friendly_id :title, :use_slug => true
5
+
6
+ belongs_to :user
7
+ belongs_to :project
8
+ belongs_to :version
9
+
10
+ def length
11
+ return "0:00" if duration.blank?
12
+ minutes = duration / 60
13
+ seconds = duration % 60
14
+ "#{minutes}:#{seconds.to_s.rjust(2,'0')}"
15
+ end
16
+
17
+ def permalink
18
+ friendly_id
19
+ end
20
+
21
+ def to_s
22
+ title
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ <p>
2
+ <%= l(:transloadit_video_directions) %>
3
+ </p>
4
+
5
+ <p>
6
+ <label><%= l(:transloadit_api_key_label) %></label>
7
+ <%= text_field_tag "settings[#{ChiliVideos::Config::API_KEY_KEYNAME}]", ChiliVideos::Config.api_key %>
8
+ </p>
9
+
10
+ <p>
11
+ <label><%= l(:transloadit_workflow_label) %></label>
12
+ <%= text_field_tag "settings[#{ChiliVideos::Config::WORKFLOW_KEYNAME}]", ChiliVideos::Config.workflow%>
13
+ </p>
@@ -0,0 +1,32 @@
1
+ <% content_for :header_tags do %>
2
+ <%= stylesheet_link_tag '/plugin_assets/chili_videos/stylesheets/forms' %>
3
+ <% end %>
4
+
5
+ <h2>Updating "<%= @video %>" video...</h2>
6
+
7
+ <%- form_for [@project, @video], :html => {:class => "tabular"} do |f| %>
8
+ <div class="box">
9
+ <p>
10
+ <%= f.label :title %>
11
+ <%= f.text_field :title %>
12
+ </p>
13
+
14
+ <p>
15
+ <%= f.label :description %>
16
+ <%= f.text_area :description %>
17
+ </p>
18
+
19
+ <%- unless @versions.blank? %>
20
+ <p>
21
+ <%- f.label :version_id %>
22
+ <select name="video[version_id]" id="video_version_id">
23
+ <%= options_for_select @versions.map {|v| [v.name, v.id]}, @video.version_id %>
24
+ <option value="">No version</option>
25
+ </select>
26
+ </p>
27
+ <%- end %>
28
+ </div>
29
+ <%= f.submit "Save updates" %>
30
+ or
31
+ <%= link_to "Cancel", project_video_path(@project, @video) %>
32
+ <%- end %>
@@ -0,0 +1,37 @@
1
+ <% content_for :header_tags do %>
2
+ <%= stylesheet_link_tag '/plugin_assets/chili_videos/stylesheets/videos' %>
3
+ <% end %>
4
+
5
+ <div class="contextual">
6
+ <%= link_to(l(:new_video_label), new_project_video_path(@project), :class => 'icon icon-add') if User.current.allowed_to?(:add_video, nil, :global => true) %>
7
+ </div>
8
+
9
+ <h2>Videos (newest first)</h2>
10
+
11
+ <%- if @videos.empty? %>
12
+ <p class="nodata">
13
+ No videos uploaded yet!
14
+ <%= link_to "Add one...", new_project_video_path(@project) %>
15
+ <p>
16
+ <%- else %>
17
+ <ul class="videos">
18
+ <%- @videos.each do |video| %>
19
+ <li class="video" id="<%= video.to_param %>">
20
+ <a href="<%= project_video_path(@project, video) %>" class="video-cell small">
21
+ <span>
22
+ <%= video.length %>
23
+ </span>
24
+ </a>
25
+ <h3>
26
+ <%= link_to(truncate(video.title, :length => 24), project_video_path(@project, video), :title => video.title) %>
27
+ </h3>
28
+ <dl>
29
+ <dt>by:</dt>
30
+ <dd>
31
+ <%= link_to(truncate(video.user.name, :length => 17), user_path(video.user)) %>
32
+ </dd>
33
+ </dl>
34
+ </li>
35
+ <%- end %>
36
+ </ul>
37
+ <%- end %>
@@ -0,0 +1,41 @@
1
+ <% content_for :header_tags do %>
2
+ <%= stylesheet_link_tag '/plugin_assets/chili_videos/stylesheets/forms' %>
3
+ <% end %>
4
+
5
+ <h2>Upload project video...</h2>
6
+
7
+ <form id="video-upload" action="http://api2.transloadit.com/assemblies" enctype="multipart/form-data" method="POST" class="tabular">
8
+ <div class="box">
9
+ <input type="hidden" name="params" value="{&quot;auth&quot;:{&quot;key&quot;:&quot;<%= @api_key %>&quot;},&quot;template_id&quot;:&quot;<%= @workflow %>&quot;,&quot;redirect_url&quot;:&quot;<%= upload_complete_project_videos_url(@project) %>&quot;}" />
10
+ <input type="hidden" name="project_id" value="<%= @project.to_param %>"/>
11
+ <input type="hidden" name="user_id" value="<%= User.current.id %>"/>
12
+
13
+ <p>
14
+ <label for="title">Title:</label>
15
+ <input type="text" name="title" id="title" value=""/>
16
+ </p>
17
+
18
+ <p>
19
+ <label for="description">Description:</label>
20
+ <textarea name="description" id="description"></textarea>
21
+ </p>
22
+
23
+ <%- unless @versions.blank? %>
24
+ <p>
25
+ <label for="version">Version:</label>
26
+ <select name="version_id" id="version">
27
+ <%= options_for_select @versions.map {|v| [v.name, v.id]} %>
28
+ <option value="">No version</option>
29
+ </select>
30
+ </p>
31
+ <%- end %>
32
+
33
+ <p>
34
+ <label for="file">Select file to upload...</label>
35
+ <input type="file" name="my_file" id="file" />
36
+ </p>
37
+ </div>
38
+ <input type="submit" value="Upload Video" />
39
+ or
40
+ <%= link_to "Cancel", project_videos_path(@project) %>
41
+ </form>
@@ -0,0 +1,6 @@
1
+ <h2>Video plugin not configured...</h2>
2
+
3
+ <p class="warning">
4
+ You must add your Transload.it account's API and workflow keys before you can upload videos. You can add your credentials on
5
+ <%= link_to "the plugin settings page", {:controller => 'settings', :action => 'plugin', :id => 'chili_videos'} %>.
6
+ </p>
@@ -0,0 +1,40 @@
1
+ <% content_for :header_tags do %>
2
+ <%= stylesheet_link_tag '/plugin_assets/chili_videos/stylesheets/videos' %>
3
+ <% end %>
4
+
5
+ <div class="contextual">
6
+ <%= link_to(l(:new_video_label), new_project_video_path(@project), :class => 'icon icon-add') if User.current.allowed_to?(:add_video, nil, :global => true) %>
7
+ <%= link_to(l(:edit_video_label), edit_project_video_path(@project), :class => 'icon icon-edit video-edit') if User.current.allowed_to?(:edit_video, nil, :global => true) %>
8
+ <%= link_to(l(:delete_video_label), project_video_path(@project), :class => 'icon icon-del video-del', :confirm => l(:confirm_video_deletion), :method => :delete) if User.current.allowed_to?(:delete_video, nil, :global => true) %>
9
+ </div>
10
+
11
+ <h2><%= @video.title.blank? ? l(:default_video_title) : @video.title %></h2>
12
+
13
+ <div class="single video">
14
+ <div class="video-cell large" id="video_<%= @video.permalink %>"></div>
15
+ <%- if gravatar_enabled? %>
16
+ <%= link_to(gravatar(@video.user.mail), user_path(@video.user), :title => "Uploaded by #{@video.user.name}") %>
17
+ <%- end %>
18
+ <dl>
19
+ <dt>Length:</dt>
20
+ <dd><%= @video.length %></dd>
21
+
22
+ <dt>Description:</dt>
23
+ <dd><%= @video.description.blank? ? "(none provided)" : @video.description %></dd>
24
+
25
+ <%- if !gravatar_enabled? %>
26
+ <dt>Uploaded by:</dt>
27
+ <dd><%= link_to @video.user, user_path(@video.user) %></dd>
28
+ <%- end %>
29
+
30
+ <%- if @video.version %>
31
+ <dt>Release:</dt>
32
+ <dd><%= link_to @video.version, project_version_path(@project, @video.version) %></dd>
33
+ <%- end %>
34
+
35
+ <dt><label for="<%= @video.title %>">Embed:</label></dt>
36
+ <dd><input type="text" id="<%= @video.title %>" class="embed standard" value="<%= video_embed_macro_markup(@video) %>" /></dd>
37
+ </dl>
38
+ </div>
39
+
40
+ <%= video_embed_code(@video, :large) %>
@@ -0,0 +1,7 @@
1
+ <h2>Upload complete!</h2>
2
+
3
+ <p>
4
+ We have a little bit of work left before your video is ready to be shared. Come back in a few minutes and we should be good to go...
5
+ </p>
6
+
7
+ <%= link_to("Back to list of videos", project_videos_path(@project)) %>
Binary file
@@ -0,0 +1,84 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
+ <html xmlns="http://www.w3.org/1999/xhtml">
3
+ <head>
4
+
5
+ <title>JW Player for Flash</title>
6
+
7
+ <style type="text/css">
8
+ body { background-color: #fff; padding: 0 20px; color:#000; font: 13px/18px Arial, sans-serif; }
9
+ a { color: #360; }
10
+ h3 { padding-top: 20px; }
11
+ ol { margin:5px 0 15px 16px; padding:0; list-style-type:square; }
12
+ </style>
13
+
14
+ </head>
15
+ <body>
16
+
17
+ <h1>Welcome to the World of LongTail Video</h1>
18
+ <p>Thanks for downloading the JW FLV Player, just one of many products created by Jeroen "JW" Wijering and his company, <a href="http://www.longtailvideo.com">LongTail Video</a>. Before you get started, let us tell you about a few other products that might interest you:</p>
19
+
20
+ <ul>
21
+ <li><a href="http://www.longtailvideo.com/players/jw-desktop-player/">Desktop Player</a> - Our sleek new desktop player is the best way to watch all your music and video files. Plus, you can even search the web for videos without ever opening your browser. <a href="http://www.longtailvideo.com/players/jw-desktop-player/">Download it now</a>.</li>
22
+ <li><a href="http://www.longtailvideo.com/referral.aspx?page=pubreferral&ref=oryixfvlxlptwph">AdSolution</a> - Monetize your videos with LongTail's AdSolution. Integrate pre-roll, overlay mid-roll and post-roll ads into your site and starting making money today. <a href="http://www.longtailvideo.com/referral.aspx?page=pubreferral&ref=oryixfvlxlptwph">Sign up now</a>.</li>
23
+ <li><a href="http://www.bitsontherun.com/via/longtailvideo">Bits on the Run</a> - Upload, encode, store, manage and stream your videos with Bits on the Run, LongTail's end-to-end video content management system. <a href="http://www.bitsontherun.com/via/longtailvideo">Sign up now</a>.</li>
24
+ <li><a href="http://www.longtailvideo.com/addons/plugins">Plugins</a> - Add functionality to your player, like analytics tracking, embed links, sharing and more. <a href="http://www.longtailvideo.com/addons/plugins">Find one for you</a>.</li>
25
+ <li><a href="http://www.longtailvideo.com/addons/skins">Skins</a> - Change the look of your player to match your site. <a href="http://www.longtailvideo.com/addons/skins">View our library</a>.</li>
26
+ </ul>
27
+
28
+
29
+ <h3>Licensing</h3>
30
+ <p>The player is licensed under a <a href="http://creativecommons.org/licenses/by-nc-sa/2.0/">Creative Commons License</a>. It allows you to use, modify and redistribute the script, but only for <b>noncommercial</b> purposes. Examples of <b>commercial use</b> include:
31
+
32
+ <ul>
33
+ <li>websites with any advertisements; </li>
34
+ <li>websites owned or operated by corporations; </li>
35
+ <li>websites designed to promote other products, such as a band or artist;</li>
36
+ <li>products (e.g. a CMS) that bundle LongTail products into its offering. </li>
37
+ </ul>
38
+
39
+ If any of the above conditions apply to you, <a href="http://www.longtailvideo.com/players/order" title="Order commercial licenses">please apply for a commercial license</a> now. If you are still unsure whether you need to purchase a license, please <a href="http://www.longtailvideo.com/forum/">post your question</a> in the forum. </p>
40
+
41
+ <h3>Player Example</h3>
42
+ <p>Below you see a simple embedded example of the JW Player. Copy and paste the source code and put the SWF, JS and FLV file on your site to get started.</p>
43
+
44
+ <!-- START OF THE PLAYER EMBEDDING TO COPY-PASTE -->
45
+
46
+ <object id="player" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" name="player" width="400" height="315">
47
+ <param name="movie" value="player-viral.swf" />
48
+ <param name="allowfullscreen" value="true" />
49
+ <param name="allowscriptaccess" value="always" />
50
+ <param name="flashvars" value="file=video.flv&image=preview.jpg" />
51
+ <embed
52
+ type="application/x-shockwave-flash"
53
+ id="player2"
54
+ name="player2"
55
+ src="player-viral.swf"
56
+ width="400"
57
+ height="315"
58
+ allowscriptaccess="always"
59
+ allowfullscreen="true"
60
+ flashvars="file=video.flv&image=preview.jpg"
61
+ />
62
+ </object>
63
+
64
+ <!-- END OF THE PLAYER EMBEDDING -->
65
+
66
+
67
+ <h3>Quickstart</h3>
68
+ <p>The easiest way to get to know the player is by using our <a href="http://www.longtailvideo.com/support/jw-player-setup-wizard">setup wizard</a>. Select an example, set the file or playlist you want to play and copy-paste the embed code to your site. If you want to play Youtube content in the player, you also have to copy the <b>yt.swf</b> file along with the player.swf or player-viral.swf.</p>
69
+
70
+ <p>If you need any help, please visit our extensive support section, including <a href="http://www.longtailvideo.com/support/faq">FAQs</a>, a string of <a href="http://www.longtailvideo.com/support/tutorials">tutorials</a> and a very active <a href="http://www.longtailvideo.com/support/forum">support forum</a>.</p>
71
+
72
+ <h3>Wiki and Source Code</h3>
73
+ <p>The <a href="http://developer.longtailvideo.com">Developer Wiki</a> contains a wealth of info about the player, including:</p>
74
+ <ol>
75
+ <li><a href="http://developer.longtailvideo.com/trac/wiki/FlashFormats">Supported file formats</a> (and playlists).</li>
76
+ <li><a href="http://developer.longtailvideo.com/trac/wiki/FlashVars">Supported flashvars</a> (for customizing the player).</li>
77
+ <li><a href="http://developer.longtailvideo.com/trac/wiki/FlashAPI">Supported API calls</a> (for actionscript / javascript interaction).</li>
78
+ <li><a href="http://developer.longtailvideo.com/trac/wiki/FlashSkinning">Supported skinning elements</a> (for creating your own graphics).</li>
79
+ <li><a href="http://developer.longtailvideo.com/trac/roadmap/">Roadmap with full changelogs</a> for each version.</li>
80
+ </ol>
81
+ <p>The source code of all different versions of the player can <a href="http://developer.longtailvideo.com/trac/browser/tags">be found here</a>. You can click a version and download the ZIP files (the links are at the bottom).</p>
82
+
83
+ </body>
84
+ </html>
@@ -0,0 +1,7 @@
1
+ input[type="text"], textarea {
2
+ width: 300px;
3
+ }
4
+
5
+ textarea {
6
+ height: 100px;
7
+ }
@@ -0,0 +1,76 @@
1
+ ul.videos li {
2
+ list-style-type: none;
3
+ float: left;
4
+ margin-right: 25px;
5
+ }
6
+
7
+ .video h3 {
8
+ border-bottom: none;
9
+ font-size: 12px;
10
+ width: 128px;
11
+ padding: 5px 0 0 0;
12
+ margin: 0;
13
+ }
14
+
15
+ .video {
16
+ padding-bottom: 30px;
17
+ }
18
+
19
+ .video.single .video-cell {
20
+ float: left;
21
+ margin-right: 20px;
22
+ }
23
+
24
+ .video .gravatar {
25
+ float: right;
26
+ }
27
+
28
+ .video.single dt {
29
+ font-weight: bold;
30
+ display: block;
31
+ }
32
+
33
+ .video input {
34
+ width: 250px;
35
+ }
36
+
37
+ .video-cell {
38
+ background-color:#000;
39
+ text-align: right;
40
+ display: block;
41
+ }
42
+
43
+ .video .video-cell.small {
44
+ width:128px;
45
+ height:96px;
46
+ }
47
+
48
+ .video .video-cell.large {
49
+ width:640px;
50
+ height:390px;
51
+ }
52
+
53
+ .video-cell span {
54
+ position:relative;
55
+ top: 81px;
56
+ padding-right: 3px;
57
+ color: #CCC;
58
+ display: block;
59
+ }
60
+
61
+ .video dl {
62
+ margin-top: 0;
63
+ }
64
+
65
+ .video dt {
66
+ float: left;
67
+ padding-right: 3px;
68
+ }
69
+
70
+ .video dd {
71
+ margin: 3px;
72
+ clear: after;
73
+ display: block;
74
+ }
75
+
76
+