Class: Recording
- Inherits:
-
Object
- Object
- Recording
- Defined in:
- lib/recording.rb
Instance Attribute Summary collapse
-
#directory ⇒ Object
readonly
Returns the value of attribute directory.
-
#friendly_name ⇒ Object
readonly
Returns the value of attribute friendly_name.
-
#processed ⇒ Object
readonly
Returns the value of attribute processed.
-
#target_dir ⇒ Object
readonly
Returns the value of attribute target_dir.
Instance Method Summary collapse
- #delete! ⇒ Object
- #determine_stream_type ⇒ Object
-
#initialize(directory) ⇒ Recording
constructor
A new instance of Recording.
- #load_info ⇒ Object
- #marshal_dump ⇒ Object
- #marshal_load(variables) ⇒ Object
- #process! ⇒ Object
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 23 |
# File 'lib/recording.rb', line 9 def initialize(directory) @mutex = Mutex.new @directory = directory @recording = nil @title = nil @subtitle = nil @friendly_name = nil @recording_time = nil @target_dir = nil @processed = false @timestamp = File.mtime(@directory + '/index') load_info determine_stream_type puts "New recording: #{@friendly_name}" end |
Instance Attribute Details
#directory ⇒ Object (readonly)
Returns the value of attribute directory.
8 9 10 |
# File 'lib/recording.rb', line 8 def directory @directory end |
#friendly_name ⇒ Object (readonly)
Returns the value of attribute friendly_name.
8 9 10 |
# File 'lib/recording.rb', line 8 def friendly_name @friendly_name end |
#processed ⇒ Object (readonly)
Returns the value of attribute processed.
8 9 10 |
# File 'lib/recording.rb', line 8 def processed @processed end |
#target_dir ⇒ Object (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
38 39 40 41 42 43 44 |
# File 'lib/recording.rb', line 38 def delete!() @mutex.synchronize { @recording.delete! if @recording @recording = nil GC.start } end |
#determine_stream_type ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/recording.rb', line 70 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_info ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/recording.rb', line 45 def load_info() begin info = File.read(@directory + '/info') rescue return end info.each_line { | line | case line[0..1] when 'T ' @title = line[2..256].chomp when 'S ' @subtitle = line[2..256].chomp when 'E ' @recording_time = Time.at(line.split[2].to_i) end } @title = 'Unknown' if not @title @subtitle = 'Unknown' if not @subtitle title = @title subtitle = @subtitle title.gsub!('/', '!') subtitle.gsub!('/', '!') @target_dir = "/video/#{title}/#{subtitle}" @friendly_name = "#{@recording_time.strftime("%y%m%d-%H%M")} - #{title}" end |
#marshal_dump ⇒ Object
24 25 26 |
# File 'lib/recording.rb', line 24 def marshal_dump() [ @directory, @recording, @title, @subtitle, @friendly_name, @target_dir, @processed, @timestamp, @recording_time ] end |
#marshal_load(variables) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/recording.rb', line 27 def marshal_load(variables) @mutex = Mutex.new @directory = variables[0] @recording = variables[1] @friendly_name = variables[4] @target_dir = variables[5] @processed = variables[6] @timestamp = variables[7] load_info end |
#process! ⇒ Object
80 81 82 83 84 85 |
# File 'lib/recording.rb', line 80 def process!() puts "Processing of #{@friendly_name} started..." @mutex.synchronize{ @processed = true if @recording.process! } end |