Class: MyJobAnime44
- Inherits:
-
Object
- Object
- MyJobAnime44
- Defined in:
- lib/lib/job.rb
Instance Method Summary collapse
- #anime44_fetch ⇒ Object
- #anime44_first ⇒ Object
- #daily_src2hqurl(url) ⇒ Object
-
#initialize(args = {}) ⇒ MyJobAnime44
constructor
A new instance of MyJobAnime44.
- #run ⇒ Object
- #top_page ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ MyJobAnime44
Returns a new instance of MyJobAnime44.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/lib/job.rb', line 4 def initialize(args={}) require 'kconv' require 'mechanize' require 'net/http' @a = args @debug = args[:debug] ||= false @a[:url] ||= 'http://www.anime44.com/' @a[:status] ||= :top_page return if @a[:url].nil? @agent = Mechanize.new @a[:recursive] ||= 4 end |
Instance Method Details
#anime44_fetch ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/lib/job.rb', line 117 def anime44_fetch print "video".yellow savedir = @a[:machine].savedir Dir.chdir savedir filename = "#{@a[:title].gsub(' ','').gsub(' ','')}.mp4" savepath = "#{savedir}/#{filename}" 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... command = "curl -# -L -R -o '#{filename}' '#{@a[:url]}' >/dev/null 2>&1 &" puts command system command unless @debug end |
#anime44_first ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/lib/job.rb', line 34 def anime44_first print :anime44_first if @debug puts @a[:url] if @debug begin @agent.get @a[:url] rescue => ex p ex if @debug p @a[:url] if @debug return end @title = @agent.page.title flg = false = @agent.page.search('embed[@src^="http://www.videozer"]').map {|ne| ne[:src] } unless [0].nil? flg = true url1 = [0].gsub('http://www.videozer.com/embed/','http://video195.videozer.com/video?v=') url = "#{url1}&r=1&t=#{Time.new.to_i.to_s}&u=&start=0" job = MyJobAnime44.new( @a.merge({ :url => url, :title => @title, :status => :anime44_fetch})) @a[:machine].retry job end unless flg == true begin @agent.get @a[:url] rescue => ex p ex if @debug p @a[:url] if @debug return end = @agent.page.search('embed[@src^="http://www.daily"]').map {|ne| ne[:src] } unless [0].nil? uri = daily_src2hqurl([0]) if uri[:status] == :ok flg = true job = MyJobAnime44.new( @a.merge({ :url => uri[:url], :title => @title, :status => :anime44_fetch})) @a[:machine].retry job end end end begin if @a[:recursive] > 0 alignleft = @agent.page.search('div.alignleft a')[0]['href'] job = MyJobAnime44.new( @a.merge({ :url => alignleft, :recursive => @a[:recursive] -1 , :status => :anime44_first})) @a[:machine].retry job else p "recursive stop" if @debug end rescue => ex end begin if @a[:recursive] > 0 alignright = @agent.page.search('div.alignright a')[0]['href'] job = MyJobAnime44.new( @a.merge({ :url => alignright, :recursive => @a[:recursive] - 1, :status => :anime44_first})) @a[:machine].retry job else p "recursive stop" if @debug end rescue => ex end end |
#daily_src2hqurl(url) ⇒ Object
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/lib/job.rb', line 140 def daily_src2hqurl(url) require 'json' begin js= JSON.parse(@agent.get(url.gsub('swf','sequence/full')).body) uri = js[0]['layerList'][0]['sequenceList'][1]['layerList'][2]['param']['videoPluginParameters']['hqURL'] rescue =>ex return {:status => :error} end {:status => :ok,:url => uri} end |
#run ⇒ Object
151 152 153 |
# File 'lib/lib/job.rb', line 151 def run send @a[:status] end |
#top_page ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lib/job.rb', line 17 def top_page print :top_page if @debug @agent.get @a[:url] # p @agent.page @agent.page.search('table')[1].css('td li') targs = @agent.page.search('table')[1].css('td li')# .select {|ne| ne.text =~ /\(Raw\)/ } a_s = [] targs.each {|ne| a_s << ne.css('a').map{|e|e[:href]}[0]} a_s.each do |link| job = MyJobAnime44.new(@a.merge({ :url => link, :status => :anime44_first })) @a[:machine].retry job end end |