media_meta_hash 0.0.1 → 0.0.1.1.alpha
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -4
- data/lib/media_meta_hash/version.rb +1 -1
- data/lib/media_meta_hash.rb +18 -56
- data/media_meta_hash.gemspec +4 -6
- metadata +10 -50
- data/LICENSE +0 -20
- data/spec/media_meta_hash_spec.rb +0 -154
- data/spec/spec_helper.rb +0 -8
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# MediaMetaHash
|
2
2
|
|
3
|
-
TODO:
|
3
|
+
TODO: Write a gem description
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -27,6 +27,3 @@ TODO: Write usage instructions here
|
|
27
27
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
28
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
29
|
5. Create new Pull Request
|
30
|
-
|
31
|
-
|
32
|
-
|
data/lib/media_meta_hash.rb
CHANGED
@@ -5,9 +5,15 @@ require 'ostruct'
|
|
5
5
|
module MediaMetaHash
|
6
6
|
HASH_TYPE = Hash.new(:article)
|
7
7
|
|
8
|
+
def self.media_meta_hash media_type, url, opts = {}
|
9
|
+
HASH_TYPE[:video] = self.method("video_hash").call(url, opts)
|
10
|
+
HASH_TYPE[:article] = self.method("article_hash").call(url, opts)
|
11
|
+
hash = HASH_TYPE[media_type]
|
12
|
+
hash
|
13
|
+
end
|
8
14
|
|
9
|
-
def self.
|
10
|
-
|
15
|
+
def self.get_video_src id
|
16
|
+
"http://www.youtube.com/v/#{id}?autohide=1&version=3"
|
11
17
|
end
|
12
18
|
|
13
19
|
def self.video_info url
|
@@ -16,30 +22,17 @@ module MediaMetaHash
|
|
16
22
|
id = $2
|
17
23
|
OpenStruct.new(
|
18
24
|
:video_id => id,
|
25
|
+
:provider => "fox_#{partial_domain}",
|
19
26
|
:embed_url => "http://video.fox#{partial_domain}.com/v/video-embed.html?video_id=#{id}",
|
20
27
|
:title => "",
|
21
28
|
:image => "",
|
22
29
|
:description => "",
|
23
|
-
:provider => "fox#{partial_domain}"
|
24
|
-
:width => 480,
|
25
|
-
:height => (480 * 0.5625).to_i
|
30
|
+
:provider => "fox#{partial_domain}"
|
26
31
|
)
|
27
32
|
else
|
28
33
|
info = VideoInfo.get(url)
|
29
|
-
|
30
34
|
if url =~ /(youtube.com|youtu.be)/
|
31
|
-
|
32
|
-
def og_url=(val)
|
33
|
-
@url = val
|
34
|
-
end
|
35
|
-
|
36
|
-
def og_url
|
37
|
-
@url
|
38
|
-
end
|
39
|
-
end
|
40
|
-
info.og_url = self.get_video_src info.video_id
|
41
|
-
info.width = 480 if info.width == nil
|
42
|
-
info.height = (480 * 0.5625).to_i if info.height == nil
|
35
|
+
info.embed_url = "http://www.youtube.com/v/#{info.video_id}?autohide=1&version=3"
|
43
36
|
end
|
44
37
|
info
|
45
38
|
end
|
@@ -52,16 +45,11 @@ module MediaMetaHash
|
|
52
45
|
:image => video.thumbnail_medium
|
53
46
|
}
|
54
47
|
|
55
|
-
{ :og => { :video =>
|
56
|
-
{:height => video.height,
|
57
|
-
:width => video.width }],
|
48
|
+
{ :og => { :video => video.embed_url,
|
58
49
|
:type => "video"
|
59
50
|
}.merge!(common).merge!(opts),
|
60
51
|
|
61
|
-
:twitter => { :player =>
|
62
|
-
{ :width => video.width,
|
63
|
-
:height => video.height
|
64
|
-
}],
|
52
|
+
:twitter => { :player => video.embed_url,
|
65
53
|
:card => "player"
|
66
54
|
}.merge!(common).merge!(self.twitter_mobile(video.provider.downcase.to_sym, video.video_id)).merge!(opts)
|
67
55
|
}
|
@@ -71,24 +59,6 @@ module MediaMetaHash
|
|
71
59
|
{ :og => { :url => url }.merge!(opts), :twitter => {}.merge!(opts) }
|
72
60
|
end
|
73
61
|
|
74
|
-
private
|
75
|
-
|
76
|
-
def self.ios_youtube_url id
|
77
|
-
"vnd.youtube://watch/#{id}"
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.get_video_src id
|
81
|
-
"http://www.youtube.com/v/#{id}?autohide=1&version=3"
|
82
|
-
end
|
83
|
-
|
84
|
-
def self.media_meta_hash media_type, url, opts = {}
|
85
|
-
if media_type == :video
|
86
|
-
self.video_hash(url, opts)
|
87
|
-
else
|
88
|
-
self.article_hash(url, opts)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
62
|
def self.twitter_mobile provider, id
|
93
63
|
tags_for = Hash.new({})
|
94
64
|
tags_for[:youtube] = {
|
@@ -106,21 +76,13 @@ module MediaMetaHash
|
|
106
76
|
}
|
107
77
|
}
|
108
78
|
}
|
109
|
-
tags_for[:vimeo] = {
|
110
|
-
:app => { :name => { :iphone => "Vimeo",
|
111
|
-
:ipad => "Vimeo",
|
112
|
-
:googleplay => "Vimeo"
|
113
|
-
},
|
114
|
-
:id => { :iphone => "425194759",
|
115
|
-
:ipad => "425194759",
|
116
|
-
:googleplay => "com.vimeo.android.videoapp"
|
117
|
-
},
|
118
|
-
:url => { :iphone => "vimeo://video/#{id}"}
|
119
|
-
}
|
120
|
-
|
121
|
-
}
|
122
79
|
|
123
80
|
tags_for[provider]
|
124
81
|
end
|
125
82
|
|
83
|
+
private
|
84
|
+
|
85
|
+
def self.ios_youtube_url id
|
86
|
+
"vnd.youtube://watch/#{id}"
|
87
|
+
end
|
126
88
|
end
|
data/media_meta_hash.gemspec
CHANGED
@@ -7,10 +7,10 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.name = "media_meta_hash"
|
8
8
|
spec.version = MediaMetaHash::VERSION
|
9
9
|
spec.authors = ["Renaldo Pierre-Louis"]
|
10
|
-
spec.email = ["
|
11
|
-
spec.description = %q{
|
12
|
-
spec.summary = %q{
|
13
|
-
spec.homepage = "
|
10
|
+
spec.email = ["rpierrelouis@hedgeye.com"]
|
11
|
+
spec.description = %q{}
|
12
|
+
spec.summary = %q{Given a url, you get a meta hash for the type of url}
|
13
|
+
spec.homepage = ""
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.add_dependency('video_info')
|
@@ -22,6 +22,4 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.3"
|
24
24
|
spec.add_development_dependency "rake"
|
25
|
-
spec.add_development_dependency "rspec"
|
26
|
-
spec.add_development_dependency "rspec-mocks"
|
27
25
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: media_meta_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.1.1.alpha
|
5
|
+
prerelease: 8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Renaldo Pierre-Louis
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-10-
|
12
|
+
date: 2013-10-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: video_info
|
@@ -59,59 +59,22 @@ dependencies:
|
|
59
59
|
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
|
-
|
63
|
-
name: rspec
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ! '>='
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
70
|
-
type: :development
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ! '>='
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: '0'
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: rspec-mocks
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ! '>='
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: '0'
|
86
|
-
type: :development
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ! '>='
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: '0'
|
94
|
-
description: Given the url to a video (youtube, vimeo, foxnews, foxbusiness), this
|
95
|
-
return a hash for opengraph (og) and twitter cards which can be used with meta-tags
|
96
|
-
gem to create the html tags
|
62
|
+
description: ''
|
97
63
|
email:
|
98
|
-
-
|
64
|
+
- rpierrelouis@hedgeye.com
|
99
65
|
executables: []
|
100
66
|
extensions: []
|
101
67
|
extra_rdoc_files: []
|
102
68
|
files:
|
103
69
|
- .gitignore
|
104
70
|
- Gemfile
|
105
|
-
- LICENSE
|
106
71
|
- LICENSE.txt
|
107
72
|
- README.md
|
108
73
|
- Rakefile
|
109
74
|
- lib/media_meta_hash.rb
|
110
75
|
- lib/media_meta_hash/version.rb
|
111
76
|
- media_meta_hash.gemspec
|
112
|
-
|
113
|
-
- spec/spec_helper.rb
|
114
|
-
homepage: https://github.com/daltonrenaldo/meta_media_hash
|
77
|
+
homepage: ''
|
115
78
|
licenses:
|
116
79
|
- MIT
|
117
80
|
post_install_message:
|
@@ -127,16 +90,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
91
|
none: false
|
129
92
|
requirements:
|
130
|
-
- - ! '
|
93
|
+
- - ! '>'
|
131
94
|
- !ruby/object:Gem::Version
|
132
|
-
version:
|
95
|
+
version: 1.3.1
|
133
96
|
requirements: []
|
134
97
|
rubyforge_project:
|
135
98
|
rubygems_version: 1.8.25
|
136
99
|
signing_key:
|
137
100
|
specification_version: 3
|
138
|
-
summary:
|
139
|
-
|
140
|
-
test_files:
|
141
|
-
- spec/media_meta_hash_spec.rb
|
142
|
-
- spec/spec_helper.rb
|
101
|
+
summary: Given a url, you get a meta hash for the type of url
|
102
|
+
test_files: []
|
data/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2013 daltonrenaldo
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
-
this software and associated documentation files (the "Software"), to deal in
|
7
|
-
the Software without restriction, including without limitation the rights to
|
8
|
-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
-
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
-
subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,154 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe MediaMetaHash do
|
4
|
-
ARTICLE_URL = "http://google.com"
|
5
|
-
YOUTUBE_URL = "http://www.youtube.com/watch?v=ZQCINxTQlN4"
|
6
|
-
FOX_URL = "http://video.foxbusiness.com/v/2734961183001/a-breach-of-privacy-between-the-irs-and-white-house/"
|
7
|
-
VIMEO_URL = "http://vimeo.com/74868773"
|
8
|
-
|
9
|
-
def basic_info opts = {}
|
10
|
-
OpenStruct.new({:title => "Boats",
|
11
|
-
:description => "Something",
|
12
|
-
:image => "http://image.com",
|
13
|
-
:type => "video",
|
14
|
-
:provider => "vimeo",
|
15
|
-
:embed_url => "http://embed_link.com",
|
16
|
-
:width => "240",
|
17
|
-
:height => "100",
|
18
|
-
:video_id => "13142"
|
19
|
-
}.merge!(opts))
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "#get" do
|
23
|
-
context ":article" do
|
24
|
-
before do
|
25
|
-
@result = MediaMetaHash.for(ARTICLE_URL, :article)
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should return a hash" do
|
29
|
-
@result.should be_instance_of Hash
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should contains these keys" do
|
33
|
-
@result.should include(:og, :twitter)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context ":video" do
|
38
|
-
before do
|
39
|
-
@result = MediaMetaHash.for(YOUTUBE_URL)
|
40
|
-
end
|
41
|
-
|
42
|
-
it "should return a hash" do
|
43
|
-
@result.should be_instance_of Hash
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should contains these keys" do
|
47
|
-
@result.should include(:og, :twitter)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "#video_info" do
|
53
|
-
context "for fox videos" do
|
54
|
-
it "returns object with correct attributes" do
|
55
|
-
info = MediaMetaHash.video_info FOX_URL
|
56
|
-
info.methods.should include(:video_id, :embed_url, :title, :image, :description, :provider, :width, :height)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context "for youtube videos" do
|
61
|
-
before do
|
62
|
-
VideoInfo.stub(:get).and_return{ basic_info({:thumbnail_medium => "url"}) }
|
63
|
-
end
|
64
|
-
|
65
|
-
it "returns object with correct attributes" do
|
66
|
-
url = "http://www.youtube.com/watch?v=ZQCINxTQlN4"
|
67
|
-
info = MediaMetaHash.video_info(url)
|
68
|
-
info.methods.should include(:video_id, :embed_url, :title, :description, :provider, :width, :height, :thumbnail_medium, :og_url)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
context "for other videos (vimeo)" do
|
73
|
-
before do
|
74
|
-
VideoInfo.stub(:get).and_return{ basic_info }
|
75
|
-
end
|
76
|
-
|
77
|
-
it "returns object with correct attritubes" do
|
78
|
-
url = "http://vimeo.com/74868773"
|
79
|
-
info = MediaMetaHash.video_info(url)
|
80
|
-
info.methods.should_not include(:og_url)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "#video_hash" do
|
86
|
-
it "gets video info" do
|
87
|
-
url = "http://vimeo.com/74868773"
|
88
|
-
MediaMetaHash.should_receive(:video_info).and_return { basic_info }
|
89
|
-
MediaMetaHash.video_hash url, {}
|
90
|
-
end
|
91
|
-
|
92
|
-
context "for youtube videos" do
|
93
|
-
before do
|
94
|
-
MediaMetaHash.stub(:video_info).and_return{ basic_info({:og_url => "http://og_url.com", :provider => :youtube}) }
|
95
|
-
@info_hash = MediaMetaHash.video_hash YOUTUBE_URL, {}
|
96
|
-
end
|
97
|
-
|
98
|
-
it "the :og key" do
|
99
|
-
@info_hash[:og].should include(:title, :description, :image, :type, :video)
|
100
|
-
end
|
101
|
-
|
102
|
-
it "the :twitter key" do
|
103
|
-
@info_hash[:twitter].should include(:title, :description, :image, :player, :card, :app)
|
104
|
-
end
|
105
|
-
|
106
|
-
it "the :twitter => :player should be an array" do
|
107
|
-
@info_hash[:twitter][:player].should be_instance_of Array
|
108
|
-
end
|
109
|
-
|
110
|
-
it "the :twitter => :player url (array.first) should be secure" do
|
111
|
-
@info_hash[:twitter][:player].first.should match(/^https/)
|
112
|
-
end
|
113
|
-
|
114
|
-
it "the :twitter => :player array should have hash" do
|
115
|
-
@info_hash[:twitter][:player].last.should include(:width, :height)
|
116
|
-
end
|
117
|
-
|
118
|
-
it "the :og => :video key" do
|
119
|
-
@info_hash[:og][:video].should == "http://og_url.com"
|
120
|
-
end
|
121
|
-
|
122
|
-
it "the :twitter => :app key" do
|
123
|
-
@info_hash[:twitter][:app].should include(:id, :name, :url)
|
124
|
-
end
|
125
|
-
|
126
|
-
it "the :twitter => :app => :id key" do
|
127
|
-
@info_hash[:twitter][:app][:id].should include(:iphone, :ipad, :googleplay)
|
128
|
-
end
|
129
|
-
|
130
|
-
it "the :twitter => :app => :name key" do
|
131
|
-
@info_hash[:twitter][:app][:name].should include(:iphone, :ipad, :googleplay)
|
132
|
-
end
|
133
|
-
|
134
|
-
it "the :twitter => :app => :url key" do
|
135
|
-
@info_hash[:twitter][:app][:url].should include(:iphone, :ipad, :googleplay)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context "for fox videos" do
|
140
|
-
before do
|
141
|
-
MediaMetaHash.stub(:video_info).and_return{ basic_info({:provider => "foxbusiness"}) }
|
142
|
-
@info_hash = MediaMetaHash.video_hash FOX_URL, {}
|
143
|
-
end
|
144
|
-
|
145
|
-
it "the :og => :video key" do
|
146
|
-
@info_hash[:og][:video].should == "http://embed_link.com"
|
147
|
-
end
|
148
|
-
|
149
|
-
it "the :twitter key" do
|
150
|
-
@info_hash[:twitter].should_not include(:app)
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|