Module: VideoInfo::Providers::VimeoScraper

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

Instance Method Summary collapse

Instance Method Details

#authorObject



7
8
9
10
11
# File 'lib/video_info/providers/vimeo_scraper.rb', line 7

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

#author_thumbnailObject



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

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



34
35
36
37
38
# File 'lib/video_info/providers/vimeo_scraper.rb', line 34

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

#available?Boolean

Returns:

  • (Boolean)


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

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



64
65
66
67
68
69
# File 'lib/video_info/providers/vimeo_scraper.rb', line 64

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

#descriptionObject



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

def description
  meta_node_value("og:description")
end

#durationObject



71
72
73
74
75
76
# File 'lib/video_info/providers/vimeo_scraper.rb', line 71

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

#heightObject



86
87
88
89
90
# File 'lib/video_info/providers/vimeo_scraper.rb', line 86

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

#keywordsObject



78
79
80
81
82
83
84
# File 'lib/video_info/providers/vimeo_scraper.rb', line 78

def keywords
  unless available?
    return nil
  end

  json_info["keywords"] || []
end

#statsObject



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

def stats
  return {} unless available?
  {
    "plays" => view_count,
    "likes" => user_interaction_count(interaction_type: "LikeAction"),
    "comments" => user_interaction_count(interaction_type: "CommentAction")
  }
end

#thumbnail_largeObject



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

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

#thumbnail_mediumObject



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

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

#thumbnail_smallObject



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

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

#titleObject



56
57
58
# File 'lib/video_info/providers/vimeo_scraper.rb', line 56

def title
  meta_node_value("og:title")
end

#view_countObject



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

def view_count
  if available?
    user_interaction_count(interaction_type: "WatchAction")
  end
end

#widthObject



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

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