videoclip 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/LICENSE +20 -0
- data/README.rdoc +13 -0
- data/Rakefile +38 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/videoclip.rb +31 -0
- data/lib/videoclip/video.rb +127 -0
- data/lib/videoclip/videos/blip.rb +34 -0
- data/lib/videoclip/videos/youtube.rb +23 -0
- data/test/test_helper.rb +3 -0
- data/test/videoclip_test.rb +8 -0
- data/videoclip.gemspec +54 -0
- metadata +69 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Steve Richert
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'jeweler'
|
8
|
+
Jeweler::Tasks.new do |g|
|
9
|
+
g.name = 'videoclip'
|
10
|
+
g.summary = %(Save videos from popular sites alongside your ActiveRecord models)
|
11
|
+
g.description = %(Save videos from popular sites alongside your ActiveRecord models)
|
12
|
+
g.email = 'steve@laserlemon.com'
|
13
|
+
g.homepage = 'http://github.com/laserlemon/videoclip'
|
14
|
+
g.authors = %w(laserlemon)
|
15
|
+
g.rubyforge_project = 'laser-lemon'
|
16
|
+
end
|
17
|
+
Jeweler::RubyforgeTasks.new do |r|
|
18
|
+
r.doc_task = 'rdoc'
|
19
|
+
end
|
20
|
+
Jeweler::GemcutterTasks.new
|
21
|
+
rescue LoadError
|
22
|
+
puts 'Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com'
|
23
|
+
end
|
24
|
+
|
25
|
+
Rake::TestTask.new do |t|
|
26
|
+
t.libs = %w(test)
|
27
|
+
t.pattern = 'test/**/*_test.rb'
|
28
|
+
end
|
29
|
+
|
30
|
+
task :default => :test
|
31
|
+
|
32
|
+
Rake::RDocTask.new do |r|
|
33
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : nil
|
34
|
+
r.rdoc_dir = 'rdoc'
|
35
|
+
r.title = ['videoclip', version].compact.join(' ')
|
36
|
+
r.rdoc_files.include('README*')
|
37
|
+
r.rdoc_files.include('lib/**/*.rb')
|
38
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.3
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'videoclip'
|
data/lib/videoclip.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'videoclip/video'
|
2
|
+
Dir.glob(Rails.root + 'lib/videoclip/*.rb').each{|v| require v }
|
3
|
+
Dir.glob(File.dirname(__FILE__) + '/videoclip/videos/*.rb').each{|v| require v }
|
4
|
+
|
5
|
+
module LaserLemon
|
6
|
+
module Videoclip
|
7
|
+
def self.included(base)
|
8
|
+
base.extend ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def has_video(name = :video, options = {})
|
13
|
+
class_inheritable_hash :videoclip_options
|
14
|
+
self.videoclip_options = {name.to_sym => options}
|
15
|
+
|
16
|
+
composed_of name,
|
17
|
+
:class_name => 'LaserLemon::Videoclip::Video',
|
18
|
+
:mapping => %w(host key url).map{|x| %W(#{name}_#{x} #{x}) },
|
19
|
+
:constructor => Proc.new{|h,k,u| LaserLemon::Videoclip::Video.build(h, k, u, options) },
|
20
|
+
:converter => Proc.new{|u| LaserLemon::Videoclip::Video.assign(u, options) },
|
21
|
+
:allow_nil => true
|
22
|
+
|
23
|
+
define_method "#{name}?" do
|
24
|
+
!! send(name)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
ActiveRecord::Base.send(:include, LaserLemon::Videoclip)
|
@@ -0,0 +1,127 @@
|
|
1
|
+
module LaserLemon
|
2
|
+
module Videoclip
|
3
|
+
class Video
|
4
|
+
cattr_reader :implementations
|
5
|
+
@@implementations = []
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def inherited(subclass)
|
9
|
+
@@implementations << subclass
|
10
|
+
end
|
11
|
+
|
12
|
+
def match(uri, host = nil)
|
13
|
+
begin
|
14
|
+
klass = @@implementations.detect{|i| (i.host == host) || i.match?(uri) }
|
15
|
+
raise if klass.nil?
|
16
|
+
rescue
|
17
|
+
raise UnrecognizedVideoHost
|
18
|
+
else klass
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_url(url)
|
23
|
+
begin
|
24
|
+
uri = URI.parse(url)
|
25
|
+
raise unless uri.is_a?(URI::HTTP)
|
26
|
+
rescue
|
27
|
+
raise InvalidUrlFormat
|
28
|
+
else uri
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def build(host, key, url, options = {})
|
33
|
+
uri = parse_url(url)
|
34
|
+
klass = match(uri, host)
|
35
|
+
klass.new(key, url, options)
|
36
|
+
end
|
37
|
+
|
38
|
+
def assign(url, options = {})
|
39
|
+
uri = parse_url(url)
|
40
|
+
klass = match(uri)
|
41
|
+
video = klass.new(nil, nil, options)
|
42
|
+
video.assign(uri)
|
43
|
+
video
|
44
|
+
end
|
45
|
+
|
46
|
+
def host
|
47
|
+
self.name.demodulize.underscore
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
attr_reader :host, :key, :url
|
52
|
+
attr_accessor :options
|
53
|
+
|
54
|
+
def initialize(key = nil, url = nil, options = {})
|
55
|
+
@host = self.class.host
|
56
|
+
@key, @url, @options = key, url, options
|
57
|
+
end
|
58
|
+
|
59
|
+
protected
|
60
|
+
def width(style)
|
61
|
+
s = get_style(style)
|
62
|
+
w = s[:width] || (s[:height].to_f * aspect_ratio).floor
|
63
|
+
w += chrome_width unless w.zero? || s[:include_chrome]
|
64
|
+
w
|
65
|
+
end
|
66
|
+
|
67
|
+
def height(style)
|
68
|
+
s = get_style(style)
|
69
|
+
h = s[:height] || (s[:width].to_f / aspect_ratio).ceil
|
70
|
+
h += chrome_height unless h.zero? || s[:include_chrome]
|
71
|
+
h
|
72
|
+
end
|
73
|
+
|
74
|
+
def aspect_ratio
|
75
|
+
16.0 / 9
|
76
|
+
end
|
77
|
+
|
78
|
+
def chrome_width
|
79
|
+
0
|
80
|
+
end
|
81
|
+
|
82
|
+
def chrome_height
|
83
|
+
0
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
def get_style(style)
|
88
|
+
case style
|
89
|
+
when nil: get_style(default_style)
|
90
|
+
when Hash: style
|
91
|
+
when String: geometry_to_style(style)
|
92
|
+
else get_style(styles.fetch(style, {}))
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def default_style
|
97
|
+
style_name = case
|
98
|
+
when @options.has_key?(:default_style): @options[:default_style]
|
99
|
+
when styles.size == 1: styles.keys.first
|
100
|
+
else :default
|
101
|
+
end
|
102
|
+
styles.fetch(style_name, {})
|
103
|
+
end
|
104
|
+
|
105
|
+
def styles
|
106
|
+
@options.fetch(:styles, {})
|
107
|
+
end
|
108
|
+
|
109
|
+
def geometry_to_style(geometry)
|
110
|
+
style = {}
|
111
|
+
style[:include_chrome] = !geometry.dup.sub!(/!$/, '').nil?
|
112
|
+
width, height = geometry.split('x')
|
113
|
+
style.merge!(:width => width.to_i, :height => height.to_i)
|
114
|
+
style.delete_if{|k,v| v == 0 }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class VideoclipError < StandardError
|
119
|
+
end
|
120
|
+
|
121
|
+
class InvalidUrlFormat < VideoclipError
|
122
|
+
end
|
123
|
+
|
124
|
+
class UnrecognizedVideoHost < VideoclipError
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module LaserLemon
|
2
|
+
module Videoclip
|
3
|
+
class Video::Blip < Video
|
4
|
+
def self.match?(uri)
|
5
|
+
(uri.host =~ /^(?:www\.)?blip\.tv$/i) && (uri.path =~ /^\/file\/\d+$/)
|
6
|
+
end
|
7
|
+
|
8
|
+
def assign(uri)
|
9
|
+
@url = "http://blip.tv#{uri.path}"
|
10
|
+
response = Net::HTTP.get(URI.parse(@url + '?skin=api'))
|
11
|
+
@key = parse_response(response, %w(response payload asset embed_lookup))
|
12
|
+
end
|
13
|
+
|
14
|
+
def embed(style = nil)
|
15
|
+
%(<embed src="http://blip.tv/play/#{@key}" type="application/x-shockwave-flash" width="#{width(style)}" height="#{height(style)}" allowscriptaccess="always" allowfullscreen="true"></embed>)
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
def chrome_height
|
20
|
+
30
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse_response(response, path, default = nil)
|
24
|
+
begin
|
25
|
+
path.collect!(&:to_s)
|
26
|
+
destination = path.pop
|
27
|
+
path.inject(Hash.from_xml(response)){|h,p| h.fetch(p, {}) }.fetch(destination, default)
|
28
|
+
rescue
|
29
|
+
default
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module LaserLemon
|
2
|
+
module Videoclip
|
3
|
+
class Video::Youtube < Video
|
4
|
+
def self.match?(uri)
|
5
|
+
(uri.host =~ /^(?:www\.)?youtube\.com$/i) && (uri.path == '/watch') && !CGI.parse(uri.query)['v'].blank?
|
6
|
+
end
|
7
|
+
|
8
|
+
def assign(uri)
|
9
|
+
@key = CGI.parse(uri.query)['v'].first
|
10
|
+
@url = "http://www.youtube.com/watch?v=#{@key}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def embed(style = nil)
|
14
|
+
%(<object width="#{width(style)}" height="#{height(style)}"><param name="movie" value="http://www.youtube.com/v/#{key}&hl=en&fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/#{key}&hl=en&fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="#{width(style)}" height="#{height(style)}"></embed></object>)
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
def chrome_height
|
19
|
+
25
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/test/test_helper.rb
ADDED
data/videoclip.gemspec
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{videoclip}
|
8
|
+
s.version = "0.2.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["laserlemon"]
|
12
|
+
s.date = %q{2009-10-07}
|
13
|
+
s.description = %q{Save videos from popular sites alongside your ActiveRecord models}
|
14
|
+
s.email = %q{steve@laserlemon.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README.rdoc",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION",
|
25
|
+
"init.rb",
|
26
|
+
"lib/videoclip.rb",
|
27
|
+
"lib/videoclip/video.rb",
|
28
|
+
"lib/videoclip/videos/blip.rb",
|
29
|
+
"lib/videoclip/videos/youtube.rb",
|
30
|
+
"test/test_helper.rb",
|
31
|
+
"test/videoclip_test.rb",
|
32
|
+
"videoclip.gemspec"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/laserlemon/videoclip}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubyforge_project = %q{laser-lemon}
|
38
|
+
s.rubygems_version = %q{1.3.5}
|
39
|
+
s.summary = %q{Save videos from popular sites alongside your ActiveRecord models}
|
40
|
+
s.test_files = [
|
41
|
+
"test/test_helper.rb",
|
42
|
+
"test/videoclip_test.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
50
|
+
else
|
51
|
+
end
|
52
|
+
else
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: videoclip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- laserlemon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-10-07 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Save videos from popular sites alongside your ActiveRecord models
|
17
|
+
email: steve@laserlemon.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .gitignore
|
27
|
+
- LICENSE
|
28
|
+
- README.rdoc
|
29
|
+
- Rakefile
|
30
|
+
- VERSION
|
31
|
+
- init.rb
|
32
|
+
- lib/videoclip.rb
|
33
|
+
- lib/videoclip/video.rb
|
34
|
+
- lib/videoclip/videos/blip.rb
|
35
|
+
- lib/videoclip/videos/youtube.rb
|
36
|
+
- test/test_helper.rb
|
37
|
+
- test/videoclip_test.rb
|
38
|
+
- videoclip.gemspec
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/laserlemon/videoclip
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --charset=UTF-8
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project: laser-lemon
|
63
|
+
rubygems_version: 1.3.5
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Save videos from popular sites alongside your ActiveRecord models
|
67
|
+
test_files:
|
68
|
+
- test/test_helper.rb
|
69
|
+
- test/videoclip_test.rb
|