#!/usr/bin/env ruby
# encoding: UTF-8
require 'net/http'
require 'uri'
require 'public_suffix_list'
require 'public_suffix'
require 'fileutils'
require 'mechanize'
require 'nokogiri'
require 'watir-webdriver'
require 'selenium/webdriver'
module VideoCounter
class ViewsCount
def initialize
make_agent
end
def find_site(url)
uri = URI.parse(url)
domain = PublicSuffix.parse(uri.host)
return domain.sld
end
def get_youtube_view(url) #ok
page = @agent.get url
doc = Nokogiri::HTML::DocumentFragment.parse(page.body)
views = doc.search(".watch-view-count").text
return views.to_s.strip
end
def get_dailymotion_view(url) #ok
page = @agent.get url
views = page.parser.xpath('//*[@id="video_views_countv2"]/b/text()')
return views.to_s.strip
end
def get_izlesene_view(url) #ok
page = @agent.get url
doc = Nokogiri::HTML::DocumentFragment.parse(page.body)
views = doc.search(".view_c").text
return views.to_s.strip
end
def get_trilulilu_view(url) #ok
page = @agent.get url
views = page.parser.xpath('//html/body/div[5]/div[3]/div/div/div/div[3]/div/div/div/div[2]/p/strong/text()')
return views[0].to_s.strip
end
def get_clipfish_view(url) #ok
page = @agent.get url
views = page.parser.xpath('//html/body/div[4]/div[6]/div/div[2]/div[3]/div[2]/div/div[2]/div[2]/div[3]/div[2]/div/div[2]/div[2]/span/text()')
return views[0].to_s.strip
end
def get_metacafe_view(url) #ok
page = @agent.get url
views_tmp = page.parser.xpath('//h2[@id="Views"]/text()')
if
views_tmp.empty?
then
views = page.parser.xpath('//html/body/div/div[6]/div/section/article/hgroup/span/text()')
else
views = views_tmp
end
return views.to_s.strip
end
def get_myspace_view(url) #ok
b = Watir::Browser.new(:phantomjs)
b.goto url
doc = Nokogiri::HTML(b.html)
regex = "(\"stats\")"+"(:)"+"(\\{)"+"(\"AllTime\")"+"(:)"+"(\".*?\")"+"(\\})" # "stats":{"AllTime":"258,549"}
doc.to_s.match(regex)
views = $6
return views.gsub('"', '')
end
def get_photobucket_view(url) # ok
b = Watir::Browser.new :phantomjs
b.goto url
doc = Nokogiri::HTML(b.html)
views = doc.xpath('//*[@id="viewCount"]')
return views.children.first.text
end
def get_daleplay_view(url) # toutes les videos sont en erreur copyright
page = @agent.get url
views = page.parser.xpath('//*[@id="video_views_countv2"]/b/text()')
return views.to_s.strip
end
def get_vxv_view(url) #ok
page = @agent.get url
views = page.parser.xpath('//*[@id="video_visit"]/text()')
return views.to_s.strip
end
def get_rutube_view(url) #ok
page = @agent.get url
views = page.parser.xpath('//html/body/div/div[2]/div[2]/div/section/div/div/div/div/div/div/div/div/div/div[2]/div[2]/div/div[2]/ul/li[2]/span[2]/text()')
return views.to_s.strip
end
def get_smotri_view(url) #ok
page = @agent.get url
doc = Nokogiri::HTML::DocumentFragment.parse(page.body)
views = doc.search(".Number").first.text
return views.to_s.strip
end
def get_miwim_view(url) #ok
page = @agent.get url
views = page.parser.xpath('//*[@id="useraction"]/div[1]/text()[3]').to_s.gsub('|','')
return views.strip
end
def get_wat_view(url) #ok
page = @agent.get url
views_tmp = page.parser.xpath('//html/body/div[3]/div[2]/div[2]/div/div/div/div/div[2]/div/span/text()').to_s.strip
views = views_tmp.split(" ")
return views[0]
end
def get_viddler_view(url) #ok
page = @agent.get url
views = page.parser.xpath('//html/body/div/div[2]/div[2]/div/p/span[2]/b/text()')
return views.to_s.strip
end
def get_veoh_view(url) #ok
page = @agent.get url
views = page.parser.xpath('.//*[@id="leftVideoDetails"]/div[1]/text()')
return views.to_s.strip
end
def get_myvideo_view(url) #ok
page = @agent.get url
views = page.parser.xpath('//*[@id="mCnt"]/text()')
return views.to_s.strip
end
def get_kewego_view(url) #ok
page = @agent.get url
views = page.parser.xpath('//html/body/div/div[4]/div[2]/div/div/div/div[2]/div/ul/li[3]/span/text()')
return views.to_s.strip
end
private
def make_agent
@agent = Mechanize.new do |a|
a.user_agent_alias = 'Mac Safari'
a.max_history = 1
a.open_timeout = 15
a.read_timeout = 5
a.keep_alive = false
end
end
end
end