diff --git a/README.markdown b/README.markdown index da7d583..ace3ba3 100644 --- a/README.markdown +++ b/README.markdown @@ -87,11 +87,13 @@ At this moment we support the following video services: - [Youtube](http://www.youtube.com/) - [Vimeo](http://vimeo.com/) +- [Vine](http://vine.co/) +- [Giphy](http://giphy.com/) +- [Gfycat](http://gfycat.com/) - [Flickr (videos)](http://flickr.com/) - [Metacafe](http://metacafe.com/) - [Dailymotion](http://dailymotion.com/) - [Collegehumor](http://collegehumor.com/) -- ~~[Blip.tv](http://blip.tv/)~~ Transformed into maker.tv - [Myspace](http://vids.myspace.com/) - [Ted Talks](http://www.ted.com/talks/) - [11870.com](http://11870.com/) diff --git a/lib/acts_as_unvlogable/vg_gfycat.rb b/lib/acts_as_unvlogable/vg_gfycat.rb new file mode 100644 index 0000000..54227f5 --- /dev/null +++ b/lib/acts_as_unvlogable/vg_gfycat.rb @@ -0,0 +1,40 @@ +class VgGfycat + attr_accessor :video_id + + def initialize(url, options={}) + @url = url + @uri = URI.parse(url) + @video_id = @uri.path.split("/")[-1] + json_endpoint = "https://gfycat.com/cajax/get/#{@video_id}" + @json = JSON.parse(Net::HTTP.get(URI.parse(json_endpoint))) + raise ArgumentError unless @video_id or @json["error"] + end + + def title + @title ||= @json["gfyItem"]["title"] + end + + def thumbnail + @thumbnail ||= @json["gfyItem"]["posterUrl"] + end + + def embed_url + @embed_url ||= @json["gfyItem"]["mp4Url"] + end + + def embed_html(width=425, height=344, options={}, params={}) + "" + end + + def download_url + nil + end + + def duration + nil + end + + def service + "Gfycat" + end +end diff --git a/lib/acts_as_unvlogable/vg_giphy.rb b/lib/acts_as_unvlogable/vg_giphy.rb index 8501065..1a6f48b 100644 --- a/lib/acts_as_unvlogable/vg_giphy.rb +++ b/lib/acts_as_unvlogable/vg_giphy.rb @@ -19,7 +19,7 @@ def thumbnail end def embed_url - @embed_url = @json["data"][0]["images"]["looping"]["mp4"] + @embed_url ||= @json["data"][0]["images"]["looping"]["mp4"] end def embed_html(width=425, height=344, options={}, params={}) diff --git a/lib/acts_as_unvlogable/vg_vine.rb b/lib/acts_as_unvlogable/vg_vine.rb index 8a4e6f7..afdfa4c 100644 --- a/lib/acts_as_unvlogable/vg_vine.rb +++ b/lib/acts_as_unvlogable/vg_vine.rb @@ -19,7 +19,7 @@ def thumbnail end def embed_url - @embed_url = "#{@url}/embed/simple" + @embed_url ||= "#{@url}/embed/simple" end def embed_html(width=600, height=600, options={}, params={}) diff --git a/spec/acts_as_unvlogable_spec.rb b/spec/acts_as_unvlogable_spec.rb index d47c38f..f4491e1 100644 --- a/spec/acts_as_unvlogable_spec.rb +++ b/spec/acts_as_unvlogable_spec.rb @@ -285,6 +285,54 @@ end end +# ---------------------------------------------------------- +# Testing gfycat +# ---------------------------------------------------------- + context "with an existent gfycat url" do + let(:videotron) { UnvlogIt.new("https://gfycat.com/WarmheartedAnyFairyfly") } + + it "initialize a VgGfycat instance" do + expect(VgGfycat).to eq(videotron.instance_values['object'].class) + expect("https://gfycat.com/WarmheartedAnyFairyfly").to eq(videotron.instance_values['object'].instance_values['url']) + expect("WarmheartedAnyFairyfly").to eq(videotron.instance_values['object'].instance_values['video_id']) + expect(videotron.instance_values['object'].instance_values['json']).to_not be_nil + end + + it "returns the video properties" do + check_video_attributes({:title => "", :service => "Gfycat"}) + end + end + + context "with an detail gfycat url" do + let(:videotron) { UnvlogIt.new("https://gfycat.com/detail/DelectableParchedCopperbutterfly?tagname=Trending&tvmode=1") } + + it "initialize a VgGfycat instance" do + expect(VgGfycat).to eq(videotron.instance_values['object'].class) + expect("https://gfycat.com/detail/DelectableParchedCopperbutterfly?tagname=Trending&tvmode=1").to eq(videotron.instance_values['object'].instance_values['url']) + expect("DelectableParchedCopperbutterfly").to eq(videotron.instance_values['object'].instance_values['video_id']) + expect(videotron.instance_values['object'].instance_values['json']).to_not be_nil + end + + it "returns the video properties" do + check_video_attributes({:title => "Ryan Williams landed a 1080 frontflip", :service => "Gfycat"}) + end + end + + context "with an search gfycat url" do + let(:videotron) { UnvlogIt.new("https://gfycat.com/gifs/search/cats/detail/BeneficialFavorableBunting") } + + it "initialize a VgGfycat instance" do + expect(VgGfycat).to eq(videotron.instance_values['object'].class) + expect("https://gfycat.com/gifs/search/cats/detail/BeneficialFavorableBunting").to eq(videotron.instance_values['object'].instance_values['url']) + expect("BeneficialFavorableBunting").to eq(videotron.instance_values['object'].instance_values['video_id']) + expect(videotron.instance_values['object'].instance_values['json']).to_not be_nil + end + + it "returns the video properties" do + check_video_attributes({:title => "High Five Cat", :service => "Gfycat"}) + end + end + # ---------------------------------------------------------- # Testing RuTube # ----------------------------------------------------------