Class: Funky::HTML::Parser Private

Inherits:
Object
  • Object
show all
Defined in:
lib/funky/html/parser.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#extract_comments_from(html, video_id) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



35
36
37
38
39
40
# File 'lib/funky/html/parser.rb', line 35

def extract_comments_from(html, video_id)
  html.match /"commentcount":(.*?),/
  html.match(/commentcount:(\d+),commentcountreduced/) if $1.nil?
  html.match /commentcount:(\d+),.*commentstargetfbid:"#{video_id}"/ if $1.nil?
  matched_count $1
end

#extract_likes_from(html) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
32
33
# File 'lib/funky/html/parser.rb', line 29

def extract_likes_from(html)
  html.match(/"likecount":(\d+),"likecountreduced"/)
  html.match(/likecount:(\d+),likecountreduced/) if $1.nil?
  matched_count $1
end

#extract_shares_from(html, video_id) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



14
15
16
17
18
19
# File 'lib/funky/html/parser.rb', line 14

def extract_shares_from(html, video_id)
  html.match(/"sharecount":(.*?),/)
  html.match(/sharecount:(\d+),sharecountreduced/) if $1.nil?
  html.match(/sharecount:(\d+),.*sharefbid:"#{video_id}"/) if $1.nil?
  matched_count $1
end

#extract_views_from(html) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



21
22
23
24
25
26
27
# File 'lib/funky/html/parser.rb', line 21

def extract_views_from(html)
  html.match(/<div><\/div><span class="fcg">\D*([\d,.]+)/)
  html.match %r{([\d,.]*?) views from this post} if $1.nil?
  html.match /<div class=\"_1vx9\"><span>([\d,.]*?) .*?<\/span><\/div>/ if $1.nil?
  html.match(/postViewCount:"([\d,.]*?)",/) if $1.nil?
  matched_count $1
end

#parse(html:, video_id:) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



5
6
7
8
9
10
11
12
# File 'lib/funky/html/parser.rb', line 5

def parse(html:, video_id:)
  {
    view_count: extract_views_from(html),
    share_count: extract_shares_from(html, video_id),
    like_count: extract_likes_from(html),
    comment_count: extract_comments_from(html, video_id)
  }
end