lib/simple_pvr/scheduler.rb in simple_pvr-1.0.0 vs lib/simple_pvr/scheduler.rb in simple_pvr-1.1.0
- old
+ new
@@ -2,11 +2,13 @@
class Scheduler
attr_reader :upcoming_recordings
def initialize
@number_of_tuners = 2
- @upcoming_recordings, @current_recordings, @recorders = [], [nil] * @number_of_tuners, {}
+ @current_recordings = [nil] * @number_of_tuners
+ @recorders = {}
+ @upcoming_recordings = []
@mutex = Mutex.new
end
def start
@thread = Thread.new do
@@ -14,11 +16,11 @@
@mutex.synchronize { process }
sleep 1
end
end
end
-
+
def recordings=(recordings)
@mutex.synchronize do
@upcoming_recordings = recordings.sort_by {|r| r.start_time }.find_all {|r| !r.expired? }
@scheduled_programmes = programme_ids_from(@upcoming_recordings)
@@ -80,11 +82,17 @@
def remove_current_recordings(recordings)
recordings.find_all {|recording| !@current_recordings.include?(recording) }
end
def stop_current_recordings_not_relevant_anymore
- @current_recordings.each do |recording|
- stop_recording(recording) if recording && !@upcoming_recordings.include?(recording)
+ @current_recordings.find_all {|r| r != nil }.each do |recording|
+ similar_recording = @upcoming_recordings.find {|r| recording.similar_to(r) }
+ if similar_recording
+ # It's (probably) the same show, so we continue recording and update with new information
+ similar_recording.update_with(recording)
+ else
+ stop_recording(recording)
+ end
end
end
def check_expiration_of_current_recordings
@current_recordings.each do |recording|
\ No newline at end of file