Class: MyJobAnisoku2
- Inherits:
-
Object
- Object
- MyJobAnisoku2
- Defined in:
- lib/lib/job.rb
Instance Method Summary collapse
- #fc2 ⇒ Object
-
#initialize(args = { }) ⇒ MyJobAnisoku2
constructor
A new instance of MyJobAnisoku2.
-
#kobetu ⇒ Object
access say-move and make video job.
-
#run ⇒ Object
run in thread.
-
#second ⇒ Object
check shoukai page.
-
#third ⇒ Object
access say-move and make video job.
-
#tokkakari ⇒ Object
check kousin page.
-
#video ⇒ Object
fetch video.
Constructor Details
#initialize(args = { }) ⇒ MyJobAnisoku2
Returns a new instance of MyJobAnisoku2.
403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/lib/job.rb', line 403 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] ||= :tokkakari @a[:recent] ||= 7 @a[:limit] ||= 4 @FC2magick = @a[:fc2magick] ||='_gGddgPfeaf_gzyr' #updated FC2 2011.7 raise "job have no machine error" unless @a[:machine] end |
Instance Method Details
#fc2 ⇒ Object
518 519 520 521 522 523 524 525 526 527 528 529 530 531 |
# File 'lib/lib/job.rb', line 518 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 = MyJobAnisoku2.new( @a.merge({ :url => url, :status => :video })) @a[:machine].retry job end |
#kobetu ⇒ Object
access say-move and make video job
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 |
# File 'lib/lib/job.rb', line 449 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) ) 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 = MyJobAnisoku2.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 ⇒ Object
run in thread
562 563 564 565 566 |
# File 'lib/lib/job.rb', line 562 def run t = Thread.new do send @a[:status] end end |
#second ⇒ Object
check shoukai page
433 434 435 436 437 438 439 440 441 442 443 444 445 446 |
# File 'lib/lib/job.rb', line 433 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_kousin.each do |link| links_kobetu << $1 if link.value =~ /(http:\/\/youtubeanisoku.*)/ end # make job for each links_kobetu links_kobetu.each do |link| job = MyJobAnisoku2.new(@a.merge({:url => link,:status => :kobetu})) @a[:machine].retry job end end |
#third ⇒ Object
access say-move and make video job
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/lib/job.rb', line 483 def third print "Third".yellow sm = { :title => @a[:title],:url => @a[:url]} @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 = MyJobAnisoku2.new( @a.merge({ :url => sm[:url], :fc2 => fc2, :title => sm[:title], :status => :fc2 })) @a[:machine].retry job return else end end job = MyJobAnisoku2.new( @a.merge({ :url => sm[:videourl], :title => sm[:title], :status => :video })) @a[:machine].retry job end |
#tokkakari ⇒ Object
check kousin page
421 422 423 424 425 426 427 428 429 430 |
# File 'lib/lib/job.rb', line 421 def tokkakari print "Tokkakari".yellow @agent.get @a[:url] links_kousins = @agent.page.links_with(:text => /#{"更新状況"}/).map(&:uri) links_kousins.each_with_index do |link,i| break if i >= @a[:recent] job = MyJobAnisoku2.new(@a.merge({ :url => link,:status => :second, }) ) @a[:machine].retry job end end |
#video ⇒ Object
fetch video
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
# File 'lib/lib/job.rb', line 534 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 |