Class: MyMachineAnisoku
- Inherits:
-
Object
- Object
- MyMachineAnisoku
- Includes:
- MyMachine
- Defined in:
- lib/lib/machine.rb
Overview
Class of Machine by EventMachine. this class controll jobs for Anisoku
Instance Attribute Summary collapse
-
#savedir ⇒ Object
directory of save video files default “#'HOME'/Desktop/video”.
Instance Method Summary collapse
- #chk_header(string) ⇒ Object
- #del_small_files ⇒ Object
- #episode_exists?(key) ⇒ Boolean
-
#finalize_files ⇒ Object
delete tiny fail files.
-
#go ⇒ Object
machine go to run eventmachine.
-
#initialize(args = { }) ⇒ MyMachineAnisoku
constructor
set video save dir.
- #make_dellist ⇒ Object
- #make_filelist ⇒ Object
- #make_header(string) ⇒ Object
Methods included from MyMachine
Constructor Details
#initialize(args = { }) ⇒ MyMachineAnisoku
set video save dir
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/lib/machine.rb', line 205 def initialize(args={ }) super(args) args[:savedir] ||= "#{ENV['HOME']}/Desktop/video" @savedir = args[:savedir] begin Dir::mkdir(@savedir, 0777) rescue => ex warn ex end require 'rubygems' require 'eventmachine' # @gaman controll eventmachine end @gaman = 0 @checklist = {} @filelist = {} @dellist = [] @args = args @args[:limit] ||= 7 @args[:recent] ||= 7 @args[:mode] ||= :anisoku make_filelist make_dellist end |
Instance Attribute Details
#savedir ⇒ Object
directory of save video files default “#'HOME'/Desktop/video”
199 200 201 |
# File 'lib/lib/machine.rb', line 199 def savedir @savedir end |
Instance Method Details
#chk_header(string) ⇒ Object
247 248 249 |
# File 'lib/lib/machine.rb', line 247 def chk_header(string) @filelist[string] end |
#del_small_files ⇒ Object
273 274 275 276 277 278 |
# File 'lib/lib/machine.rb', line 273 def del_small_files @dellist.each do |e| p e if @debug File.delete("#{e}") end end |
#episode_exists?(key) ⇒ Boolean
280 281 282 283 284 285 286 287 288 |
# File 'lib/lib/machine.rb', line 280 def episode_exists?(key) if @checklist[key].nil? puts "MACHINE NOE FIRST CHECK THIS EPISODE!!".red.bold if @debug @checklist[key] = "checked" return false else return true end end |
#finalize_files ⇒ Object
delete tiny fail files
306 307 308 309 310 311 312 |
# File 'lib/lib/machine.rb', line 306 def finalize_files del_small_files command = "find #{@savedir} -size -1000k -type f -print0| xargs -0 rm -v " exec command command = "find /Users/seijiro/Desktop/video -type f > ~/Desktop/video.m3u && open ~/Desktop/video.m3u " exec command end |
#go ⇒ Object
machine go to run eventmachine
291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/lib/machine.rb', line 291 def go EM.run do EM.add_periodic_timer(0.00001) do print "loop".green if should_stop_machine? finalize_files EM.stop end @queue.pop.run unless @queue.empty? end end puts "End of fetch".green.bold end |
#make_dellist ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/lib/machine.rb', line 259 def make_dellist @filelist.each do |k,v| p k if @debug max_size = v.map { |e| e[:size] }.max p max_size if @debug v.each do |vv| if vv[:size] < max_size || vv[:size] < 1024 * 1024 * 2 @dellist << vv[:name] end end end pp @dellist if @debug end |
#make_filelist ⇒ Object
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/lib/machine.rb', line 230 def make_filelist Dir.new(@savedir).each do |entry| if File.file?("#{@savedir}/#{entry}") header = make_header(entry) if header filesize = File.size("#{@savedir}/#{entry}") @filelist[header] = [] unless chk_header(header) @filelist[header] << { :size => filesize, :name => "#{@savedir}/#{entry}", } end end end pp @filelist if @debug end |
#make_header(string) ⇒ Object
251 252 253 254 255 256 257 |
# File 'lib/lib/machine.rb', line 251 def make_header(string) if string.scan(/^.*?\d{1,3}話/).first header = string.scan(/^.*?\d{1,3}話/).first.gsub(' ','').gsub(' ','') end p header if @debug return header end |