reddavis-embedit 0.0.4 → 0.0.5

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/README CHANGED
@@ -17,6 +17,12 @@ At the time of writing, you now have the ability to call:
17
17
  media.url => The url to the media
18
18
  media.html => The embed code, whether this is a generic flash player, a company player (Vimeo, Youtube), image tag and more to come
19
19
 
20
- You also specify media sizes => media.html(:width => 200, :height => 700)
20
+ You also specify media sizes => media.html(:width => 200, :height => 700)
21
+
22
+ You can also validate an url (useful for a active record (or whatever you use) validation)
23
+ media.valid? => Returns true or false
21
24
 
22
- At the moment Embedit supports the oEmbed family (http://www.oembed.com/) and YouTube.
25
+ At the moment Embedit supports:
26
+ - oEmbed family (http://www.oembed.com/)
27
+ - YouTube (http://youtube.com)
28
+ - OVI (http://share.ovi.com/)
data/lib/embedit/media.rb CHANGED
@@ -8,8 +8,8 @@ module Embedit
8
8
  @valid = true #Innocent until proven guilty
9
9
  @oembed_providers = Providers.new.sites
10
10
  find_provider(url)
11
- rescue #Horrible hack, but flickrs poor status headers == :( if it breaks, its gotta be invalid
12
- @valid = false
11
+ rescue #Horrible hack, but flickrs poor status headers == :(
12
+ @valid = false #if it breaks, its gotta be invalid, I suggest removing when debugging
13
13
  end
14
14
 
15
15
  def title
@@ -37,16 +37,19 @@ module Embedit
37
37
 
38
38
  #Find a provider
39
39
  def find_provider(url)
40
+ return @valid = false unless Validate.new(url).valid?
41
+
40
42
  @oembed_providers.keys.each do |key| #First search oembed providers for a match
41
- if url.match(/(\.|\/)#{key}\./) && Validate.new(url).valid? #URL can be www.vimeo.com || http://vimeo.com
43
+ if url.match(/(\.|\/)#{key}\./) #URL can be www.vimeo.com || http://vimeo.com
42
44
  return @media_data = Oembed.new(url, key)
43
45
  end
44
46
  end
45
- if url.match(/(\.|\/)youtube\./) && Validate.new(url).valid? #Next up is YouTube
47
+ if url.match(/(\.|\/)youtube\./) #Next up is YouTube
46
48
  return @media_data = YouTube.new(url)
49
+ elsif url.match(/share\.ovi\.com/)
50
+ return @media_data = Ovi.new(url)
47
51
  end
48
52
  @valid = false
49
53
  end
50
-
51
54
  end
52
55
  end
@@ -0,0 +1,42 @@
1
+ #http://share.ovi.com - They have no API so screen scrape probably best solution here
2
+
3
+ module Embedit
4
+
5
+ class Ovi
6
+ require 'hpricot'
7
+
8
+ attr_reader :title, :url, :format
9
+
10
+ def initialize(url)
11
+ page = Hpricot(open(url))
12
+ @url= url
13
+ work_out_html(page)
14
+ work_out_format(@html)
15
+ @title = page.search("h2.pagetitle").inner_html.strip
16
+ end
17
+
18
+ def html(size = {})
19
+ @html.gsub!(/height="\d+"/, %{height="#{size[:height]}"}) if size[:height]
20
+ @html.gsub!(/width="\d+"/, %{width="#{size[:width]}"}) if size[:width]
21
+ @html
22
+ end
23
+
24
+ private
25
+
26
+ def work_out_html(page)
27
+ @html = page.search("tr#M_sidebar_uimediaembed_uifp1 td input").first.attributes['value'] rescue nil #We first search for video or audio, if not its got to be image (hopfully)
28
+ if @html.nil?
29
+ @html = page.search("div#M_sidebar_uimediaembed_uiip td input#M_sidebar_uimediaembed_uihtml2").first.attributes['value'].gsub(/<a \S+>/, '').gsub(/<\/a>/, '') #Follow Embedit convention, images should not be surrounded a a <a href></a>
30
+ end
31
+ end
32
+
33
+ def work_out_format(html)
34
+ case html
35
+ when /flash\/player\.aspx\?media/ then @format = 'video'
36
+ when /flash\/audioplayer\.aspx\?media/ then @format = 'audio'
37
+ when /<img src/ then @format = 'photo'
38
+ end
39
+ end
40
+
41
+ end
42
+ end
@@ -33,6 +33,8 @@ class Validate
33
33
  # Now we go through all services not linked with oEmbed
34
34
  if @url.match(/(\.|\/)youtube\./) #All youtube links should end with a .com (Please correct if I'm wrong) they get redirected to jp.youtube.com or whatever
35
35
  return true
36
+ elsif @url.match(/share\.ovi\.com/)
37
+ return true
36
38
  end
37
39
  return false #Return false if all else fail
38
40
  end
data/lib/embedit.rb CHANGED
@@ -10,15 +10,16 @@ require 'embedit/providers'
10
10
  require 'embedit/media'
11
11
  require 'embedit/oembed'
12
12
  require 'embedit/youtube'
13
+ require 'embedit/ovi'
13
14
  require 'embedit/exceptions'
14
15
  require 'embedit/validate'
15
16
 
16
17
 
17
- #puts a = Embedit::Media.new('http://www.vimeo.com/1263763').valid?
18
+ #puts a = Embedit::Media.new('http://www.vimeo.com/1263763').html
18
19
 
19
- #puts b = Embedit::Media.new('http://www.flickr.com/photos/kentfield/2735062540/').valid? #.valid #.html(:height => 200)
20
+ #puts b = Embedit::Media.new('http://www.flickr.com/photos/reddavis999/2692043113/').html #valid? #.valid #.html(:height => 200)
20
21
 
21
- #puts c = Embedit::Media.new('http://www.viddler.com/explore/winelibrarytv/videos/14212300/').html(:height => 200, :width => 500)
22
+ #puts c = Embedit::Media.new('http://www.viddler.com/explore/winelibrarytv/videos/147/').format #html(:height => 200, :width => 500)
22
23
 
23
24
  #puts d = Embedit::Media.new('http://qik.com/video/141977').html(:height => 50)
24
25
 
@@ -28,7 +29,14 @@ require 'embedit/validate'
28
29
 
29
30
  #YouTUBE
30
31
 
31
- #puts g = Embedit::Media.new("http://www.youtube.com/watch?v=j3TOT1lnVTA")
32
+ #puts g = Embedit::Media.new("http://www.youtube.com/watch?v=j3TOT1lnVTA").title
32
33
 
33
34
  #puts Validate.new('http://www.flickr.com/photos/kentfield/2735062540/').valid?
34
35
 
36
+ #OVI
37
+
38
+ #puts a = Embedit::Media.new('http://share.ovi.com/media/james___.public/james___.10016').html(:height => 900, :width => 100)
39
+
40
+ #puts b = Embedit::Media.new('http://share.ovi.com/media/DefragTV.public/DefragTV.10014').html#(:height => 900, :width => 100)
41
+
42
+ #puts c = Embedit::Media.new('http://share.ovi.com/media/james___.public/james___.10016').html(:height => 900, :width => 100)
data/spec/oembed_spec.rb CHANGED
@@ -1,61 +1,139 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe "Vimeo oEmbed tests" do
4
-
4
+
5
5
  it "should properly validate a valid Vimeo url" do
6
6
  media = Embedit::Media.new('http://www.vimeo.com/1263763').valid?
7
7
  media.should == true
8
8
  end
9
9
 
10
+ it "should show this videos title as 'Matt Week - Day One Time Lapse'" do
11
+ media = Embedit::Media.new('http://www.vimeo.com/1263763').title
12
+ media.should == 'Matt Week - Day One Time Lapse'
13
+ end
14
+
15
+ it "should show the format as video" do
16
+ media = Embedit::Media.new('http://www.vimeo.com/1263763').format
17
+ media.should == 'video'
18
+ end
19
+
10
20
  it "should validate an invalid (with only numbers) Vimeo url" do
11
21
  media = Embedit::Media.new('http://www.vimeo.com/126007722').valid?
12
22
  media.should == false
13
23
  end
14
24
 
15
- it "should validate an invalid (with some letters) Vimeo url" do
16
- media = Embedit::Media.new('http://www.vimeo.com/126badurl').valid?
17
- media.should == false
18
- end
19
-
20
25
  end
21
26
 
22
27
  describe "Flickr oEmbed tests" do
23
28
 
24
- it "should properly validate a valid Flickr url" do
29
+ it "should validate a valid Flickr url" do
25
30
  media = Embedit::Media.new('http://www.flickr.com/photos/asianmack/2781811902/in/set-72157606856535809/').valid?
26
31
  media.should == true
27
32
  end
28
33
 
29
- it "should properly validate an invalid (with only numbers) Flickr url" do
34
+ it "should show this pictures title as 'Logan Square" do
35
+ media = Embedit::Media.new('http://www.flickr.com/photos/asianmack/2781811902/in/set-72157606856535809/').title
36
+ media.should == 'Logan Square'
37
+ end
38
+
39
+ it "should show the format as photo" do
40
+ media = Embedit::Media.new('http://www.flickr.com/photos/asianmack/2781811902/in/set-72157606856535809/').format
41
+ media.should == 'photo'
42
+ end
43
+
44
+ it "should validate an invalid Flickr url" do
30
45
  media = Embedit::Media.new('http://www.flickr.com/photos/banuelos_ismael/280428728023/').valid?
31
46
  media.should == false
32
47
  end
33
48
 
34
- it "should properly validate an invalid (with some letters) Flickr url" do
35
- media = Embedit::Media.new('http://www.flickr.com/photos/banuelos_ismael/2804287asd23/').valid?
49
+ end
50
+
51
+ describe "Viddler oEmbed tests" do
52
+
53
+ it "should validate a valid Viddler url" do
54
+ media = Embedit::Media.new('http://www.viddler.com/explore/winelibrarytv/videos/635/').valid?
55
+ media.should == true
56
+ end
57
+
58
+ it "should show this videos title as 'episode526'" do
59
+ media = Embedit::Media.new('http://www.viddler.com/explore/winelibrarytv/videos/635/').title
60
+ media.should == 'episode526'
61
+ end
62
+
63
+ it "should show the format as video" do
64
+ media = Embedit::Media.new('http://www.viddler.com/explore/winelibrarytv/videos/635/').format
65
+ media.should == 'video'
66
+ end
67
+
68
+ it "should validate an invalid Viddler url" do
69
+ media = Embedit::Media.new('http://www.viddler.com/explore/winelibrarytv/videos/635222/').valid?
36
70
  media.should == false
37
71
  end
38
72
 
39
- it "should properly validate an invalid (with some letters) Flickr url" do
40
- media = Embedit::Media.new('http://www.flickr.com/photos/banuelos_ismael/2804287asd23/').valid?
73
+ end
74
+
75
+ describe "Qik oEmbed tests" do
76
+
77
+ it "should validate a valid Qik url" do
78
+ media = Embedit::Media.new('http://qik.com/video/239734').valid?
79
+ media.should == true
80
+ end
81
+
82
+ it "should show this videos title as 'heading to the digg tent at dnc'" do
83
+ media = Embedit::Media.new('http://qik.com/video/239734').title
84
+ media.should == 'heading to the digg tent at dnc'
85
+ end
86
+
87
+ it "should show the format as video" do
88
+ media = Embedit::Media.new('http://qik.com/video/239734').format
89
+ media.should == 'video'
90
+ end
91
+
92
+ it "should validate an invalid Qik url" do
93
+ media = Embedit::Media.new('http://qik.com/video/2397342222132131').valid?
41
94
  media.should == false
42
95
  end
96
+
97
+ end
98
+
99
+ describe "Pownce oEmbed tests" do
100
+
101
+ it "should validate a valid Pownce url" do
102
+ media = Embedit::Media.new('http://pownce.com/dburka/notes/2951118/').valid?
103
+ media.should == true
104
+ end
43
105
 
44
- it "should properly validate an invalid Flickr url photos/url-here" do
45
- media = Embedit::Media.new('http://www.flickr.com/photos/as').valid?
106
+ it "should show the format as video" do
107
+ media = Embedit::Media.new('http://pownce.com/dburka/notes/2951118/').format
108
+ media.should == 'video'
109
+ end
110
+
111
+ it "should validate a invalid Pownce url" do
112
+ media = Embedit::Media.new('http://pownce.com/dburka/notes/295111822/').valid?
46
113
  media.should == false
47
114
  end
48
115
 
49
116
  end
50
117
 
51
- describe "Viddler oEmbed tests" do
52
- it "should properly validate a valid Viddler url" do
53
- media = Embedit::Media.new('http://www.viddler.com/explore/winelibrarytv/videos/635/').valid?
118
+ describe "Revision3 oEmbed tests" do
119
+
120
+ it "should validate a valid Rev3 url" do
121
+ media = Embedit::Media.new('http://revision3.com/trs/FlipOut/?autoplay=true&hp').valid?
54
122
  media.should == true
55
123
  end
124
+
125
+ it "should show this videos title as 'heading to the digg tent at dnc'" do
126
+ media = Embedit::Media.new('http://revision3.com/trs/FlipOut/?autoplay=true&hp').title
127
+ media.should == 'Flipping Out - Hamlet 2, Traitor, Castle Crashers, Mario Super Sluggers, Planetary, and Transmetropolitan'
128
+ end
56
129
 
57
- it "should properly validate an invalid (with only numbers) Viddler url" do
58
- media = Embedit::Media.new('http://www.viddler.com/explore/winelibrarytv/videos/635222/').valid?
130
+ it "should show the format as video" do
131
+ media = Embedit::Media.new('http://revision3.com/trs/FlipOut/?autoplay=true&hp').format
132
+ media.should == 'video'
133
+ end
134
+
135
+ it "should validate a invalid Rev3 url" do
136
+ media = Embedit::Media.new('http://revision3.com/trsa/FqlipOusat/?autoplay=true&hp').valid?
59
137
  media.should == false
60
138
  end
61
139
 
data/spec/ovi_spec.rb ADDED
@@ -0,0 +1,35 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "Ovi tests" do
4
+
5
+ it "should show video format for video" do
6
+ create_media('http://share.ovi.com/media/DefragTV.public/DefragTV.10014').format.should == 'video'
7
+ end
8
+
9
+ it "should show video title as 'NetworkWorld Talks Automatic Defrag'" do
10
+ create_media('http://share.ovi.com/media/DefragTV.public/DefragTV.10014').title.should == 'NetworkWorld Talks Automatic Defrag'
11
+ end
12
+
13
+ it "should show audio format for audio" do
14
+ create_media('http://share.ovi.com/media/ekki808.mu-sick/ekki808.10001').format.should == 'audio'
15
+ end
16
+
17
+ it "should show audio title as 'mon'" do
18
+ create_media('http://share.ovi.com/media/ekki808.mu-sick/ekki808.10001').title.should == 'mon'
19
+ end
20
+
21
+ it "should show photo format for photo" do
22
+ create_media('http://share.ovi.com/media/james___.public/james___.10016').format.should == 'photo'
23
+ end
24
+
25
+ it "should show photo title as 'Tom Arnold at Westbury'" do
26
+ create_media('http://share.ovi.com/media/james___.public/james___.10016').title.should == 'Tom Arnold at Westbury'
27
+ end
28
+
29
+ private
30
+
31
+ def create_media(url)
32
+ Embedit::Media.new(url)
33
+ end
34
+
35
+ end
@@ -0,0 +1,31 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe "YouTube tests" do
4
+
5
+ it "should show true on valid url" do
6
+ a = create_media("http://www.youtube.com/watch?v=j3TOT1lnVTA").valid?
7
+ a.should == true
8
+ end
9
+
10
+ it "should have the title of 'Best robot dance ever'" do
11
+ a = create_media("http://www.youtube.com/watch?v=j3TOT1lnVTA").title
12
+ a.should == 'Best robot dance ever'
13
+ end
14
+
15
+ it "should show format as video" do
16
+ a = create_media("http://www.youtube.com/watch?v=j3TOT1lnVTA").format
17
+ a.should == 'video'
18
+ end
19
+
20
+ it "should show false on invalid url" do
21
+ a = create_media("http://www.youtube.com/watch?v=j3TOT1lnVTWWWWWWA").valid?
22
+ a.should == false
23
+ end
24
+
25
+ private
26
+
27
+ def create_media(url)
28
+ Embedit::Media.new(url)
29
+ end
30
+
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reddavis-embedit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Red Davis
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-27 14:41:48 -07:00
12
+ date: 2008-09-04 04:28:32 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -31,8 +31,11 @@ files:
31
31
  - lib/embedit/oembed.rb
32
32
  - lib/embedit/exceptions.rb
33
33
  - lib/embedit/validate.rb
34
+ - lib/embedit/ovi.rb
34
35
  - spec/spec_helper.rb
35
36
  - spec/oembed_spec.rb
37
+ - spec/youtube_spec.rb
38
+ - spec/ovi_spec.rb
36
39
  has_rdoc: false
37
40
  homepage: http://github.com/reddavis/embedit/
38
41
  post_install_message:
@@ -58,6 +61,6 @@ rubyforge_project:
58
61
  rubygems_version: 1.2.0
59
62
  signing_key:
60
63
  specification_version: 2
61
- summary: Ruby interface for embedding any media
64
+ summary: Ruby interface for embedding a range of media
62
65
  test_files: []
63
66