Module: MediaMetaHash
- Defined in:
- lib/media_meta_hash.rb,
lib/media_meta_hash/version.rb
Constant Summary collapse
- HASH_TYPE =
Hash.new(:article)
- VERSION =
"0.0.4"
Class Method Summary collapse
- .article_hash(url, opts) ⇒ Object
- .for(url, media_type = :video, opts = {}) ⇒ Object
- .video_hash(url, opts) ⇒ Object
- .video_info(url) ⇒ Object
Class Method Details
.article_hash(url, opts) ⇒ Object
99 100 101 |
# File 'lib/media_meta_hash.rb', line 99 def self.article_hash url, opts { :og => { :url => url }.merge!(opts), :twitter => {}.merge!(opts) } end |
.for(url, media_type = :video, opts = {}) ⇒ Object
9 10 11 |
# File 'lib/media_meta_hash.rb', line 9 def self.for url, media_type = :video, opts = {} self.(media_type, url, opts) end |
.video_hash(url, opts) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/media_meta_hash.rb', line 71 def self.video_hash url, opts video = self.video_info(url) if video common = { :title => video.title, :description => video.description, :image => video.thumbnail_medium } { :og => { :video => [video.og_url || video., {:height => video.height, :width => video.width }], :type => "video" }.merge!(common).merge!(opts), :twitter => { :player => [video..sub("http://", "https://"), { :width => video.width, :height => video.height }], :card => "player" }.merge!(common).merge!(self.twitter_mobile(video.provider.downcase.to_sym, video.video_id)).merge!(opts) } else {}.merge!(opts) end end |
.video_info(url) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/media_meta_hash.rb', line 13 def self.video_info url if url =~ /video\.fox(news|business)\.com\/v\/(\d*)\/.*/ partial_domain = $1 id = $2 OpenStruct.new( :video_id => id, :embed_url => "http://video.fox#{partial_domain}.com/v/video-embed.html?video_id=#{id}", :title => "", :image => "", :description => "", :provider => "fox#{partial_domain}", :width => 480, :height => (480 * 0.5625).to_i ) elsif url =~ /video\.cnbc\.com/ && url =~ /video=(\d*)/ id = $1 OpenStruct.new( :video_id => id, :embed_url => "http://video.cnbc.com/gallery/?video=#{id}", :title => "", :image => "", :description => "", :provider => "cnbc", :width => 480, :height => (480 * 0.5625).to_i ) elsif url =~ /yahoo\.com\/video/ OpenStruct.new( :video_id => "", :embed_url => url, :title => "", :image => "", :description => "", :provider => "yahoo", :width => 480, :height => (480 * 0.5625).to_i ) else info = VideoInfo.get(url) if url =~ /(youtube.com|youtu.be)/ && info class << info def og_url=(val) @url = val end def og_url @url end end info.og_url = self.get_video_src info.video_id info.width = 480 if info.width == nil info.height = (480 * 0.5625).to_i if info.height == nil end info end end |