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
- #process! ⇒ Object
- #update_target_dir ⇒ 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 |
# 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
#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
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_type ⇒ Object
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_info ⇒ Object
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_dir ⇒ Object
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 |