Class: VideoInfo::Providers::Youtube

Inherits:
VideoInfo::Provider show all
Defined in:
lib/video_info/providers/youtube.rb

Direct Known Subclasses

YoutubePlaylist

Instance Attribute Summary

Attributes inherited from VideoInfo::Provider

#data, #options, #url, #video_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from VideoInfo::Provider

#available?, #embed_code, #stats, #thumbnail

Constructor Details

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

Returns a new instance of Youtube.



8
9
10
11
12
13
14
15
16
# File 'lib/video_info/providers/youtube.rb', line 8

def initialize(url, options = {})
  if VideoInfo.provider_api_keys[:youtube].nil?
    extend YoutubeScraper
  else
    extend YoutubeAPI
  end

  super(url, options)
end

Class Method Details

.usable?(url) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/video_info/providers/youtube.rb', line 18

def self.usable?(url)
  url.match?(/(youtube\.com\/(?!playlist|embed\/videoseries).*)|(youtu\.be)/)
end

Instance Method Details

#embed_urlObject



30
31
32
# File 'lib/video_info/providers/youtube.rb', line 30

def embed_url
  "//www.youtube.com/embed/#{video_id}"
end

#providerObject



22
23
24
# File 'lib/video_info/providers/youtube.rb', line 22

def provider
  "YouTube"
end

#thumbnail_largeObject



42
43
44
# File 'lib/video_info/providers/youtube.rb', line 42

def thumbnail_large
  "https://i.ytimg.com/vi/#{video_id}/hqdefault.jpg"
end

#thumbnail_large_2xObject



46
47
48
# File 'lib/video_info/providers/youtube.rb', line 46

def thumbnail_large_2x
  "https://i.ytimg.com/vi/#{video_id}/sddefault.jpg"
end

#thumbnail_maxresObject



50
51
52
# File 'lib/video_info/providers/youtube.rb', line 50

def thumbnail_maxres
  "https://i.ytimg.com/vi/#{video_id}/maxresdefault.jpg"
end

#thumbnail_mediumObject



38
39
40
# File 'lib/video_info/providers/youtube.rb', line 38

def thumbnail_medium
  "https://i.ytimg.com/vi/#{video_id}/mqdefault.jpg"
end

#thumbnail_smallObject



34
35
36
# File 'lib/video_info/providers/youtube.rb', line 34

def thumbnail_small
  "https://i.ytimg.com/vi/#{video_id}/default.jpg"
end