Module: VideoInfo::Providers::VimeoScraper

Defined in:
lib/video_info/providers/vimeo_scraper.rb

Instance Method Summary collapse

Instance Method Details

#authorObject



10
11
12
13
14
# File 'lib/video_info/providers/vimeo_scraper.rb', line 10

def author
  if available?
    json_info['author']['name']
  end
end

#author_thumbnailObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/video_info/providers/vimeo_scraper.rb', line 16

def author_thumbnail
  unless available?
    return nil
  end

  split_point = 'window.vimeo.clip_page_config ='
  script_tags = data.css('script')

  script_index = script_tags.find_index do |x|
    x.text.include?(split_point)
  end

  script_text = script_tags[script_index].text

  split_script_text = script_text.split(split_point)[1]

  parsed_data = JSON.parse(split_script_text.split(";\n")[0])

  parsed_data['owner']['portrait']['src']
end

#author_urlObject



37
38
39
40
41
# File 'lib/video_info/providers/vimeo_scraper.rb', line 37

def author_url
  if available?
    json_info['author']['url']
  end
end

#available?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/video_info/providers/vimeo_scraper.rb', line 43

def available?
  is_available = super

  if data.nil?
    is_available = false
  elsif is_available
    password_elements = data.css('.exception_title--password')

    unless password_elements.empty?
      is_available = false
    end
  end

  is_available
end

#dateObject



67
68
69
70
71
72
# File 'lib/video_info/providers/vimeo_scraper.rb', line 67

def date
  if available?
    upload_date = json_info['uploadDate']
    ISO8601::DateTime.new(upload_date).to_time
  end
end

#descriptionObject



63
64
65
# File 'lib/video_info/providers/vimeo_scraper.rb', line 63

def description
  meta_node_value('og:description')
end

#durationObject



74
75
76
77
78
79
# File 'lib/video_info/providers/vimeo_scraper.rb', line 74

def duration
  if available?
    duration = json_info['duration']
    ISO8601::Duration.new(duration).to_seconds.to_i
  end
end

#heightObject



93
94
95
96
97
# File 'lib/video_info/providers/vimeo_scraper.rb', line 93

def height
  if available?
    json_info['height']
  end
end

#keywordsObject



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/video_info/providers/vimeo_scraper.rb', line 81

def keywords
  unless available?
    return nil
  end

  if json_info['keywords']
    json_info['keywords']
  else
    []
  end
end

#thumbnail_largeObject



117
118
119
120
121
# File 'lib/video_info/providers/vimeo_scraper.rb', line 117

def thumbnail_large
  if available?
    thumbnail_url.split('_')[0] + '_640.jpg'
  end
end

#thumbnail_mediumObject



111
112
113
114
115
# File 'lib/video_info/providers/vimeo_scraper.rb', line 111

def thumbnail_medium
  if available?
    thumbnail_url.split('_')[0] + '_200x150.jpg'
  end
end

#thumbnail_smallObject



105
106
107
108
109
# File 'lib/video_info/providers/vimeo_scraper.rb', line 105

def thumbnail_small
  if available?
    thumbnail_url.split('_')[0] + '_100x75.jpg'
  end
end

#titleObject



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

def title
  meta_node_value('og:title')
end

#view_countObject



123
124
125
126
127
# File 'lib/video_info/providers/vimeo_scraper.rb', line 123

def view_count
  if available?
    user_interaction_count(interaction_type: "http://schema.org/WatchAction")
  end
end

#widthObject



99
100
101
102
103
# File 'lib/video_info/providers/vimeo_scraper.rb', line 99

def width
  if available?
    json_info['width']
  end
end