class Funky::HTML::Parser
Public Instance Methods
extract_comments_from(html, video_id)
click to toggle source
# File lib/funky/html/parser.rb, line 40 def extract_comments_from(html, video_id) html.match /"commentcount":(.*?),/ html.match(/commentcount:(\d+),commentcountreduced/) if $1.nil? html.match /commentcount:(\d+),commentTotalCount/ if $1.nil? html.match /commentcount:(\d+),.*commentstargetfbid:"#{video_id}"/ if $1.nil? html.match(/comment_count:{total_count:(\d+)}/) if $1.nil? matched_count $1 end
extract_likes_from(html)
click to toggle source
# File lib/funky/html/parser.rb, line 32 def extract_likes_from(html) html.match(/"likecount":(\d+),"likecountreduced"/) html.match(/likecount:(\d+),likecountreduced/) if $1.nil? html.match(%r[{localized_name:"Like",reaction_type:"LIKE",id:"1635855486666999",key:1},reaction_count:(\d+)}]) if $1.nil? html.match(%r[{reaction_count:(\d+),node:{key:1,id:"1635855486666999",localized_name:"Like",reaction_type:"LIKE"}]) if $1.nil? matched_count $1 end
extract_views_from(html)
click to toggle source
# File lib/funky/html/parser.rb, line 22 def extract_views_from(html) html.match(/<div><\/div><span class="fcg">\D*([\d,.]+)/) html.match(/postViewCount:"([\d,.]*?)",/) if $1.nil? 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 /id=\"u_0_w\">([\d,.]*?) .*?<\/span><\/div>/ if $1.nil? html.match />([\d,.]*?) Views<\/span><\/div>/ if $1.nil? matched_count $1 end
parse(html:, video_id:)
click to toggle source
# 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
Private Instance Methods
matched_count(matched)
click to toggle source
# File lib/funky/html/parser.rb, line 51 def matched_count(matched) matched ? matched.delete(',').to_i : nil end