videoclip 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,13 +1,124 @@
1
1
  = videoclip
2
2
 
3
+ Easily attach videos to your ActiveRecord models from all sorts of popular sites!
4
+
5
+ <tt>videoclip</tt>[http://github.com/laserlemon/videoclip] was inspired by <tt>paperclip</tt>[http://github.com/technoweenie/paperclip] from thoughtbot[http://github.com/thoughtbot]. It uses aggregation (just like <tt>paperclip</tt> or <tt>acts_as_money</tt>) to save the necessary information to link to or embed Flash video from a number of sources.
6
+
7
+ In particular, <tt>videoclip</tt> saves three values for each video:
8
+
9
+ * The host of the video (e.g., "youtube", "blip")
10
+ * A unique key string to identify the video
11
+ * A link back to the original source of the video
12
+
13
+ In addition, <tt>videoclip</tt> can return the HTML needed to embed the video on your own site by using the host and the key of the video. You can specify styles (much like you can using <tt>paperclip</tt>) to define the size(s) at which you'd like to embed the video.
14
+
3
15
  == Installation
4
16
 
5
- script/plugin install git://github.com/laserlemon/videoclip.git
17
+ In <tt>environment.rb</tt>:
18
+
19
+ Rails::Initializer.run do |config|
20
+ config.gem 'videoclip'
21
+ end
22
+
23
+ At your application root, run:
24
+
25
+ $ sudo rake gems:install
6
26
 
7
27
  == Example
8
28
 
9
- Coming soon...
29
+ To use videoclip in an ActiveRecord model, call the <tt>has_video</tt> method:
30
+
31
+ class Product < ActiveRecord::Base
32
+ has_video :video,
33
+ :styles => {:large => '640x360', :medium => '480x270', :small => '320x240!'},
34
+ :default_style => :large
35
+
36
+ validates_presence_of :name
37
+ end
38
+
39
+ In the example above, the first argument is the name of the video. You'll need to add three columns to your <tt>Product</tt> model, each prefixed with the video name:
40
+
41
+ class AddVideoToProducts < ActiveRecord::Migration
42
+ def self.up
43
+ change_table :products do |t|
44
+ t.string :video_host
45
+ t.string :video_key
46
+ t.string :video_url
47
+ end
48
+ end
49
+
50
+ def self.down
51
+ change_table :products do |t|
52
+ t.remove :video_host
53
+ t.remove :video_key
54
+ t.remove :video_url
55
+ end
56
+ end
57
+ end
58
+
59
+ Now attaching videos is a snap...
60
+
61
+ >> p = Product.create(:name => 'Treadmill', :video => 'http://www.youtube.com/watch?v=pv5zWaTEVkI&feature=related')
62
+ => #<Product name: "Treadmill", video_host: "youtube", video_key: "pv5zWaTEVkI", video_url: "http://www.youtube.com/watch?v=pv5zWaTEVkI">
63
+ >> p.video.host
64
+ => "youtube"
65
+ >> p.video.key
66
+ => "pv5zWaTEVkI"
67
+ >> p.video.url
68
+ => "http://www.youtube.com/watch?v=pv5zWaTEVkI"
69
+ >> p.video.embed
70
+ => "<object width=\"640\" height=\"385\"><param name=\"movie\" value=\"http://www.youtube.com/v/pv5zWaTEVkI&hl=en&fs=1\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/pv5zWaTEVkI&hl=en&fs=1\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"640\" height=\"385\"></embed></object>"
71
+ >> p.update_attribute(:video, 'http://blip.tv/file/62177')
72
+ => "http://blip.tv/file/62177"
73
+ >> p.video.host
74
+ => "blip"
75
+ >> p.video.key
76
+ => "AYSAKwI"
77
+ >> p.video.url
78
+ => "http://blip.tv/file/62177"
79
+ >> p.video.embed
80
+ => "<embed src=\"http://blip.tv/play/AYSAKwI\" type=\"application/x-shockwave-flash\" width=\"640\" height=\"390\" allowscriptaccess=\"always\" allowfullscreen=\"true\"></embed>"
81
+ >> p.video.embed(:small)
82
+ => "<embed src=\"http://blip.tv/play/AYSAKwI\" type=\"application/x-shockwave-flash\" width=\"320\" height=\"240\" allowscriptaccess=\"always\" allowfullscreen=\"true\"></embed>"
83
+
84
+ There are a few things to note in the example above:
85
+
86
+ 1. The input needed to create a video object is simply the URL of the video on its host site. This URL doesn't have to be perfectly formed. A canonical link will be stored.
87
+ 2. The format of the embed string is unique to the video host and should closely resemble the embed string recommended by the host.
88
+ 3. The actual dimensions used in the embed string may be larger than those specified in the model. This is due to additional controls (or "chrome") surrounding the played back video (note: this can be overridden, see below).
89
+
90
+ == Styles
91
+
92
+ As seen in the above example, the <tt>embed</tt> method accepts a style argument to determine the output dimensions of the video. The style argument can be in one of three formats: a symbol, string or hash.
93
+
94
+ 1. A symbol references a key in the <tt>:styles</tt> hash of your <tt>has_video</tt> declaration.
95
+ 2. A string is used as a ImageMagick-ish representation of the geometry to use (see below).
96
+ 3. A hash can be used to define the <tt>:width</tt> and <tt>:height</tt> of the embedded video as well as a boolean option, <tt>:include_chrome</tt> (see below).
97
+
98
+ The geometry string is a simpler form of an {ImageMagick geometry string}[http://www.imagemagick.org/script/command-line-processing.php#geometry]. For <tt>videoclip</tt>, the geometry string follows a simple pattern:
99
+
100
+ "#{width}x#{height}"
101
+
102
+ So the geometry <tt>640x360</tt> would output a video playback 640 pixels wide and 360 pixels tall. Note that embedded video from some hosts includes padding around the edges for controls called "chrome." For instance, Youtube adds 25 pixels of chrome to the bottom of each embedded video. For this reason, the default <tt>videoclip</tt> behavior is to add the chrome dimensions to the video player dimensions. So a geometry of <tt>640x360</tt> would actually embed a Youtube player 640 pixels wide and 385 pixels tall. This keeps the viewable video size consistent.
103
+
104
+ However, if absolute dimensions are required, an exclamation point can be added to the end of a geometry to ensure that the chrome dimensions are included in the given dimensions, so that the embedded player will not exceed that size.
105
+
106
+ Additionally, either the width or the height values can be excluded. For the geometry <tt>720x</tt>, the viewable video will be 720 pixels wide and the height will be set according to that video host's default aspect ratio. The overriding default for all hosts is 16:9 so in this case, the height would be 405 pixels plus the height of the video host's chrome. Again, the chrome can be included in the dimensions by changing the geometry to <tt>720x!</tt>.
107
+
108
+ The width dimension can also be excluded. The geometry <tt>x405</tt> would yield the same results as <tt>720x</tt> for a 16:9 video host.
109
+
110
+ For a hash style declaration, the <tt>:include_chrome</tt> option is equivalent to appending an exclamation point to a geometry string.
111
+
112
+ As shown in the example, the <tt>embed</tt> method can also accept zero arguments, in which case the specified <tt>:default_style</tt> is used. If there is only a single style defined or if the default style is named <tt>:default</tt>, the <tt>:default_style</tt> option can be omitted.
113
+
114
+ == Contributing
115
+
116
+ Video sites are often changing the dimensions of their video players or the format of their URLs. Because of this, the <tt>videoclip</tt> video classes for these hosts will need to be updated as well. When an update is needed, please create a new issue[http://github.com/laserlemon/videoclip/issues] or fork the repository yourself and fix away!
117
+
118
+ I'm always open to outside contribution and as long as your work is in line with the direction of the project, I'll more than likely include it, so feel free! Or if you're not comfortable hacking away at the code, please send me your feedback.
10
119
 
11
- == Tips
120
+ == TODO
12
121
 
13
- Coming soon...
122
+ * Tests!
123
+ * More video hosts
124
+ * Convince Hulu to open a public API
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.6
1
+ 0.2.7
@@ -51,6 +51,8 @@ module LaserLemon
51
51
  attr_reader :host, :key, :url
52
52
  attr_accessor :options
53
53
 
54
+ alias_method :to_s, :url
55
+
54
56
  def initialize(key = nil, url = nil, options = {})
55
57
  @host = self.class.host
56
58
  @key, @url, @options = key, url, options
@@ -2,7 +2,7 @@ module LaserLemon
2
2
  module Videoclip
3
3
  class Video::Blip < Video
4
4
  def self.match?(uri)
5
- (uri.host =~ /^(?:www\.)?blip\.tv$/i) && (uri.path =~ /^\/file\/\d+$/)
5
+ (uri.host =~ /^(?:www\.)?blip\.tv$/i) && (uri.path =~ /^\/file\/\d+/)
6
6
  end
7
7
 
8
8
  def assign(uri)
data/videoclip.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{videoclip}
8
- s.version = "0.2.6"
8
+ s.version = "0.2.7"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["laserlemon"]
12
- s.date = %q{2009-10-10}
12
+ s.date = %q{2009-10-11}
13
13
  s.description = %q{Save videos from popular sites alongside your ActiveRecord models}
14
14
  s.email = %q{steve@laserlemon.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: videoclip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - laserlemon
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-10 00:00:00 -04:00
12
+ date: 2009-10-11 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15