video_info 0.2.0

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 ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Thibaud Guillaume-Gentil
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
@@ -0,0 +1,62 @@
1
+ = VideoInfo
2
+
3
+ Small Ruby Gem to get video info from youtube and vimeo url.
4
+
5
+ == Install
6
+
7
+ gem install video_info --source http://gemcutter.org
8
+
9
+ == Usage
10
+
11
+ video = VideoInfo.new("http://www.youtube.com/watch?v=mZqGqE0D0n4")
12
+
13
+ video.id => "mZqGqE0D0n4"
14
+ video.provider => "YouTube"
15
+ video.title => "Cherry Bloom - King Of The Knife"
16
+ video.description => "The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net"
17
+ video.keywords => "alternative, bloom, cherry, clip, drum, guitar, king, knife, of, Paris-Forum, rock, the, tremplin"
18
+ video.duration => 175 (in seconds)
19
+ video.date => Sat Apr 12 22:25:35 UTC 2008
20
+ video.thumbnail_small => "http://i.ytimg.com/vi/mZqGqE0D0n4/2.jpg"
21
+ video.thumbnail_large => "http://i.ytimg.com/vi/mZqGqE0D0n4/0.jpg"
22
+
23
+ video = VideoInfo.new("http://vimeo.com/898029")
24
+
25
+ video.id => "898029"
26
+ video.provider => "Vimeo"
27
+ video.title => "Cherry Bloom - King Of The Knife"
28
+ video.description => "The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net"
29
+ video.keywords => "alternative, bloom, cherry, clip, drum, guitar, king, knife, of, Paris-Forum, rock, the, tremplin"
30
+ video.duration => 175 (in seconds)
31
+ video.date => Mon Apr 14 13:10:39 +0200 2008
32
+ video.width => 640
33
+ video.height => 360
34
+ video.thumbnail_small => "http://ts.vimeo.com.s3.amazonaws.com/343/731/34373130_100.jpg"
35
+ video.thumbnail_large => "http://ts.vimeo.com.s3.amazonaws.com/343/731/34373130_640.jpg"
36
+
37
+ video = VideoInfo.new("http://badurl.com/898029")
38
+
39
+ video.valid? => false
40
+
41
+ == License
42
+
43
+ Copyright (c) 2008 Thibaud Guillaume-Gentil
44
+
45
+ Permission is hereby granted, free of charge, to any person obtaining
46
+ a copy of this software and associated documentation files (the
47
+ "Software"), to deal in the Software without restriction, including
48
+ without limitation the rights to use, copy, modify, merge, publish,
49
+ distribute, sublicense, and/or sell copies of the Software, and to
50
+ permit persons to whom the Software is furnished to do so, subject to
51
+ the following conditions:
52
+
53
+ The above copyright notice and this permission notice shall be
54
+ included in all copies or substantial portions of the Software.
55
+
56
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
57
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
58
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
59
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
60
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
61
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
62
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,46 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "video_info"
8
+ gem.summary = "Vimeo & Youtube parser"
9
+ gem.description = "Get video info from youtube and vimeo url."
10
+ gem.email = "thibaud@thibaud.me"
11
+ gem.homepage = "http://github.com/guillaumegentil/video_info"
12
+ gem.authors = ["Thibaud Guillaume-Gentil"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_dependency "hpricot", ">= 0.8.1"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ task :default => :spec
37
+
38
+ require 'rake/rdoctask'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "video_info #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/init.rb ADDED
File without changes
data/lib/video.rb ADDED
@@ -0,0 +1,5 @@
1
+ class Video
2
+ attr_accessor :url, :id, :provider, :title, :description, :keywords,
3
+ :duration, :date, :width, :height,
4
+ :thumbnail_small, :thumbnail_large
5
+ end
@@ -0,0 +1,28 @@
1
+ require 'hpricot'
2
+ require 'open-uri'
3
+
4
+ class Vimeo < Video
5
+
6
+ def initialize(url)
7
+ @id = url.gsub(/.*\.com\/([0-9]+).*$/i, '\1')
8
+ get_info unless @id == url
9
+ end
10
+
11
+ private
12
+
13
+ def get_info
14
+ doc = Hpricot(open("http://vimeo.com/api/v2/video/#{@id}.xml"))
15
+ @provider = "Vimeo"
16
+ @url = doc.search("url").inner_text
17
+ @title = doc.search("title").inner_text
18
+ @description = doc.search("description").inner_text
19
+ @keywords = doc.search("tags").inner_text
20
+ @duration = doc.search("duration").inner_text.to_i # seconds
21
+ @width = doc.search("width").inner_text.to_i
22
+ @height = doc.search("height").inner_text.to_i
23
+ @date = Time.parse(doc.search("upload_date").inner_text, Time.now.utc)
24
+ @thumbnail_small = doc.search("thumbnail_small").inner_text
25
+ @thumbnail_large = doc.search("thumbnail_large").inner_text
26
+ end
27
+
28
+ end
@@ -0,0 +1,26 @@
1
+ require 'hpricot'
2
+ require 'open-uri'
3
+
4
+ class Youtube < Video
5
+
6
+ def initialize(url)
7
+ @id = url.gsub(/.*v=([^&]+).*$/i, '\1')
8
+ get_info unless @id == url
9
+ end
10
+
11
+ private
12
+
13
+ def get_info
14
+ doc = Hpricot(open("http://gdata.youtube.com/feeds/api/videos/#{@id}"))
15
+ @provider = "YouTube"
16
+ @url = "http://www.youtube.com/watch?v=#{@id}"
17
+ @title = doc.search("media:title").inner_text
18
+ @description = doc.search("media:description").inner_text
19
+ @keywords = doc.search("media:keywords").inner_text
20
+ @duration = doc.search("media:content").first[:duration].to_i # seconds
21
+ @date = Time.parse(doc.search("published").inner_text, Time.now.utc)
22
+ @thumbnail_small = doc.search("media:thumbnail").first[:url]
23
+ @thumbnail_large = doc.search("media:thumbnail").last[:url]
24
+ end
25
+
26
+ end
data/lib/video_info.rb ADDED
@@ -0,0 +1,40 @@
1
+ require 'video'
2
+ require 'video/vimeo'
3
+ require 'video/youtube'
4
+
5
+ class VideoInfo
6
+
7
+ def initialize(url)
8
+ case url
9
+ when /vimeo\.com/
10
+ @video = Vimeo.new(url)
11
+ when /youtube\.com/
12
+ @video = Youtube.new(url)
13
+ end
14
+ end
15
+
16
+ def valid?
17
+ @video && !["", nil].include?(title)
18
+ end
19
+
20
+ def method_missing(sym, *args, &block)
21
+ @video.send sym, *args, &block
22
+ end
23
+
24
+ # def embed(options = {})
25
+ # width = options[:width]
26
+ # height = options[:height]
27
+ #
28
+ # allowfullscreen = options[:fullscreen]
29
+ # fullscreen = options[:fullscreen] ? 1 : 0
30
+ # show_title = options[:show_title] ? 1 : 0
31
+ # show_byline = options[:show_byline] ? 1 : 0
32
+ # show_portrait = options[:show_portrait] ? 1 : 0
33
+ # case provider
34
+ # when "Youtub"
35
+ #
36
+ # %{<object width="#{width}" height="#{height}"><param name="allowfullscreen" value="#{allowfullscreen}" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=#{id}&amp;server=vimeo.com&amp;show_title=#{show_title}&amp;show_byline=#{show_byline}&amp;show_portrait=#{show_portrait}&amp;color=00adef&amp;fullscreen=#{fullscreen}" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=#{vimeo_id}&amp;server=vimeo.com&amp;show_title=#{show_title}&amp;show_byline=#{show_byline}&amp;show_portrait=#{show_portrait}&amp;color=00adef&amp;fullscreen=#{fullscreen}" type="application/x-shockwave-flash" allowfullscreen="#{allowfullscreen}" allowscriptaccess="always" width="#{options[:width]}" height="#{options[:height]}"></embed></object>}
37
+ # %{<object width="#{options[:width]}" height="#{options[:height]}"><param name="movie" value="http://www.youtube.com/v/#{youtube_id}"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/#{id}" type="application/x-shockwave-flash" wmode="transparent" width="#{options[:width]}" height="#{options[:height]}"></embed></object>}
38
+ # end
39
+
40
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'video_info'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "VideoInfo" do
4
+
5
+ describe "from Youtube" do
6
+ subject { VideoInfo.new('http://www.youtube.com/watch?v=mZqGqE0D0n4') }
7
+
8
+ its(:provider) { should == 'YouTube' }
9
+ its(:url) { should == 'http://www.youtube.com/watch?v=mZqGqE0D0n4' }
10
+ its(:title) { should == 'Cherry Bloom - King Of The Knife' }
11
+ its(:description) { should == 'The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net' }
12
+ its(:keywords) { should == 'cherry, bloom, king, of, the, knife, guitar, drum, clip, rock, alternative, tremplin, Paris-Forum' }
13
+ its(:duration) { should == 175 }
14
+ its(:width) { should be_nil }
15
+ its(:height) { should be_nil }
16
+ its(:date) { should == Time.parse('Sat Apr 12 22:25:35 UTC 2008') }
17
+ its(:thumbnail_small) { should == 'http://i.ytimg.com/vi/mZqGqE0D0n4/2.jpg' }
18
+ its(:thumbnail_large) { should == 'http://i.ytimg.com/vi/mZqGqE0D0n4/0.jpg' }
19
+ it { should be_valid }
20
+ end
21
+
22
+ describe "from Vimeo" do
23
+ subject { VideoInfo.new('http://www.vimeo.com/898029') }
24
+
25
+ its(:provider) { should == 'Vimeo' }
26
+ its(:url) { should == 'http://vimeo.com/898029' }
27
+ its(:title) { should == 'Cherry Bloom - King Of The Knife' }
28
+ its(:description) { should == 'The first video from the upcoming album Secret Sounds, to download in-stores April 14. Checkout http://www.cherrybloom.net' }
29
+ its(:keywords) { should == 'cherry bloom, secret sounds, king of the knife, rock, alternative' }
30
+ its(:duration) { should == 175 }
31
+ its(:width) { should == 640 }
32
+ its(:height) { should == 360 }
33
+ its(:date) { should == Time.parse('Mon Apr 14 13:10:39 +0200 2008') }
34
+ its(:thumbnail_small) { should == 'http://ts.vimeo.com.s3.amazonaws.com/343/731/34373130_100.jpg' }
35
+ its(:thumbnail_large) { should == 'http://ts.vimeo.com.s3.amazonaws.com/343/731/34373130_640.jpg' }
36
+ it { should be_valid }
37
+ end
38
+
39
+ it "should be invalid with misstaped url" do
40
+ video = VideoInfo.new('http://www.vimeo.com/1')
41
+ video.should_not be_valid
42
+ end
43
+
44
+ it "should be invalid with bad url" do
45
+ video = VideoInfo.new('http://www.yasda.com/asdasd')
46
+ video.should_not be_valid
47
+ end
48
+
49
+ it "should be invalid with blank url" do
50
+ video = VideoInfo.new('')
51
+ video.should_not be_valid
52
+ end
53
+
54
+ it "should be invalid with nil url" do
55
+ video = VideoInfo.new(nil)
56
+ video.should_not be_valid
57
+ end
58
+
59
+ end
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{video_info}
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Thibaud Guillaume-Gentil"]
12
+ s.date = %q{2009-11-27}
13
+ s.description = %q{Get video info from youtube and vimeo url.}
14
+ s.email = %q{thibaud@thibaud.me}
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/video.rb",
27
+ "lib/video/vimeo.rb",
28
+ "lib/video/youtube.rb",
29
+ "lib/video_info.rb",
30
+ "spec/spec.opts",
31
+ "spec/spec_helper.rb",
32
+ "spec/video_info_spec.rb",
33
+ "video_info.gemspec"
34
+ ]
35
+ s.homepage = %q{http://github.com/guillaumegentil/video_info}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.5}
39
+ s.summary = %q{Vimeo & Youtube parser}
40
+ s.test_files = [
41
+ "spec/spec_helper.rb",
42
+ "spec/video_info_spec.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
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
51
+ s.add_runtime_dependency(%q<hpricot>, [">= 0.8.1"])
52
+ else
53
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
54
+ s.add_dependency(%q<hpricot>, [">= 0.8.1"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
58
+ s.add_dependency(%q<hpricot>, [">= 0.8.1"])
59
+ end
60
+ end
61
+
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: video_info
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Thibaud Guillaume-Gentil
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-27 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.2.9
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: hpricot
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.1
34
+ version:
35
+ description: Get video info from youtube and vimeo url.
36
+ email: thibaud@thibaud.me
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .gitignore
46
+ - LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - init.rb
51
+ - lib/video.rb
52
+ - lib/video/vimeo.rb
53
+ - lib/video/youtube.rb
54
+ - lib/video_info.rb
55
+ - spec/spec.opts
56
+ - spec/spec_helper.rb
57
+ - spec/video_info_spec.rb
58
+ - video_info.gemspec
59
+ has_rdoc: true
60
+ homepage: http://github.com/guillaumegentil/video_info
61
+ licenses: []
62
+
63
+ post_install_message:
64
+ rdoc_options:
65
+ - --charset=UTF-8
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.3.5
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Vimeo & Youtube parser
87
+ test_files:
88
+ - spec/spec_helper.rb
89
+ - spec/video_info_spec.rb