Class: Recordings

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

Instance Method Summary collapse

Constructor Details

#initializeRecordings

Returns a new instance of Recordings.



7
8
9
# File 'lib/recordings.rb', line 7

def initialize()
  @recordings_db = Hash.new
end

Instance Method Details

#add(directory) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/recordings.rb', line 45

def add(directory)
  # TODO: Add a new recording that was found in the specified directory
  # Ensure that VDR has finished writing the recording by checking the mtime of the index file
  # Wait at least 30 seconds after VDR has finished
  return false unless (Time.now - File.mtime(directory + '/index')) > 30
  @recordings_db[directory] = Recording.new(directory)
  @recordings_db[directory].process!
end

#dumpObject



32
33
34
35
36
# File 'lib/recordings.rb', line 32

def dump()
  File.open('/vdr/rubyVDRconvert.recordings.marshal', 'wb:ascii-8bit') { | f |
    f.write(Marshal.dump(@recordings_db))
  }
end

#loadObject



37
38
39
40
41
42
43
44
# File 'lib/recordings.rb', line 37

def load()
  begin
    data = File.read('/vdr/rubyVDRconvert.recordings.marshal')
    @recordings_db = Marshal.load(data)
  rescue
    @recordings_db = Hash.new
  end
end

#scanObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/recordings.rb', line 10

def scan()
  basedir = '/vdr'
  found_directories = Array.new
  Find.find(basedir) { | entry |
    entry.force_encoding('BINARY')
    # Look for the index file created by VDR
    if File.basename(entry) == "index" then
      directory = File.dirname(entry)
      unless directory.end_with?('.del') # These directories have been marked as deleted from VDR...
        found_directories << directory
        if @recordings_db[directory] == nil then
          # Found a new entry
          add(directory)
        end
      end
    end
  }
  @recordings_db.each { | recording |
    puts "Removing recording: #{recording}"
    recording[1].delete! unless found_directories.include?(recording[1].directory)
  }
end