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.



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

def initialize()
	@recordings_db = Hash.new
end

Instance Method Details

#add(directory) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/recordings.rb', line 48

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 if (Time.now - File.mtime(directory + '/index')) > 30
	@recordings_db[directory] = Recording.new(directory)
	@recordings_db[directory].process!
end

#delete(recording) ⇒ Object



56
57
58
# File 'lib/recordings.rb', line 56

def delete(recording)
	# TODO: Delete the recording
end

#dumpObject



36
37
38
39
40
# File 'lib/recordings.rb', line 36

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

#loadObject



41
42
43
44
45
46
47
# File 'lib/recordings.rb', line 41

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

#scanObject



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

def scan()
	basedir = '/var/vdr/video'
	found_directories = Array.new
	Find.find(basedir) { | entry |
 entry.force_encoding('BINARY')
 # Guess encoding of filename
 cd = CharDet.detect(entry)
 encoding = cd['encoding']
 #p encoding
 entry.force_encoding(encoding)
 # Look for the index file created by VDR
 if File.basename(entry) == "index" then
directory = File.dirname(entry)
found_directories << directory
if @recordings_db[directory] == nil then
  # Found a new entry
  p directory
  add(directory)
end
 end
	}
	@recordings_db.each { | recording |
 recording.delete! unless found_directories.include?(recording.directory)
	}
end