Class: OggEncode::OggEncoder

Inherits:
Object
  • Object
show all
Defined in:
lib/autogg/encoder.rb

Class Method Summary collapse

Class Method Details

.count_flacsObject



35
36
37
38
39
# File 'lib/autogg/encoder.rb', line 35

def count_flacs
  c = 0
  Find.find( @options.paths.flac ) {|p| c += 1 if Flac.exists?( p ) }
  c
end

.count_oggsObject



41
42
43
44
45
# File 'lib/autogg/encoder.rb', line 41

def count_oggs
  c = 0
  Find.find( @options.paths.ogg ) {|p| c += 1 if Ogg.exists?( p ) }
  c
end

.encfile(inpath) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/autogg/encoder.rb', line 22

def encfile( inpath )
  outpath = getoutpath( inpath )
  @ps_hash.store( nil, outpath ) do
    ps = IO.popen %Q{oggenc #{@options.oggargs.join(' ')} "#{inpath}" -o "#{outpath}"}
  end
  @pbar.inc
end

.encode(options) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/autogg/encoder.rb', line 55

def encode( options )
  @options = options
  @ps_hash = SizedPsHash.new( options.max_procs )
  @log = Logger.new(@options.paths.ogg)
  oggencdir
ensure
  @log.close
end

.getoutpath(inpath) ⇒ Object



30
31
32
33
# File 'lib/autogg/encoder.rb', line 30

def getoutpath( inpath )
  outpath = inpath.gsub( @options.paths.flac, @options.paths.ogg )
  outpath.gsub!( /\.flac/, '.ogg' )
end

.interuptObject



47
48
49
50
51
52
53
# File 'lib/autogg/encoder.rb', line 47

def interupt
  puts "\n" + "Shutting down and removing partially encoded files"
  @ps_hash.each do |pid, path|
    File.delete( path )
  end
  exit
end

.oggencdirObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/autogg/encoder.rb', line 8

def oggencdir
  @pbar = ProgressBar.new( "Progress", ( count_flacs - count_oggs ) )
  Find.find( @options.paths.flac ) do |path|
    if FileTest.directory?( path )
      Find.prune if File.basename( path )[0] == ?.
    elsif Flac.exists?( path ) and not Ogg.exists?( getoutpath(path) )
      encfile( path )
    else
      @log << path
    end
  end
  Process.waitall ; @ps_hash = {} ; @pbar.finish
end