Skip to content

Commit e32a826

Browse files
authored
Merge pull request #234 from tylerpaige/chore/update-cassettes
Update VCR cassettes for Vimeo
2 parents 05f3c4c + 3bf9eee commit e32a826

File tree

62 files changed

+36214
-4038
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+36214
-4038
lines changed

lib/video_info/providers/vimeo_api.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ def api_key
77
VideoInfo.provider_api_keys[:vimeo]
88
end
99

10+
def available?
11+
is_available = super
12+
13+
if is_available
14+
# For password-protected videos, the API might return 200 on HEAD
15+
# but fail or return incomplete data on GET. Try to access the video data.
16+
begin
17+
video_data = _video
18+
# Check if we have the essential video data
19+
is_available = !video_data.nil? && !video_data["name"].nil?
20+
rescue VideoInfo::HttpError
21+
# If we get an HTTP error (like 401), the video is not available
22+
is_available = false
23+
end
24+
end
25+
26+
is_available
27+
end
28+
1029
%w[description].each do |method|
1130
define_method(method) { _video[method] }
1231
end

lib/video_info/providers/vimeo_scraper.rb

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,7 @@ def author_thumbnail
1515
return nil
1616
end
1717

18-
split_point = "window.vimeo.clip_page_config ="
19-
script_tags = data.css("script")
20-
21-
script_index = script_tags.find_index do |x|
22-
x.text.include?(split_point)
23-
end
24-
25-
script_text = script_tags[script_index].text
26-
27-
split_script_text = script_text.split(split_point)[1]
28-
29-
parsed_data = JSON.parse(split_script_text.split(";\n")[0])
30-
31-
parsed_data["owner"]["portrait"]["src"]
18+
json_info["author"]["image"]
3219
end
3320

3421
def author_url
@@ -42,12 +29,10 @@ def available?
4229

4330
if data.nil?
4431
is_available = false
45-
elsif is_available
46-
password_elements = data.css(".exception_title--password")
32+
end
4733

48-
unless password_elements.empty?
49-
is_available = false
50-
end
34+
if json_info.nil?
35+
is_available = false
5136
end
5237

5338
is_available
@@ -141,17 +126,26 @@ def interaction_statistic
141126
end
142127

143128
def json_info
144-
@json_info ||= JSON.parse(data.css("script").detect do |n|
145-
type = n.attr("type")
129+
@json_info ||= begin
130+
return nil if data.nil?
146131

147-
if type.nil?
148-
false
149-
else
150-
type.value == "application/ld+json"
132+
script_elements = data.css("script")
133+
script_element = script_elements.detect do |n|
134+
type = n.attr("type")
135+
if type.nil?
136+
false
137+
else
138+
type.value == "application/ld+json"
139+
end
151140
end
152-
end.text)[0]
141+
return nil if script_element.nil?
142+
JSON.parse(script_element.text)[0]
143+
rescue JSON::ParserError
144+
nil
145+
end
153146
end
154147

148+
155149
def thumbnail_url
156150
@thumbnail_url ||= remove_overlay(meta_node_value("og:image"))
157151
end

spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/_available_/with_password_required_video/_available_/1_2_3_1_1.yml

Lines changed: 235 additions & 95 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/fixtures/vcr_cassettes/VideoInfo_Providers_Vimeo/_available_/with_password_required_video/_available_/2_2_3_1_1.yml

Lines changed: 93 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)