Class: Bulbasaur::ExtractImagesFromYoutube

Inherits:
Object
  • Object
show all
Defined in:
lib/bulbasaur/extracts/extract_images_from_youtube.rb

Constant Summary collapse

EXTRACT_URL_PATTERN =
/www\.youtube(?:-nocookie)?\.com\/(?:v|embed)\/[a-zA-Z0-9-]+/i
EXTRACT_VID_PATTERN =
/(?<=v|embed)\/(?<vid>[a-zA-Z0-9-]+)/i

Instance Method Summary collapse

Constructor Details

#initialize(html) ⇒ ExtractImagesFromYoutube

Returns a new instance of ExtractImagesFromYoutube.



8
9
10
# File 'lib/bulbasaur/extracts/extract_images_from_youtube.rb', line 8

def initialize(html)
  @html = html
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
# File 'lib/bulbasaur/extracts/extract_images_from_youtube.rb', line 12

def call
  images = Array.new
  @html.scan(EXTRACT_URL_PATTERN).each do |video|
    vid = get_vid(video)
    images << { url: image_url(vid), video_url: video, source: 'youtube' }
  end
  images
end