hosted_video 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3a6a7e853650beed5f23d9f8eda9a4846870b722
4
- data.tar.gz: aca5db0ccd9aeddf127e92e65b1870a8d859ea4b
3
+ metadata.gz: 7de6ddafdc048c125a565f8c3af73ee3ac0a980f
4
+ data.tar.gz: ba024b1e762357a3b6790409d56b6820d959e49b
5
5
  SHA512:
6
- metadata.gz: 069b1ce6d284e915ab9380eababc2cb0c6710c9809a1fa30b2f807829667c16d93114e0a1e2279f4f5c47e0f4b72d95ce665059e139981476aff2eab82685d51
7
- data.tar.gz: 356aa45d53fc31fa6c691fab168f7ec19a439a488da97a42e4540e56346be5434cc915526e8e08cd4deab17ee3d5c2e28acc9e17a638b90cf0342d93edfd3a03
6
+ metadata.gz: 3d681ba4a1e99802556b93d05de4f08fd683af6fd5e20504dd2f57b9c53666cf42a8485bfacf714c3d6177362fb9d4964ca293a812a37e67b7363b1a7f80185a
7
+ data.tar.gz: 1c6d1bf026fe4e71632daddab92ed569c58789f5388e8c1d4989787030c076e6f3c156dc1f07fdc76637f9b2eebe06266d1a0eb674d73d2e90ec432492040074
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
- # HostedVideo
1
+ hosted_video
2
+ ============
3
+ [![Build Status](https://travis-ci.org/pascalevi4/hosted_video.svg?branch=master)](https://travis-ci.org/pascalevi4/hosted_video)
4
+ [![Code Climate](https://codeclimate.com/github/pascalevi4/hosted_video.png)](https://codeclimate.com/github/pascalevi4/hosted_video)
2
5
 
3
- TODO: Write a gem description
6
+ Ruby gem for parsing urls to determine video hostings and get video details. Youtube, Rutube and Vimeo services are supported.
4
7
 
5
8
  ## Installation
6
9
 
@@ -18,7 +21,12 @@ Or install it yourself as:
18
21
 
19
22
  ## Usage
20
23
 
21
- TODO: Write usage instructions here
24
+ ```ruby
25
+ video = HostedVideo.from_url('http://www.youtube.com/watch?v=TBKN7_vx2xo')
26
+ video.vid # => "TBKN7_vx2xo"
27
+ video.preview # => "http://img.youtube.com/vi/TBKN7_vx2xo/hqdefault.jpg"
28
+ video.iframe_code # => "<iframe width='420' height='315' frameborder='0' src='http://www.youtube.com/embed/TBKN7_vx2xo?wmode=transparent'></iframe>"
29
+ ```
22
30
 
23
31
  ## Contributing
24
32
 
@@ -0,0 +1,24 @@
1
+ module HostedVideo
2
+ module Providers
3
+ class RutubeByIframe < Base
4
+ def self.can_parse?(url)
5
+ url =~ /rutube\.ru\/video\/embed\/(\w{32}|\w{7}).*/
6
+ end
7
+
8
+ def preview
9
+ JSON.load(open("http://rutube.ru/api/video/#{vid}/?format=json"))['thumbnail_url']
10
+ end
11
+
12
+ def url_for_iframe
13
+ "http://rutube.ru/video/embed/#{vid}"
14
+ end
15
+
16
+ private
17
+
18
+ def vid_regex
19
+ /rutube\.ru\/video\/embed\/(?<id>\w{32}|\w{7}).*/
20
+ end
21
+ end
22
+ end
23
+ end
24
+
@@ -0,0 +1,23 @@
1
+ module HostedVideo
2
+ module Providers
3
+ class VimeoByIframe < Base
4
+ def self.can_parse?(url)
5
+ url =~ /player\.vimeo\.com\/video\/\d{7,8}.*/
6
+ end
7
+
8
+ def preview
9
+ JSON.load(open("http://vimeo.com/api/v2/video/#{vid}.json")).first['thumbnail_large']
10
+ end
11
+
12
+ def url_for_iframe
13
+ "http://player.vimeo.com/video/#{vid}?api=0"
14
+ end
15
+
16
+ private
17
+
18
+ def vid_regex
19
+ /player\.vimeo\.com\/video\/(?<id>\d{7,8}).*/
20
+ end
21
+ end
22
+ end
23
+ end
@@ -3,7 +3,7 @@ module HostedVideo
3
3
  class Youtube < Base
4
4
 
5
5
  def self.can_parse?(url)
6
- url =~ /(youtube\.com\/)|(youtu\.be)/
6
+ url =~ /(youtube\.com\/watch\?v=)|(youtu\.be\/)/
7
7
  end
8
8
 
9
9
  def preview
@@ -0,0 +1,24 @@
1
+ module HostedVideo
2
+ module Providers
3
+ class YoutubeByIframe < Base
4
+
5
+ def self.can_parse?(url)
6
+ url =~ /youtube\.com\/embed\/[\w,-]{11}(\?.*)?/
7
+ end
8
+
9
+ def preview
10
+ "http://img.youtube.com/vi/#{vid}/hqdefault.jpg"
11
+ end
12
+
13
+ def url_for_iframe
14
+ "http://www.youtube.com/embed/#{vid}?wmode=transparent"
15
+ end
16
+
17
+ private
18
+
19
+ def vid_regex
20
+ /youtube\.com\/embed\/(?<id>[\w,-]{11})(\?.*)?/
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module HostedVideo
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -29,7 +29,7 @@ describe HostedVideo do
29
29
  end
30
30
  end
31
31
 
32
- context 'youtube' do
32
+ context 'youtube url' do
33
33
  let(:parser) { subject.from_url('http://www.youtube.com/watch?v=4wTLjEqj5Xk&a=GxdCwVVULXctT2lYDEPllDR0LRTutYfW') }
34
34
 
35
35
  it 'successfully determines' do
@@ -62,7 +62,33 @@ describe HostedVideo do
62
62
  end
63
63
  end
64
64
 
65
- context 'vimeo' do
65
+ context 'youtube by iframe src url' do
66
+ let(:parser) { subject.from_url('//www.youtube.com/embed/MT4oShGnFuw?wmode=transparent') }
67
+
68
+ it 'successfully determines' do
69
+ parser.kind.should == 'youtubebyiframe'
70
+ end
71
+
72
+ it 'gets right video id' do
73
+ parser.vid.should == 'MT4oShGnFuw'
74
+ end
75
+
76
+ it 'gets right preview url' do
77
+ parser.preview.should == "http://img.youtube.com/vi/MT4oShGnFuw/hqdefault.jpg"
78
+ end
79
+
80
+ describe 'iframe_code' do
81
+ it 'gets right iframe html' do
82
+ parser.iframe_code.should == "<iframe width='420' height='315' frameborder='0' src='http://www.youtube.com/embed/MT4oShGnFuw?wmode=transparent'></iframe>"
83
+ end
84
+
85
+ it 'receives attributes and applies them to iframe tag' do
86
+ parser.iframe_code({ wmode: true }).should == "<iframe width='420' height='315' frameborder='0' wmode='true' src='http://www.youtube.com/embed/MT4oShGnFuw?wmode=transparent'></iframe>"
87
+ end
88
+ end
89
+ end
90
+
91
+ context 'vimeo url' do
66
92
  let(:parser) { subject.from_url('https://vimeo.com/63645580') }
67
93
 
68
94
  it 'successfully determines' do
@@ -90,7 +116,35 @@ describe HostedVideo do
90
116
  end
91
117
  end
92
118
 
93
- context 'rutube' do
119
+ context 'vimeo iframe src url' do
120
+ let(:parser) { subject.from_url('//player.vimeo.com/video/33481092') }
121
+
122
+ it 'successfully determines' do
123
+ parser.kind.should == 'vimeobyiframe'
124
+ end
125
+
126
+ it 'gets right video id' do
127
+ parser.vid.should == '33481092'
128
+ end
129
+
130
+ it 'get right preview url' do
131
+ stub_request(:get, "http://vimeo.com/api/v2/video/33481092.json")
132
+ .to_return(:body => "[{\"id\":33481092,\"title\":\"lalala\",\"description\":\"\",\"url\":\"http:\\/\\/vimeo.com\\/33481092\",\"upload_date\":\"2011-12-11 08:32:29\",\"thumbnail_small\":\"http:\\/\\/i.vimeocdn.com\\/video\\/227287871_100x75.jpg\",\"thumbnail_medium\":\"http:\\/\\/i.vimeocdn.com\\/video\\/227287871_200x150.jpg\",\"thumbnail_large\":\"http:\\/\\/i.vimeocdn.com\\/video\\/33481092_640.jpg\",\"user_id\":7790763,\"user_name\":\"Thomas Schank\",\"user_url\":\"http:\\/\\/vimeo.com\\/drtom\",\"user_portrait_small\":\"http:\\/\\/www.gravatar.com\\/avatar\\/4edb77ba747ee69a9540046a24611981?d=http%3A%2F%2Fi.vimeocdn.com%2Fportrait%2Fdefault-red_30x30.png&s=30\",\"user_portrait_medium\":\"http:\\/\\/www.gravatar.com\\/avatar\\/4edb77ba747ee69a9540046a24611981?d=http%3A%2F%2Fi.vimeocdn.com%2Fportrait%2Fdefault-red_75x75.png&s=75\",\"user_portrait_large\":\"http:\\/\\/www.gravatar.com\\/avatar\\/4edb77ba747ee69a9540046a24611981?d=http%3A%2F%2Fi.vimeocdn.com%2Fportrait%2Fdefault-red_100x100.png&s=100\",\"user_portrait_huge\":\"http:\\/\\/www.gravatar.com\\/avatar\\/4edb77ba747ee69a9540046a24611981?d=http%3A%2F%2Fi.vimeocdn.com%2Fportrait%2Fdefault-red_300x300.png&s=300\",\"stats_number_of_likes\":5,\"stats_number_of_plays\":221,\"stats_number_of_comments\":0,\"duration\":791,\"width\":640,\"height\":360,\"tags\":\"ruby, programming language, eigenclass, object hierarchy\",\"embed_privacy\":\"anywhere\"}]", :status => 200, :headers => { 'Content-Length' => 3 })
133
+ parser.preview.should == "http://i.vimeocdn.com/video/33481092_640.jpg"
134
+ end
135
+
136
+ describe 'iframe_code' do
137
+ it 'gets right iframe html' do
138
+ parser.iframe_code.should == "<iframe width='420' height='315' frameborder='0' src='http://player.vimeo.com/video/33481092?api=0'></iframe>"
139
+ end
140
+
141
+ it 'receives attributes and applies them to iframe tag' do
142
+ parser.iframe_code({ wmode: true }).should == "<iframe width='420' height='315' frameborder='0' wmode='true' src='http://player.vimeo.com/video/33481092?api=0'></iframe>"
143
+ end
144
+ end
145
+ end
146
+
147
+ context 'rutube url' do
94
148
  let(:parser) { subject.from_url('http://rutube.ru/video/52b48444f3efcfd2c2346972dfa16d6c/') }
95
149
 
96
150
  it 'successfully determines' do
@@ -119,4 +173,33 @@ describe HostedVideo do
119
173
  end
120
174
  end
121
175
 
176
+ context 'rutube iframe src url' do
177
+ let(:parser) { subject.from_url('http://rutube.ru/video/embed/94867125d81559df05cbcd3713a67c78') }
178
+
179
+ it 'successfully determines' do
180
+ parser.kind.should == 'rutubebyiframe'
181
+ end
182
+
183
+ it 'gets right video id' do
184
+ parser.vid.should == '94867125d81559df05cbcd3713a67c78'
185
+ end
186
+
187
+ it 'get right preview url' do
188
+ stub_request(:get, "http://rutube.ru/api/video/94867125d81559df05cbcd3713a67c78/?format=json")
189
+ .to_return(:body => "{\"description\": \"\\u043f\\u043e\\u0434\\u0431\\u043e\\u0440\\u043a\\u0430\", \"title\": \"\\u043f\\u0440\\u043e\\u0432\\u0438\\u043d\\u0438\\u0432\\u0448\\u0438\\u0435\\u0441\\u044f \\u0441\\u043e\\u0431\\u0430\\u043a\\u0438\", \"is_hidden\": false, \"created_ts\": \"2014-04-08T10:12:50\", \"html\": \"<iframe width=\\\"720\\\" height=\\\"405\\\" src=\\\"//rutube.ru/video/embed/6910411\\\" frameborder=\\\"0\\\" webkitAllowFullScreen mozallowfullscreen allowfullscreen></iframe>\", \"id\": \"52b48444f3efcfd2c2346972dfa16d6c\", \"thumbnail_url\": \"http://pic.rutube.ru/video/1d/c8/94867125d81559df05cbcd3713a67c78.jpg\", \"for_registered\": false, \"for_linked\": false, \"video_url\": \"http://rutube.ru/video/52b48444f3efcfd2c2346972dfa16d6c/\", \"duration\": 287, \"has_high_quality\": true, \"hits\": 3302, \"is_adult\": false, \"is_deleted\": false, \"last_update_ts\": \"2014-04-08T15:51:41\", \"embed_url\": \"http://rutube.ru/video/embed/6910411\", \"source_url\": \"http://rutube.ru/tracks/6910411.html\", \"is_external\": false, \"author\": {\"id\": 216135, \"name\": \"NADEZHDA\", \"avatar_url\": \"http://pic.rutube.ru/user/f8/5f/f85ff0c9f3e57858502ff5fff0058af7.jpeg\", \"site_url\": \"http://rutube.ru/video/person/216135/\"}, \"category\": {\"id\": 10, \"category_url\": \"http://rutube.ru/video/category/10/\", \"name\": \"\\u0416\\u0438\\u0432\\u043e\\u0442\\u043d\\u044b\\u0435\"}, \"picture_url\": \"\", \"rutube_poster\": null, \"is_official\": false, \"restrictions\": null, \"action_reason\": 0, \"show\": null, \"persons\": \"http://rutube.ru/api/metainfo/video/52b48444f3efcfd2c2346972dfa16d6c/videoperson\", \"genres\": \"http://rutube.ru/api/metainfo/video/52b48444f3efcfd2c2346972dfa16d6c/videogenre\", \"music\": null, \"track_id\": 6910411}", :status => 200, :headers => { 'Content-Length' => 3 })
190
+ parser.preview.should == "http://pic.rutube.ru/video/1d/c8/94867125d81559df05cbcd3713a67c78.jpg"
191
+ end
192
+
193
+
194
+ describe 'iframe_code' do
195
+ it 'gets right iframe html' do
196
+ parser.iframe_code.should == "<iframe width='420' height='315' frameborder='0' src='http://rutube.ru/video/embed/94867125d81559df05cbcd3713a67c78'></iframe>"
197
+ end
198
+
199
+ it 'receives attributes and applies them to iframe tag' do
200
+ parser.iframe_code({ wmode: true }).should == "<iframe width='420' height='315' frameborder='0' wmode='true' src='http://rutube.ru/video/embed/94867125d81559df05cbcd3713a67c78'></iframe>"
201
+ end
202
+ end
203
+ end
204
+
122
205
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hosted_video
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Alekseev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-27 00:00:00.000000000 Z
11
+ date: 2014-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,8 +84,11 @@ files:
84
84
  - lib/hosted_video/configuration.rb
85
85
  - lib/hosted_video/providers/base.rb
86
86
  - lib/hosted_video/providers/rutube.rb
87
+ - lib/hosted_video/providers/rutube_by_iframe.rb
87
88
  - lib/hosted_video/providers/vimeo.rb
89
+ - lib/hosted_video/providers/vimeo_by_iframe.rb
88
90
  - lib/hosted_video/providers/youtube.rb
91
+ - lib/hosted_video/providers/youtube_by_iframe.rb
89
92
  - lib/hosted_video/version.rb
90
93
  - spec/lib/hosted_video_spec.rb
91
94
  - spec/spec_helper.rb