Skip to content

Commit

Permalink
adding gfycat
Browse files Browse the repository at this point in the history
  • Loading branch information
mamuso committed Jul 24, 2016
1 parent e0ffc44 commit 2e380bc
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.markdown
Expand Up @@ -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/)
Expand Down
40 changes: 40 additions & 0 deletions 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={})
"<video id='giphyplayer' width='#{width}' height='#{height}' controls autoplay><source src='#{@embed_url}' type='video/mp4'>Your browser does not support mp4.</video>"
end

def download_url
nil
end

def duration
nil
end

def service
"Gfycat"
end
end
2 changes: 1 addition & 1 deletion lib/acts_as_unvlogable/vg_giphy.rb
Expand Up @@ -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={})
Expand Down
2 changes: 1 addition & 1 deletion lib/acts_as_unvlogable/vg_vine.rb
Expand Up @@ -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={})
Expand Down
48 changes: 48 additions & 0 deletions spec/acts_as_unvlogable_spec.rb
Expand Up @@ -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
# ----------------------------------------------------------
Expand Down

0 comments on commit 2e380bc

Please sign in to comment.