class VideoInfo
Constants
- PROVIDERS
- VERSION
Attributes
disable_providers[W]
logger[W]
Public Class Methods
disable_providers()
click to toggle source
# File lib/video_info.rb, line 16 def disable_providers @disable_providers || [] end
disabled_provider?(provider)
click to toggle source
# File lib/video_info.rb, line 74 def self.disabled_provider?(provider) disable_providers.map(&:downcase).include?(provider.downcase) end
enabled_providers()
click to toggle source
# File lib/video_info.rb, line 78 def self.enabled_providers PROVIDERS .reject { |p| disabled_provider?(p) } .map { |p| Providers.const_get(p) } end
get(*args)
click to toggle source
# File lib/video_info.rb, line 59 def self.get(*args) new(*args) end
logger()
click to toggle source
# File lib/video_info.rb, line 31 def logger @logger ||= Logger.new($stdout).tap do |lgr| lgr.progname = name end end
new(url, options = {})
click to toggle source
# File lib/video_info.rb, line 55 def initialize(url, options = {}) @provider = _select_provider(url, options) end
provider_api_keys()
click to toggle source
# File lib/video_info.rb, line 20 def provider_api_keys @provider_api_keys || {} end
provider_api_keys=(api_keys)
click to toggle source
# File lib/video_info.rb, line 24 def provider_api_keys=(api_keys) api_keys.keys.each do |key| raise ArgumentError, "Key must be a symbol!" unless key.is_a?(Symbol) end @provider_api_keys = api_keys end
usable?(url)
click to toggle source
# File lib/video_info.rb, line 63 def self.usable?(url) new(url) true rescue UrlError false end
valid_url?(url)
click to toggle source
# File lib/video_info.rb, line 84 def self.valid_url?(url) enabled_providers.any? { |p| p.usable?(url) } end
Public Instance Methods
==(other)
click to toggle source
# File lib/video_info.rb, line 70 def ==(other) url == other.url && video_id == other.video_id end
Private Instance Methods
_providers_const()
click to toggle source
# File lib/video_info.rb, line 104 def _providers_const PROVIDERS.map { |p| Providers.const_get(p) } end
_select_provider(url, options)
click to toggle source
# File lib/video_info.rb, line 90 def _select_provider(url, options) if (provider_const = _providers_const.detect { |p| p.usable?(url) }) const_provider = provider_const.new(url, options) if defined?(const_provider.provider) && const_provider.provider ensure_enabled_provider(const_provider.provider) end const_provider else raise UrlError, "Url is not usable by any Providers: #{url}" end end
ensure_enabled_provider(provider)
click to toggle source
# File lib/video_info.rb, line 108 def ensure_enabled_provider(provider) if self.class.disabled_provider?(provider) raise UrlError, "#{provider} is disabled" end end