video_player 0.1.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -9
- data/Rakefile +7 -0
- data/lib/video_player.rb +63 -30
- data/lib/video_player/version.rb +1 -1
- data/spec/spec_helper.rb +5 -0
- data/spec/video_player/video_player_spec.rb +155 -0
- data/video_player.gemspec +1 -0
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d37ffd1181e8c99963783e3a3cb8f9ba3b76885
|
4
|
+
data.tar.gz: b4f2a60c44fb0eaedbfd3a2dc74975e4d3329550
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67c6a651067628f91d30689bf2988fdd146faf4382f986e5400511be346fb511c9eb2761a71773dd863e73d6771464b3d448e2daeec23e9298ba07762b671850
|
7
|
+
data.tar.gz: e99110eaada65b5b505eecfb7ecd895b3f053a5951fb2e66cc95ab823561f2e2d24c9177473f907c5b828fa405d05b2412271a1d13f7dd68b3d6430f132dc80e
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# Video player for Youtube, Vimeo and
|
1
|
+
# Video player for Youtube, Vimeo, İzlesene and Wistia
|
2
2
|
[![Gem Version](https://badge.fury.io/rb/video_player.svg)](http://badge.fury.io/rb/video_player)
|
3
3
|
|
4
|
-
Create video player for Youtube, Vimeo and
|
4
|
+
Create video player for Youtube, Vimeo, İzlesene and Wistia videos for Ruby.
|
5
5
|
|
6
6
|
And it may support more video hoster with your [contributions](#contributing).
|
7
7
|
|
@@ -25,7 +25,7 @@ or install the gem on terminal.
|
|
25
25
|
|
26
26
|
**url**
|
27
27
|
|
28
|
-
> Youtube, Vimeo and
|
28
|
+
> Youtube, Vimeo, İzlesene and Wistia video link
|
29
29
|
>
|
30
30
|
> http://www.youtube.com/watch?v=iEPTlhBmwRg
|
31
31
|
>
|
@@ -36,6 +36,10 @@ or install the gem on terminal.
|
|
36
36
|
> or
|
37
37
|
>
|
38
38
|
> http://www.izlesene.com/video/feder-goodbye-feat-lyse/7886121
|
39
|
+
>
|
40
|
+
> or
|
41
|
+
>
|
42
|
+
> https://<subdomain>.wistia.com/medias/9ub91enoph
|
39
43
|
|
40
44
|
**width** *(default = 420)*
|
41
45
|
|
@@ -50,15 +54,27 @@ or install the gem on terminal.
|
|
50
54
|
require 'video_player' # if you're not use Rails 4
|
51
55
|
VideoPlayer::player("http://vimeo.com/101419884")
|
52
56
|
# returns iframe player from Vimeo video
|
53
|
-
#
|
57
|
+
# <iframe width=\"420\" height=\"315\"
|
58
|
+
# src=\"//player.vimeo.com/video/101419884\"
|
59
|
+
# frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
|
54
60
|
|
55
61
|
VideoPlayer::player("http://www.youtube.com/watch?v=iEPTlhBmwRg", "1200", "800", true)
|
56
62
|
# returns iframe player which has 1200px width and 800px height with autoplay from Youtube video
|
57
|
-
#
|
63
|
+
# <iframe width=\"1200\" height=\"800\"
|
64
|
+
# src=\"//www.youtube.com/embed/iEPTlhBmwRg?autoplay=1&rel=0\"
|
65
|
+
# frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
|
58
66
|
|
59
67
|
VideoPlayer::player("http://www.izlesene.com/video/feder-goodbye-feat-lyse/7886121")
|
60
68
|
# returns iframe player from İzlesene video
|
61
|
-
#
|
69
|
+
# <iframe width=\"420\" height=\"315\"
|
70
|
+
# src=\"//www.izlesene.com/embedplayer/7886121/?autoplay=1&showrel=0&showinfo=0\"
|
71
|
+
# frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
|
72
|
+
|
73
|
+
VideoPlayer::player("https://example.wistia.com/medias/9ub91enoph")
|
74
|
+
# returns iframe player from Wistia video
|
75
|
+
# <iframe width=\"420\" height=\"315\"
|
76
|
+
# src=\"//fast.wistia.net/embed/iframe/9ub91enoph/?autoplay=1&showrel=0&showinfo=0\"
|
77
|
+
# frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
|
62
78
|
```
|
63
79
|
|
64
80
|
It gets you only raw data. You must handle it on erb, haml, slim, etc for output without HTML escaping.
|
@@ -80,6 +96,11 @@ video = VideoPlayer::player("http://vimeo.com/101419884")
|
|
80
96
|
## Contributing
|
81
97
|
1. Fork it ( https://github.com/tgezginis/video_player/fork )
|
82
98
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
83
|
-
3.
|
84
|
-
4.
|
85
|
-
5.
|
99
|
+
3. Extend the specs, run with `rake`
|
100
|
+
4. Commit your changes (`git commit -am 'Add some feature'`)
|
101
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
102
|
+
6. Create a new Pull Request
|
103
|
+
|
104
|
+
**Thanks**
|
105
|
+
[mikel](https://github.com/mikel)
|
106
|
+
[foxgaocn](https://github.com/foxgaocn)
|
data/Rakefile
CHANGED
data/lib/video_player.rb
CHANGED
@@ -1,37 +1,70 @@
|
|
1
1
|
require "video_player/version"
|
2
2
|
|
3
3
|
module VideoPlayer
|
4
|
-
def self.player
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
4
|
+
def self.player(*args)
|
5
|
+
VideoPlayer::Parser.new(*args).embed_code
|
6
|
+
end
|
7
|
+
|
8
|
+
class Parser
|
9
|
+
DefaultWidth = '420'
|
10
|
+
DefaultHeight = '315'
|
11
|
+
DefaultAutoPlay = true
|
12
|
+
|
13
|
+
YouTubeRegex = /\A(https?:\/\/)?(www.)?(youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/watch\?feature=player_embedded&v=)([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/i
|
14
|
+
VimeoRegex = /\Ahttps?:\/\/(www.)?vimeo\.com\/([A-Za-z0-9._%-]*)((\?|#)\S+)?/i
|
15
|
+
IzleseneRegex = /\Ahttp:\/\/(?:.*?)\izlesene\.com\/video\/([\w\-\.]+[^#?\s]+)\/(.*)?$/i
|
16
|
+
WistiaRegex = /\Ahttps?:\/\/(.+)?(wistia.com|wi.st)\/(medias|embed)\/([A-Za-z0-9_-]*)(\&\S+)?(\?\S+)?/i
|
17
|
+
|
18
|
+
attr_accessor :url, :width, :height
|
19
|
+
|
20
|
+
def initialize(url, width = DefaultWidth, height = DefaultHeight, autoplay = DefaultAutoPlay)
|
21
|
+
@url = url
|
22
|
+
@width = width
|
23
|
+
@height = height
|
24
|
+
@autoplay = autoplay
|
25
|
+
end
|
26
|
+
|
27
|
+
def embed_code
|
28
|
+
case
|
29
|
+
when matchdata = url.match(YouTubeRegex)
|
30
|
+
youtube_embed(matchdata[4])
|
31
|
+
when matchdata = url.match(VimeoRegex)
|
32
|
+
vimeo_embed(matchdata[2])
|
33
|
+
when matchdata = url.match(IzleseneRegex)
|
34
|
+
izlesene_embed(matchdata[2])
|
35
|
+
when matchdata = url.match(WistiaRegex)
|
36
|
+
wistia_embed(matchdata[4])
|
37
|
+
else
|
38
|
+
false
|
32
39
|
end
|
33
|
-
|
34
|
-
|
40
|
+
end
|
41
|
+
|
42
|
+
def autoplay
|
43
|
+
!!@autoplay ? '1' : '0'
|
44
|
+
end
|
45
|
+
|
46
|
+
def iframe_code(src)
|
47
|
+
%{<iframe src="#{src}" width="#{width}" height="#{height}" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>}
|
48
|
+
end
|
49
|
+
|
50
|
+
def youtube_embed(video_id)
|
51
|
+
src = "//www.youtube.com/embed/#{video_id}?autoplay=#{autoplay}&rel=0"
|
52
|
+
iframe_code(src)
|
53
|
+
end
|
54
|
+
|
55
|
+
def vimeo_embed(video_id)
|
56
|
+
src = "//player.vimeo.com/video/#{video_id}"
|
57
|
+
iframe_code(src)
|
58
|
+
end
|
59
|
+
|
60
|
+
def izlesene_embed(video_id)
|
61
|
+
src = "//www.izlesene.com/embedplayer/#{video_id}/?autoplay=#{autoplay}&showrel=0&showinfo=0"
|
62
|
+
iframe_code(src)
|
63
|
+
end
|
64
|
+
|
65
|
+
def wistia_embed(video_id)
|
66
|
+
src = "//fast.wistia.net/embed/iframe/#{video_id}/?autoplay=#{autoplay}&showrel=0&showinfo=0"
|
67
|
+
iframe_code(src)
|
35
68
|
end
|
36
69
|
end
|
37
70
|
end
|
data/lib/video_player/version.rb
CHANGED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe VideoPlayer do
|
4
|
+
|
5
|
+
describe "existing API" do
|
6
|
+
let(:parser) { VideoPlayer::Parser.new('https://www.youtube.com/watch?v=12345678') }
|
7
|
+
|
8
|
+
it "passes the player method to an instance of VideoPlayer::Parser" do
|
9
|
+
expect(VideoPlayer::Parser).to receive(:new).once.and_return(VideoPlayer::Parser.new('url'))
|
10
|
+
VideoPlayer::player('https://www.youtube.com/watch?v=12345678')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe "selecting video embed method" do
|
15
|
+
|
16
|
+
let(:width) { %|width="#{VideoPlayer::Parser::DefaultWidth}"| }
|
17
|
+
let(:height) { %|height="#{VideoPlayer::Parser::DefaultHeight}"| }
|
18
|
+
let(:attributes) { %|frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen| }
|
19
|
+
|
20
|
+
context "youtube links" do
|
21
|
+
|
22
|
+
let(:youtube_urls) { [
|
23
|
+
'http://youtube.com/watch?v=abcde12345',
|
24
|
+
'http://youtu.be/abcde12345',
|
25
|
+
'http://youtube.com/watch?feature=player_embedded&v=abcde12345',
|
26
|
+
'https://youtube.com/watch?v=abcde12345',
|
27
|
+
'https://youtu.be/abcde12345',
|
28
|
+
'https://youtube.com/watch?feature=player_embedded&v=abcde12345'
|
29
|
+
]}
|
30
|
+
|
31
|
+
it "uses the youtube embed method" do
|
32
|
+
youtube_urls.each do |url|
|
33
|
+
parser = VideoPlayer::Parser.new(url)
|
34
|
+
expect(parser).to receive(:youtube_embed).once
|
35
|
+
parser.embed_code
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
it "returns a valid embed code" do
|
40
|
+
src = "//www.youtube.com/embed/abcde12345?autoplay=0&rel=0"
|
41
|
+
code = %|<iframe src="#{src}" #{width} #{height} #{attributes}></iframe>|
|
42
|
+
|
43
|
+
url = 'https://youtube.com/watch?feature=player_embedded&v=abcde12345'
|
44
|
+
expect(VideoPlayer.player(url, VideoPlayer::Parser::DefaultWidth, VideoPlayer::Parser::DefaultHeight, false)).to eq(code)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns a valid autoplay embed code" do
|
48
|
+
src = "//www.izlesene.com/embedplayer/12345678/?autoplay=1&showrel=0&showinfo=0"
|
49
|
+
code = %|<iframe src="#{src}" #{width} #{height} #{attributes}></iframe>|
|
50
|
+
|
51
|
+
url = 'http://izlesene.com/video/abcde-abcde-abcde-abcde-abcde/12345678'
|
52
|
+
expect(VideoPlayer.player(url)).to eq(code)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "vimeo links" do
|
57
|
+
let(:vimeo_urls) { [
|
58
|
+
'http://vimeo.com/abcde12345',
|
59
|
+
'http://www.vimeo.com/abcde12345',
|
60
|
+
'https://vimeo.com/abcde12345',
|
61
|
+
'https://www.vimeo.com/abcde12345'
|
62
|
+
]}
|
63
|
+
|
64
|
+
it "uses the youtube embed method" do
|
65
|
+
vimeo_urls.each do |url|
|
66
|
+
parser = VideoPlayer::Parser.new(url)
|
67
|
+
expect(parser).to receive(:vimeo_embed).once
|
68
|
+
parser.embed_code
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "returns a valid embed code" do
|
73
|
+
src = "//www.izlesene.com/embedplayer/12345678/?autoplay=0&showrel=0&showinfo=0"
|
74
|
+
code = %|<iframe src="#{src}" #{width} #{height} #{attributes}></iframe>|
|
75
|
+
|
76
|
+
url = 'http://izlesene.com/video/abcde-abcde-abcde-abcde-abcde/12345678'
|
77
|
+
expect(VideoPlayer.player(url, VideoPlayer::Parser::DefaultWidth, VideoPlayer::Parser::DefaultHeight, false)).to eq(code)
|
78
|
+
end
|
79
|
+
|
80
|
+
it "returns a valid autoplay embed code" do
|
81
|
+
src = "//www.izlesene.com/embedplayer/12345678/?autoplay=1&showrel=0&showinfo=0"
|
82
|
+
code = %|<iframe src="#{src}" #{width} #{height} #{attributes}></iframe>|
|
83
|
+
|
84
|
+
url = 'http://izlesene.com/video/abcde-abcde-abcde-abcde-abcde/12345678'
|
85
|
+
expect(VideoPlayer.player(url)).to eq(code)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "izlesene links" do
|
90
|
+
|
91
|
+
let(:izlesene_urls) { [
|
92
|
+
'http://izlesene.com/video/abcde-abcde-abcde-abcde-abcde/12345678',
|
93
|
+
'http://www.izlesene.com/video/abcde-abcde-abcde-abcde-abcde/12345678'
|
94
|
+
]}
|
95
|
+
|
96
|
+
it "uses the youtube embed method" do
|
97
|
+
izlesene_urls.each do |url|
|
98
|
+
parser = VideoPlayer::Parser.new(url)
|
99
|
+
expect(parser).to receive(:izlesene_embed).once
|
100
|
+
parser.embed_code
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
it "returns a valid embed code" do
|
105
|
+
src = "//www.izlesene.com/embedplayer/12345678/?autoplay=0&showrel=0&showinfo=0"
|
106
|
+
code = %|<iframe src="#{src}" #{width} #{height} #{attributes}></iframe>|
|
107
|
+
|
108
|
+
url = 'http://izlesene.com/video/abcde-abcde-abcde-abcde-abcde/12345678'
|
109
|
+
expect(VideoPlayer.player(url, VideoPlayer::Parser::DefaultWidth, VideoPlayer::Parser::DefaultHeight, false)).to eq(code)
|
110
|
+
end
|
111
|
+
|
112
|
+
it "returns a valid autoplay embed code" do
|
113
|
+
src = "//www.izlesene.com/embedplayer/12345678/?autoplay=1&showrel=0&showinfo=0"
|
114
|
+
code = %|<iframe src="#{src}" #{width} #{height} #{attributes}></iframe>|
|
115
|
+
|
116
|
+
url = 'http://izlesene.com/video/abcde-abcde-abcde-abcde-abcde/12345678'
|
117
|
+
expect(VideoPlayer.player(url)).to eq(code)
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
context "wistia links" do
|
123
|
+
|
124
|
+
let(:wistia_urls) { [
|
125
|
+
'https://company.wistia.com/medias/12345678'
|
126
|
+
]}
|
127
|
+
|
128
|
+
it "uses the youtube embed method" do
|
129
|
+
wistia_urls.each do |url|
|
130
|
+
parser = VideoPlayer::Parser.new(url)
|
131
|
+
expect(parser).to receive(:wistia_embed).once
|
132
|
+
parser.embed_code
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
it "returns a valid embed code" do
|
137
|
+
src = "//fast.wistia.net/embed/iframe/12345678/?autoplay=0&showrel=0&showinfo=0"
|
138
|
+
code = %|<iframe src="#{src}" #{width} #{height} #{attributes}></iframe>|
|
139
|
+
|
140
|
+
url = 'https://company.wistia.com/medias/12345678'
|
141
|
+
expect(VideoPlayer.player(url, VideoPlayer::Parser::DefaultWidth, VideoPlayer::Parser::DefaultHeight, false)).to eq(code)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "returns a valid autoplay embed code" do
|
145
|
+
src = "//fast.wistia.net/embed/iframe/12345678/?autoplay=1&showrel=0&showinfo=0"
|
146
|
+
code = %|<iframe src="#{src}" #{width} #{height} #{attributes}></iframe>|
|
147
|
+
|
148
|
+
url = 'https://company.wistia.com/medias/12345678'
|
149
|
+
expect(VideoPlayer.player(url)).to eq(code)
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
data/video_player.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: video_player
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tolga Gezginiş
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
41
55
|
description: Create video player for Youtube, Vimeo and İzlesene videos
|
42
56
|
email:
|
43
57
|
- tolga@gezginis.com
|
@@ -52,6 +66,8 @@ files:
|
|
52
66
|
- Rakefile
|
53
67
|
- lib/video_player.rb
|
54
68
|
- lib/video_player/version.rb
|
69
|
+
- spec/spec_helper.rb
|
70
|
+
- spec/video_player/video_player_spec.rb
|
55
71
|
- video_player.gemspec
|
56
72
|
homepage: https://github.com/tgezginis/video_player
|
57
73
|
licenses:
|
@@ -77,4 +93,6 @@ rubygems_version: 2.4.8
|
|
77
93
|
signing_key:
|
78
94
|
specification_version: 4
|
79
95
|
summary: Video player for Youtube, Vimeo and İzlesene
|
80
|
-
test_files:
|
96
|
+
test_files:
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
- spec/video_player/video_player_spec.rb
|