#!/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 VideoTitle
class ViewTitle
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_title(url) #ok
page = @agent.get url
views = page.parser.xpath('//*[@id="eow-title"]/text()')
return views.to_s.strip # sortie en html, supprimer les tags?
end
def get_dailymotion_title(url) #ok
page = @agent.get url
views = page.at('meta[@property="og:title"]')[:content]
return views
end
def get_izlesene_title(url) #ok
page = @agent.get url
views = page.at('meta[@property="og:title"]')[:content]
#views = page.parser.xpath('//html/body/div[9]/div/article/div[2]/meta[10]/content()')
return views.to_s.strip
end
def get_trilulilu_title(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/h1/text()')
return views[0].to_s.strip
end
def get_clipfish_title(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/h1/text()')
return views[0].to_s.strip
end
def get_metacafe_title(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]/hgroup/h1/text()')
else
views = views_tmp
end
return views.to_s.strip
end
def get_myspace_title(url) #ok
page = @agent.get url
views = page.at('meta[@property="og:title"]')[:content]
return views
end
def get_photobucket_title(url) #ok
page = @agent.get url
views = page.at('meta[@property="og:title"]')[:content]
return views
end
def get_daleplay_title(url) #ko no available vid
page = @agent.get url
views = page.parser.xpath('//*[@id="video_views_countv2"]/b/text()')
return views.to_s.strip
end
def get_vxv_title(url) #ok
page = @agent.get url
views = page.parser.xpath('//html/body/div[4]/div/div/div[2]/h1/text()')
return views.to_s.strip
end
def get_rutube_title(url) #ok
page = @agent.get url
views = page.at('meta[@property="og:title"]')[:content]
return views
end
def get_smotri_title(url) #ok
page = @agent.get url
views = page.parser.xpath('//html/body/div[6]/div/div/div[3]/div/div/div[2]/div/h1/text()')
return views.to_s.strip
end
def get_miwim_title(url) #ok
page = @agent.get url
views = page.parser.xpath('//*[@id="viewvideo-title"]/h1/text()')
return views.to_s.strip
end
def get_wat_title(url) #ok
page = @agent.get url
views = page.parser.xpath('//html/body/div[3]/div[2]/div/div[2]/div/div/div/h1/text()')
return views.to_s.strip
end
def get_viddler_title(url) #ok
page = @agent.get url
views = page.at('meta[@property="og:title"]')[:content]
return views.to_s.strip
end
def get_veoh_title(url) #ok
page = @agent.get url
views = page.at('meta[@name="og:title"]')[:content]
return views.to_s.strip
end
def get_myvideo_title(url) #ok
page = @agent.get url
views = page.parser.xpath('//html/body/div[6]/div[3]/div[6]/div[3]/div/div[2]/div/table/tbody/tr/td[2]/h1/text()')
return views.to_s.strip
end
def get_kewego_title(url) #ok
page = @agent.get url
views = page.at('meta[@name="title"]')[:content]
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