class MyJobAnisoku
Job Class for Fetch Anisoku Function:
access "youtubeanisoku1.blog106.fc2.com" and crawl web site. find a link to "say-move.org" and access "say-move.org". finary find video link of Animetion,then fetch video file to your local. save video directory is supplied by machine.
Notice:
job is automatically generated on after another. This Class Needs to be handle by Machine Class
@example
# inside machine class job = MyJobAnisoku.new( :machine => self ) job.run
Public Class Methods
new(args = { })
click to toggle source
# File lib/lib/job.rb, line 175 def initialize(args = { }) require 'rubygems' require 'kconv' require 'mechanize' require 'net/http' @a = args @debug = args[:debug] ||= false @a[:url] ||= 'http://youtubeanisoku1.blog106.fc2.com/' @a[:url] = URI.parse @a[:url] unless @a[:url].class == URI::HTTP @agent = Mechanize.new @a[:status] ||= :new @a[:recent] ||= 7 @a[:limit] ||= 4 # make md5 with magicword '_gGddgPfeaf_gzyr' @FC2magick = @a[:fc2magick] ||='_gGddgPfeaf_gzyr' #updated FC2 2011.7 raise "job have no machine error" unless @a[:machine] p @a if @debug && @a[:status] == :new end
Public Instance Methods
fc2()
click to toggle source
# File lib/lib/job.rb, line 334 def fc2 print "fc2".yellow require 'digest' url = "http://video.fc2.com/ginfo.php?mimi=#{Digest::MD5.hexdigest(@a[:fc2] + @FC2magick)}&v=#{@a[:fc2]}&upid=#{@a[:fc2]}&otag=1" url = `curl -# -L -R "#{url} "` url = url.split('&')[0].split('=')[1] + '?' + url.split('&')[1] puts url.red.bold job = MyJobAnisoku.new( @a.merge({ :url => url, :status => :video })) @a[:machine].retry job end
kobetu()
click to toggle source
access say-move and make video job
# File lib/lib/job.rb, line 261 def kobetu print "Kobetu".yellow @agent.get @a[:url] title = @agent.page.title.gsub(' ★ You Tube アニ速 ★','') # acume url htmlA = @agent.page/"/html/body/table/tr[2]/td/table/tr/td[2]/div[4]/div[@class='kijisub']" require 'pp' targsHTMLs = htmlA.inner_html.toutf8.split(/ランキング/)[0].split(/\n第/).reverse! #http://posterous.com/getfile/files.posterous.com/temp-2011-08-21/eolunzlwwwFopCnhszaBwJlFEJEnHcloqkoyaFuhdezmdgipcyyiyzdpqcpG/cro08nyoutube.doc require 'digest' targsHTMLs.each_with_index do |html,i| break if i >= @a[:limit] key = title + html.to_s unless @a[:machine].episode_exists?( Digest::MD5.hexdigest(key) ) # puts "NOW 2 PROCEED FETCH".green.bold + html[0..20].yellow.bold indi = Nokogiri::HTML.fragment(html).css("a") indi.each do |va| p va[:href] if @debug if va[:href] =~ /(http:\/\/say-move\.org\/comeplay\.php.*)/ job = MyJobAnisoku.new( @a.merge({ :url => $1, :title => title + '第' + html.split('<').first.gsub(' ','').gsub(' ',''), :status => :third})) @a[:machine].retry job end end else puts "ALREADY REGISTED CANCELL FETCH".cyan.bold + html[0..20].yellow.bold if @debug end key = nil end end
run()
click to toggle source
run in thread
# File lib/lib/job.rb, line 378 def run t = Thread.new do case @a[:status] when :new then tokkakari when :second then second when :kobetu then kobetu when :third then third when :fc2 then fc2 when :video then video end end end
second()
click to toggle source
check shoukai page
# File lib/lib/job.rb, line 238 def second print "Second".yellow @agent.get @a[:url] links_kousin = @agent.page/"/html/body/table/tr[2]/td/table/tr/td[2]/div[4]/ul/li/a/@href" # links_kobetu links_kobetu = [] links_kousin.each do |link| links_kobetu << $1 if link.value =~ /(http:\/\/youtubeanisoku.*)/ end # make job for each links_kobetu links_kobetu.each do |link| p link if @debug job = MyJobAnisoku.new( @a.merge({ :url => link, :status => :kobetu } )) @a[:machine].retry job end end
third()
click to toggle source
access say-move and make video job
# File lib/lib/job.rb, line 296 def third print "Third".yellow #sm has title and url sm = { :title => @a[:title],:url => @a[:url]} # debug fc2 video sm[:url] = "http://say-move.org/comeplay.php?comeid=217953" @agent.get(sm[:url]) sm[:title] += @agent.page.title.gsub!('FC2 SayMove!','') set = @agent.page/"/html/body/div/div[2]/div[7]/div[2]/input/@value" if !set.empty? sm[:videourl] = set[0].value else set = @agent.page/"/html/body/div/div[2]/div[3]/object/param[5]/@value" fc2 = set[0].value.split('&')[1].split('=')[1] unless fc2.nil? p sm[:url] if @debug job = MyJobAnisoku.new( @a.merge({ :url => sm[:url], :fc2 => fc2, :title => sm[:title], :status => :fc2 })) @a[:machine].retry job return else end end job = MyJobAnisoku.new( @a.merge({ :url => sm[:videourl], :title => sm[:title], :status => :video })) @a[:machine].retry job end
tokkakari()
click to toggle source
check kousin page
# File lib/lib/job.rb, line 195 def tokkakari print "Tokkakari".yellow @agent.get @a[:url] links_kousins = @agent.page.links_with(:text => /#{"更新状況"}/) links_kousins2 = @agent.page.links_with(:href => /blog\-entry/) targs = [] targs2 = [] links_kousins.each do |link| targs << link.uri end links_kousins2.each do |link| targs2 << link.uri end targs.each_with_index do |link,i| break if i >= @a[:recent] p link if @debug job = MyJobAnisoku .new( @a.merge({ :url => link, :status => :second, }) ) @a[:machine].retry job end targs2.each_with_index do |link,i| p link if @debug job = MyJobAnisoku .new( @a.merge({ :url => link, :status => :kobetu, }) ) @a[:machine].retry job end end
video()
click to toggle source
fetch video
# File lib/lib/job.rb, line 350 def video print "video".yellow # save video directory is supplied by machine. savedir = @a[:machine].savedir Dir.chdir savedir filename = "#{@a[:title].gsub(' ','').gsub(' ','')}.mp4" savepath = "#{savedir}/#{filename}" # check fetch candidate had been already saved? if File.exist?(savepath) && File.size(savepath) > 1024 * 1024 * 3 puts "File Already Saved ".yellow.bold + savepath return else puts "Fetching ".green.bold + savepath MyLogger.ln "Fetch Attempt Start ".green.bold + savepath end # use curl command # no need UA... uri = "http://#{@a[:url].host}#{@a[:url].path}" uri += "?#{@a[:url].query}" if @a[:url].query command = "curl -# -L -R -o '#{filename}' '#{uri}' >/dev/null 2>&1" # command += "&& growlnotify -t '#{filename}' -m '#{uri}' " puts command if @debug system command unless @debug end