Skip to content

Commit a79ffaa

Browse files
committed
Get title as text for reels
1 parent 8653e23 commit a79ffaa

3 files changed

Lines changed: 27 additions & 15 deletions

File tree

lib/forki/scrapers/sieves/video_sieves/video_sieve_watch_tab.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ def self.check(graphql_objects)
4040

4141
def self.sieve(graphql_objects)
4242
video_object = self.extractor(graphql_objects)
43+
title_object = self.extract_title_object(graphql_objects)
44+
45+
text = title_object.dig("text")
4346

4447
video_url = video_object["attachments"]&.first.dig("media", "browser_native_sd_url")
4548

@@ -104,7 +107,7 @@ def self.sieve(graphql_objects)
104107
reshare_warning: feedback_object["should_show_reshare_warning"],
105108
video_preview_image_urls: video_preview_image_urls,
106109
video_url: video_url,
107-
text: nil, # There is no text associated with these videos
110+
text: text, # There is no text associated with these videos
108111
created_at: video_object["attachments"].first["media"]["publish_time"],
109112
profile_link: profile_link,
110113
has_video: true,
@@ -127,4 +130,11 @@ def self.extractor(graphql_objects)
127130

128131
story
129132
end
133+
134+
def self.extract_title_object(graphql_objects)
135+
attachment_objects = graphql_objects.filter do |go|
136+
go.has_key?("attachments")
137+
end
138+
attachment_objects.first&.dig("attachments")&.first.dig("media", "title")
139+
end
130140
end

lib/forki/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Forki
4-
VERSION = "0.2.32"
4+
VERSION = "0.2.33"
55
end

test/post_test.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,11 +289,6 @@ def test_reel_other_format
289289
end
290290
end
291291

292-
# Not sure why this is here, it's not a link that works
293-
# def test_another_link
294-
# Forki::Post.lookup("https://www.facebook.com/manuelbuffa84/posts/pfbid02uqbifnKoRhW6Z9T1EBNXAnH5uyn9khWjPtfUYZPrLfkdjxtpTqpj521doA6Aa51ol")
295-
# end
296-
297292
def test_another_link_2
298293
post = Forki::Post.lookup("https://www.facebook.com/bonifacemusavulivh/posts/1800353787146024/").first
299294

@@ -363,14 +358,6 @@ def test_a_url_that_seems_to_fail_2
363358
assert File.size(post.first.image_file) > 1000
364359
end
365360

366-
# NOTE: This does fail, because it's gone'
367-
# def test_a_url_that_seems_to_fail_3
368-
# post = Forki::Post.lookup("https://www.facebook.com/share/p/19JjhuYDjy/")
369-
# assert_not_nil(post)
370-
371-
# assert File.size(post.first.image_file) > 1000
372-
# end
373-
374361
def test_a_video_without_text_works
375362
post = Forki::Post.lookup("https://www.facebook.com/watch/live/?ref=watch_permalink&v=535737772684504")
376363
assert_not_nil(post)
@@ -502,4 +489,19 @@ def test_multiple_media_works
502489
assert_not_nil(post.created_at)
503490
end
504491
end
492+
493+
def test_a_reel_with_text_works
494+
posts = Forki::Post.lookup("https://www.facebook.com/watch/?v=1264952764841420&ref=sharing")
495+
assert_not_nil(posts)
496+
497+
posts.each do |post|
498+
post.video_files.each do |image|
499+
assert File.size(image) > 1000
500+
end
501+
502+
assert File.size(post.user.profile_image_file) > 1000
503+
assert_not_nil(post.created_at)
504+
assert !post.text.blank?
505+
end
506+
end
505507
end

0 commit comments

Comments
 (0)