Skip to content

Commit

Permalink
Update for a few new paths
Browse files Browse the repository at this point in the history
  • Loading branch information
cguess committed Sep 12, 2024
1 parent 9ebc1e3 commit 578ed82
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 19 deletions.
18 changes: 10 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
forki (0.2.5)
forki (0.2.8)
apparition
capybara
oj
Expand Down Expand Up @@ -35,14 +35,15 @@ GEM
capybara (~> 3.13, < 4)
websocket-driver (>= 0.6.5)
ast (2.4.2)
bigdecimal (3.1.5)
base64 (0.2.0)
bigdecimal (3.1.8)
builder (3.2.4)
byebug (11.1.3)
capybara (3.39.2)
capybara (3.40.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
nokogiri (~> 1.11)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
Expand All @@ -54,7 +55,7 @@ GEM
erubi (1.12.0)
ethon (0.16.0)
ffi (>= 1.15.0)
ffi (1.16.3)
ffi (1.17.0-arm64-darwin)
i18n (1.13.0)
concurrent-ruby (~> 1.0)
json (2.6.3)
Expand All @@ -67,12 +68,12 @@ GEM
minitest (5.18.0)
nokogiri (1.15.1-arm64-darwin)
racc (~> 1.4)
oj (3.16.3)
oj (3.16.4)
bigdecimal (>= 3.0)
parallel (1.23.0)
parser (3.2.2.1)
ast (~> 2.4.1)
public_suffix (5.0.4)
public_suffix (5.1.1)
racc (1.6.2)
rack (2.2.4)
rack-test (2.1.0)
Expand Down Expand Up @@ -129,7 +130,8 @@ GEM
rubocop-rails (~> 2.0)
ruby-progressbar (1.13.0)
rubyzip (2.3.2)
selenium-webdriver (4.16.0)
selenium-webdriver (4.21.1)
base64 (~> 0.2)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
Expand Down
16 changes: 13 additions & 3 deletions lib/forki/scrapers/post_scraper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ def extract_video_post_data(graphql_strings)
begin
feedback_object = story_node_object["comet_sections"]["feedback"]["story"]["feedback_context"]["feedback_target_with_context"]["ufi_renderer"]["feedback"]
rescue NoMethodError
feedback_object = story_node_object["comet_sections"]["feedback"]["story"]["comet_feed_ufi_container"]["story"]["story_ufi_container"]["story"]["feedback_context"]["feedback_target_with_context"]
begin
feedback_object = story_node_object["comet_sections"]["feedback"]["story"]["comet_feed_ufi_container"]["story"]["story_ufi_container"]["story"]["feedback_context"]["feedback_target_with_context"]
rescue NoMethodError
feedback_object = story_node_object["comet_sections"]["feedback"]["story"]["story_ufi_container"]["story"]["feedback_context"]["feedback_target_with_context"]
end
end

if feedback_object["comet_ufi_summary_and_actions_renderer"]["feedback"].key?("cannot_see_top_custom_reactions")
Expand Down Expand Up @@ -315,8 +319,14 @@ def extract_image_post_data(graphql_object_array)
# TODO: These two branches are *super* similar, probably a lot of overlap
attachments = graphql_object["node"]["comet_sections"]["content"]["story"]["attachments"]

if graphql_object["node"]["comet_sections"]["feedback"]["story"].key?("feedback_context")
feedback_object = graphql_object["node"]["comet_sections"]["feedback"]["story"]["feedback_context"]["feedback_target_with_context"]["ufi_renderer"]["feedback"]["comet_ufi_summary_and_actions_renderer"]["feedback"]
if graphql_object["node"]["comet_sections"]["feedback"]["story"].has_key?("story_ufi_container")
feedback_object = graphql_object["node"]["comet_sections"]["feedback"]["story"]["story_ufi_container"]["story"]["feedback_context"]["feedback_target_with_context"]["comet_ufi_summary_and_actions_renderer"]["feedback"]
elsif graphql_object["node"]["comet_sections"]["feedback"]["story"].dig("feedback_context")
begin
feedback_object = graphql_object["node"]["comet_sections"]["feedback"]["story"]["feedback_context"]["feedback_target_with_context"]["ufi_renderer"]["feedback"]["comet_ufi_summary_and_actions_renderer"]["feedback"]
rescue NoMethodError
debugger
end
elsif graphql_object["node"]["comet_sections"]["feedback"]["story"].has_key?("comet_feed_ufi_container")
feedback_object = graphql_object["node"]["comet_sections"]["feedback"]["story"]["comet_feed_ufi_container"]["story"]["story_ufi_container"]["story"]["feedback_context"]["feedback_target_with_context"]["comet_ufi_summary_and_actions_renderer"]["feedback"]
else
Expand Down
27 changes: 20 additions & 7 deletions lib/forki/scrapers/sieves/video_sieves/video_sieve_watch_tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ def self.check(graphql_objects)
def self.sieve(graphql_objects)
video_object = self.extractor(graphql_objects)

video_url = video_object["attachments"].first["media"]["browser_native_sd_url"]
video_preview_image_url = video_object["attachments"].first["media"]["preferred_thumbnail"]["image"]["uri"]
# video_url = video_object["attachments"].first["media"]["browser_native_sd_url"]
video_url = video_object["short_form_video_context"]["playback_video"]["browser_native_hd_url"]
video_url = video_object["short_form_video_context"]["playback_video"]["browser_native_sd_url"] if video_url.nil?

# video_preview_image_url = video_object["attachments"].first["media"]["preferred_thumbnail"]["image"]["uri"]
video_preview_image_url = video_object["short_form_video_context"]["video"]["first_frame_thumbnail"]

if !video_object["feedback_context"].nil?
feedback_object = video_object["feedback_context"]["feedback_target_with_context"]
Expand All @@ -51,16 +55,25 @@ def self.sieve(graphql_objects)
feedback_object = feedback_object["feedback"] if feedback_object.has_key?("feedback")
end

profile_link = video_object["attachments"].first["media"]["owner"]["url"]
begin
profile_link = video_object["attachments"].first["media"]["owner"]["url"]
rescue StandardError => e
profile_link = video_object["short_form_video_context"]["video_owner"]["url"]
end

if profile_link.nil?
filtered_json = graphql_objects.find { |go| go.has_key? "attachments" }
profile_link = filtered_json["attachments"].first["media"]["creation_story"]["comet_sections"]["title"]["story"]["actors"].first["url"]
end

if feedback_object.key?("cannot_see_top_custom_reactions")
reactions = feedback_object["cannot_see_top_custom_reactions"]["top_reactions"]["edges"]
else
reactions = feedback_object["top_reactions"]["edges"]
begin
if feedback_object.key?("cannot_see_top_custom_reactions")
reactions = feedback_object["cannot_see_top_custom_reactions"]["top_reactions"]["edges"]
else
reactions = feedback_object["top_reactions"]["edges"]
end
rescue StandardError => e
reactions = feedback_object["unified_reactors"]["count"]
end

post_details = {
Expand Down
2 changes: 1 addition & 1 deletion lib/forki/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Forki
VERSION = "0.2.8"
VERSION = "0.2.9"
end
4 changes: 4 additions & 0 deletions test/post_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,8 @@ def test_a_pure_text_link
assert !post.first.text.empty?
assert_predicate post.first.text.length, :positive?
end

def test_an_alternative_reel
Forki::Post.lookup("https://www.facebook.com/reel/2841887882618164")
end
end

0 comments on commit 578ed82

Please sign in to comment.