Class: VideoSieveWatchTab

Inherits:
VideoSieve show all
Defined in:
lib/forki/scrapers/sieves/video_sieves/video_sieve_watch_tab.rb

Overview

This is for the “watch” tab style videos www.facebook.com/watch/live/?v=394367115960503

Class Method Summary collapse

Methods inherited from VideoSieve

can_process_with_sieve?, sieve_for_graphql_objects

Class Method Details

.check(graphql_objects) ⇒ Object

To check if it’s valid for the inputted graphql objects



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/forki/scrapers/sieves/video_sieves/video_sieve_watch_tab.rb', line 5

def self.check(graphql_objects)
  video_object = self.extractor(graphql_objects)
  return false if video_object.nil?

  video_object = video_object["attachments"]
  return false if video_object.nil?

  return false unless video_object.kind_of?(Array) && !video_object.empty?

  video_object = video_object.first
  return false unless video_object.kind_of?(Hash) && video_object.keys.include?("media")

  true
rescue StandardError
  return false
end

.sieve(graphql_objects) ⇒ Object

output the expected format of:

post_details =

id: video_object["id"],
num_comments: num_comments,
num_shares: share_count_object.fetch("count", nil),
num_views: feedback_object["comet_ufi_summary_and_actions_renderer"]["feedback"]["video_view_count"],
reshare_warning: feedback_object["comet_ufi_summary_and_actions_renderer"]["feedback"]["should_show_reshare_warning"],
video_preview_image_url: video_object["preferred_thumbnail"]["image"]["uri"],
video_url: video_object["browser_native_hd_url"] || video_object["browser_native_sd_url"],
text: text,
created_at: creation_date,
profile_link: story_node_object["comet_sections"]["context_layout"]["story"]["comet_sections"]["actor_photo"]["story"]["actors"][0]["url"],
has_video: true

post_details = Forki.retrieve_media(post_details) post_details = Forki.retrieve_media(post_details) post_details = reaction_counts



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/forki/scrapers/sieves/video_sieves/video_sieve_watch_tab.rb', line 41

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"]

  if !video_object["feedback_context"].nil?
    feedback_object = video_object["feedback_context"]["feedback_target_with_context"]
  else
    feedback_object = graphql_objects.find { |go| !go.dig("feedback", "total_comment_count").nil? }
    feedback_object = feedback_object["feedback"] if feedback_object.has_key?("feedback")
  end

  profile_link = video_object["attachments"].first["media"]["owner"]["url"]
  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"]
  end

  post_details = {
    id: video_object.dig("shareable", "id") || video_object["attachments"].first["media"]["id"],
    num_comments: feedback_object["total_comment_count"],
    num_shared: nil, # This is not associated with these videos in this format
    num_views: nil, # This is not associated with these videos in this format
    reshare_warning: feedback_object["should_show_reshare_warning"],
    video_preview_image_url: video_preview_image_url,
    video_url: video_url,
    text: nil, # There is no text associated with these videos
    created_at: video_object["attachments"].first["media"]["publish_time"],
    profile_link: profile_link,
    has_video: true,
    video_preview_image_file: Forki.retrieve_media(video_preview_image_url),
    video_file: Forki.retrieve_media(video_url),
    reactions: reactions
  }
end