media_meta_hash 0.0.1.beta
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/media_meta_hash/version.rb +3 -0
- data/lib/media_meta_hash.rb +126 -0
- data/media_meta_hash.gemspec +27 -0
- metadata +137 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Renaldo Pierre-Louis
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# MediaMetaHash
|
|
2
|
+
|
|
3
|
+
TODO: Write a gem description
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
gem 'media_meta_hash'
|
|
10
|
+
|
|
11
|
+
And then execute:
|
|
12
|
+
|
|
13
|
+
$ bundle
|
|
14
|
+
|
|
15
|
+
Or install it yourself as:
|
|
16
|
+
|
|
17
|
+
$ gem install media_meta_hash
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
TODO: Write usage instructions here
|
|
22
|
+
|
|
23
|
+
## Contributing
|
|
24
|
+
|
|
25
|
+
1. Fork it
|
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
require "media_meta_hash/version"
|
|
2
|
+
require "video_info"
|
|
3
|
+
require 'ostruct'
|
|
4
|
+
|
|
5
|
+
module MediaMetaHash
|
|
6
|
+
HASH_TYPE = Hash.new(:article)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def self.for url, media_type = :video, opts = {}
|
|
10
|
+
self.media_meta_hash(media_type, url, opts)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def self.video_info url
|
|
14
|
+
if url =~ /video\.fox(news|business)\.com\/v\/(\d*)\/.*/
|
|
15
|
+
partial_domain = $1
|
|
16
|
+
id = $2
|
|
17
|
+
OpenStruct.new(
|
|
18
|
+
:video_id => id,
|
|
19
|
+
:embed_url => "http://video.fox#{partial_domain}.com/v/video-embed.html?video_id=#{id}",
|
|
20
|
+
:title => "",
|
|
21
|
+
:image => "",
|
|
22
|
+
:description => "",
|
|
23
|
+
:provider => "fox#{partial_domain}",
|
|
24
|
+
:width => 480,
|
|
25
|
+
:height => (480 * 0.5625).to_i
|
|
26
|
+
)
|
|
27
|
+
else
|
|
28
|
+
info = VideoInfo.get(url)
|
|
29
|
+
|
|
30
|
+
if url =~ /(youtube.com|youtu.be)/
|
|
31
|
+
class << info
|
|
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
|
|
43
|
+
end
|
|
44
|
+
info
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def self.video_hash url, opts
|
|
49
|
+
video = self.video_info(url)
|
|
50
|
+
common = { :title => video.title,
|
|
51
|
+
:description => video.description,
|
|
52
|
+
:image => video.thumbnail_medium
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
{ :og => { :video => [video.og_url || video.embed_url,
|
|
56
|
+
{:height => video.height,
|
|
57
|
+
:width => video.width }],
|
|
58
|
+
:type => "video"
|
|
59
|
+
}.merge!(common).merge!(opts),
|
|
60
|
+
|
|
61
|
+
:twitter => { :player => [video.embed_url.sub("http://", "https://"),
|
|
62
|
+
{ :width => video.width,
|
|
63
|
+
:height => video.height
|
|
64
|
+
}],
|
|
65
|
+
:card => "player"
|
|
66
|
+
}.merge!(common).merge!(self.twitter_mobile(video.provider.downcase.to_sym, video.video_id)).merge!(opts)
|
|
67
|
+
}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def self.article_hash url, opts
|
|
71
|
+
{ :og => { :url => url }.merge!(opts), :twitter => {}.merge!(opts) }
|
|
72
|
+
end
|
|
73
|
+
|
|
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
|
+
def self.twitter_mobile provider, id
|
|
93
|
+
tags_for = Hash.new({})
|
|
94
|
+
tags_for[:youtube] = {
|
|
95
|
+
:app => { :name => { :iphone => "YouTube",
|
|
96
|
+
:ipad => "YouTube",
|
|
97
|
+
:googleplay => "YouTube"
|
|
98
|
+
},
|
|
99
|
+
:id => { :iphone => "544007664",
|
|
100
|
+
:ipad => "544007664",
|
|
101
|
+
:googleplay => "com.google.android.youtube"
|
|
102
|
+
},
|
|
103
|
+
:url => { :iphone => self.ios_youtube_url(id),
|
|
104
|
+
:ipad => self.ios_youtube_url(id),
|
|
105
|
+
:googleplay => "http://www.youtube.com/watch/v=#{id}"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
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
|
+
|
|
123
|
+
tags_for[provider]
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'media_meta_hash/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "media_meta_hash"
|
|
8
|
+
spec.version = MediaMetaHash::VERSION
|
|
9
|
+
spec.authors = ["Renaldo Pierre-Louis"]
|
|
10
|
+
spec.email = ["rpierrelouis@hedgeye.com"]
|
|
11
|
+
spec.description = %q{Given the url to a video (youtube, vimeo, foxnews, foxbusiness), this return a hash for opengraph (og) and twitter cards which can be used with meta-tags gem to create the html tags}
|
|
12
|
+
spec.summary = %q{This gem takes video url (youtube, vimeo, foxnews, foxbusiness) and returns a hash for og and twitter card}
|
|
13
|
+
spec.homepage = ""
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.add_dependency('video_info')
|
|
17
|
+
|
|
18
|
+
spec.files = `git ls-files`.split($/)
|
|
19
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
20
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
21
|
+
spec.require_paths = ["lib"]
|
|
22
|
+
|
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
24
|
+
spec.add_development_dependency "rake"
|
|
25
|
+
spec.add_development_dependency "rspec"
|
|
26
|
+
spec.add_development_dependency "rspec-mocks"
|
|
27
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: media_meta_hash
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1.beta
|
|
5
|
+
prerelease: 6
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Renaldo Pierre-Louis
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-10-11 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: video_info
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: bundler
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ~>
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '1.3'
|
|
38
|
+
type: :development
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ~>
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '1.3'
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: rake
|
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
|
49
|
+
none: false
|
|
50
|
+
requirements:
|
|
51
|
+
- - ! '>='
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
type: :development
|
|
55
|
+
prerelease: false
|
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
57
|
+
none: false
|
|
58
|
+
requirements:
|
|
59
|
+
- - ! '>='
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
- !ruby/object:Gem::Dependency
|
|
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
|
|
97
|
+
email:
|
|
98
|
+
- rpierrelouis@hedgeye.com
|
|
99
|
+
executables: []
|
|
100
|
+
extensions: []
|
|
101
|
+
extra_rdoc_files: []
|
|
102
|
+
files:
|
|
103
|
+
- .gitignore
|
|
104
|
+
- Gemfile
|
|
105
|
+
- LICENSE.txt
|
|
106
|
+
- README.md
|
|
107
|
+
- Rakefile
|
|
108
|
+
- lib/media_meta_hash.rb
|
|
109
|
+
- lib/media_meta_hash/version.rb
|
|
110
|
+
- media_meta_hash.gemspec
|
|
111
|
+
homepage: ''
|
|
112
|
+
licenses:
|
|
113
|
+
- MIT
|
|
114
|
+
post_install_message:
|
|
115
|
+
rdoc_options: []
|
|
116
|
+
require_paths:
|
|
117
|
+
- lib
|
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
|
+
none: false
|
|
120
|
+
requirements:
|
|
121
|
+
- - ! '>='
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0'
|
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
|
+
none: false
|
|
126
|
+
requirements:
|
|
127
|
+
- - ! '>'
|
|
128
|
+
- !ruby/object:Gem::Version
|
|
129
|
+
version: 1.3.1
|
|
130
|
+
requirements: []
|
|
131
|
+
rubyforge_project:
|
|
132
|
+
rubygems_version: 1.8.25
|
|
133
|
+
signing_key:
|
|
134
|
+
specification_version: 3
|
|
135
|
+
summary: This gem takes video url (youtube, vimeo, foxnews, foxbusiness) and returns
|
|
136
|
+
a hash for og and twitter card
|
|
137
|
+
test_files: []
|