Class: Recording

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory) ⇒ Recording

Returns a new instance of Recording.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/recording.rb', line 9

def initialize(directory)
	@mutex = Mutex.new
	@directory = directory
	@recording = nil
	@title = nil
	@subtitle = nil
	@friendly_name = nil
	@target_dir = nil
	@processed = false
	@timestamp = File.mtime(@directory + '/index')
	load_info
	update_target_dir
	determine_stream_type
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



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

def directory
  @directory
end

#friendly_nameObject (readonly)

Returns the value of attribute friendly_name.



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

def friendly_name
  @friendly_name
end

#processedObject (readonly)

Returns the value of attribute processed.



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

def processed
  @processed
end

#target_dirObject (readonly)

Returns the value of attribute target_dir.



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

def target_dir
  @target_dir
end

Instance Method Details

#delete!Object



23
24
25
26
27
28
29
# File 'lib/recording.rb', line 23

def delete!()
	@mutex.synchronize {
 @recording = nil
 GC.start
 FileDir.delete!(@target_dir)
	}
end

#determine_stream_typeObject



53
54
55
56
57
58
59
60
61
62
# File 'lib/recording.rb', line 53

def determine_stream_type()
	case
 when File.file?(@directory + '/00001.ts')
@recording = RecordingTS.new(self)
 when File.file?(@directory + '/00001.vdr')
@recording = RecordingVDR.new(self)
 else
raise 'Unknown recording'
	end
end

#load_infoObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/recording.rb', line 30

def load_info()
	#begin
 info = File.read(@directory + '/info')
 info.force_encoding('BINARY')
 cd = CharDet.detect(info)
 encoding = cd['encoding']
 info.each_line { | line |
case line[0..1]
  when 'T '
	@title = line[2..256].chomp
	@title.force_encoding(encoding)
	p "Found title: #{@title}"
  when 'S '
	@subtitle = line[2..256].chomp
	@subtitle.force_encoding(encoding)
	p "Found subtitle: #{@subtitle}"
end
 }
	#rescue
	#end
	@title = 'Unknown' if not @title
	@subtitle = 'Unknown' if not @subtitle
end

#process!Object



71
72
73
74
75
# File 'lib/recording.rb', line 71

def process!()
	@mutex.synchronize{
 @processed = true if @recording.process!
	}
end

#update_target_dirObject



63
64
65
66
67
68
69
70
# File 'lib/recording.rb', line 63

def update_target_dir()
	title = @title
	subtitle = @subtitle
	title.gsub!('/', '!')
	subtitle.gsub!('/', '!')
	@target_dir = "/video/#{title}/#{subtitle}"
	@friendly_name = "#{title} - #{subtitle}"	
end