Sha256: 3dd3ce4bb15f7e5cb186b6741008c0f46983f54337f0354e8a51ffaea3d45ad6
Contents?: true
Size: 1.85 KB
Versions: 1
Compression:
Stored size: 1.85 KB
Contents
# encoding: UTF-8 require 'open-uri' require 'multi_json' require 'htmlentities' if RUBY_VERSION.to_i < 2 require 'iconv' end class VideoInfo module Providers class Vkontakte < Provider attr_accessor :video_owner def self.usable?(url) url =~ /(vk\.com)|(vkontakte\.ru)/ end def provider 'Vkontakte' end def description content = data[/<meta name="description" content="(.*)" \/>/,1] HTMLEntities.new.decode(content) end alias_method :keywords, :description def width { 240 => 320, 360 => 480, 480 => 640, 720 => 1280 }[height] end def height data[/url(\d+)/,1].to_i end def title data[/<title>(.*)<\/title>/,1].gsub(" | ВКонтакте", "") end def view_count data[/mv_num_views\\">(\d+)/,1].to_i end def embed_url "vk.com/video_ext.php?oid=#{video_owner}&id=#{video_id}&hash=#{_data_hash}" end def duration data[/"duration":(\d+)/,1].to_i end private def _set_data_from_api uri = open(_api_url, options) if RUBY_VERSION.to_i < 2 Iconv.iconv('utf-8', 'cp1251', uri.read)[0] else uri.read.encode("UTF-8") end end def _data_hash data[/hash2\\":\\"(\w+)/,1] end def _set_video_id_from_url url.gsub(_url_regex) { @video_owner, @video_id = ($1 || $2 || $3).split('_') } end def _url_regex /(?:vkontakte\.ru\/video|vk\.com\/video)(\d+_\d+)/i end def _api_url "http://vk.com/video#{video_owner}_#{video_id}" end def _default_iframe_attributes { allowfullscreen: "allowfullscreen" } end def _default_url_attributes {} end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
video_info-2.0.0 | lib/video_info/providers/vkontakte.rb |