Class: VideoInfo

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/video_info.rb,
lib/video_info/version.rb,
lib/video_info/provider.rb,
lib/video_info/providers/vimeo.rb,
lib/video_info/providers/wistia.rb,
lib/video_info/providers/youtube.rb,
lib/video_info/providers/vimeo_api.rb,
lib/video_info/providers/dailymotion.rb,
lib/video_info/providers/youtube_api.rb,
lib/video_info/providers/vimeo_scraper.rb,
lib/video_info/providers/youtube_scraper.rb,
lib/video_info/providers/youtubeplaylist.rb,
lib/video_info/providers/youtubeplaylist_api.rb,
lib/video_info/providers/youtubeplaylist_scraper.rb

Defined Under Namespace

Modules: Providers, YoutubePlaylistAPI Classes: Error, HttpError, Provider, UrlError

Constant Summary collapse

PROVIDERS =
%w[
  Dailymotion
  Wistia
  Vimeo
  Youtube
  YoutubePlaylist
].freeze
VERSION =
"4.2.0".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, options = {}) ⇒ VideoInfo

Returns a new instance of VideoInfo.



55
56
57
# File 'lib/video_info.rb', line 55

def initialize(url, options = {})
  @provider = _select_provider(url, options)
end

Class Attribute Details

.disable_providersObject



16
17
18
# File 'lib/video_info.rb', line 16

def disable_providers
  @disable_providers || []
end

.loggerObject



31
32
33
34
35
# File 'lib/video_info.rb', line 31

def logger
  @logger ||= Logger.new($stdout).tap do |lgr|
    lgr.progname = name
  end
end

Class Method Details

.disabled_provider?(provider) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/video_info.rb', line 74

def self.disabled_provider?(provider)
  disable_providers.map(&:downcase).include?(provider.downcase)
end

.enabled_providersObject



78
79
80
81
82
# 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) ⇒ Object



59
60
61
# File 'lib/video_info.rb', line 59

def self.get(*args)
  new(*args)
end

.provider_api_keysObject



20
21
22
# File 'lib/video_info.rb', line 20

def provider_api_keys
  @provider_api_keys || {}
end

.provider_api_keys=(api_keys) ⇒ Object



24
25
26
27
28
29
# 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) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
# File 'lib/video_info.rb', line 63

def self.usable?(url)
  new(url)
  true
rescue UrlError
  false
end

.valid_url?(url) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/video_info.rb', line 84

def self.valid_url?(url)
  enabled_providers.any? { |p| p.usable?(url) }
end

Instance Method Details

#==(other) ⇒ Object



70
71
72
# File 'lib/video_info.rb', line 70

def ==(other)
  url == other.url && video_id == other.video_id
end