From 763d455aa39cf06d8b563e7b486dab0ea36fd6df Mon Sep 17 00:00:00 2001 From: jrlambs Date: Fri, 7 Apr 2017 23:55:50 -0400 Subject: [PATCH] Fix some bugs in the creation of the start/stop timers --- .../com/moparisthebest/rcrdit/RcrdIt.java | 34 +++++++++++++++---- .../rcrdit/scheduler/PartialScheduler.java | 28 +++++++-------- 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/moparisthebest/rcrdit/RcrdIt.java b/src/main/java/com/moparisthebest/rcrdit/RcrdIt.java index 7639275..2083f3f 100644 --- a/src/main/java/com/moparisthebest/rcrdit/RcrdIt.java +++ b/src/main/java/com/moparisthebest/rcrdit/RcrdIt.java @@ -34,6 +34,7 @@ import com.moparisthebest.rcrdit.tuner.Tuners; import com.moparisthebest.rcrdit.xmltv.Channel; import com.moparisthebest.rcrdit.xmltv.Program; import com.moparisthebest.rcrdit.xmltv.Tv; +import jersey.repackaged.com.google.common.collect.Lists; import net.fortuna.ical4j.data.CalendarOutputter; import net.fortuna.ical4j.model.Calendar; import net.fortuna.ical4j.model.DateTime; @@ -85,7 +86,7 @@ import org.glassfish.jersey.jackson.JacksonFeature; public class RcrdIt extends ResourceConfig implements AutoCloseable { // for testing, should be null normally - private static final LocalDateTime fakeTime = null;//LocalDateTime.of(2017, 3, 11, 0, 0); + private static final LocalDateTime fakeTime = LocalDateTime.of(2017, 4, 6, 22, 31); private static final Logger log = LoggerFactory.getLogger(RcrdIt.class); @@ -426,7 +427,9 @@ public class RcrdIt extends ResourceConfig implements AutoCloseable { final Program program = schedule.getPrograms().get(x); if(program.getAutoRec() != null) { // wanted to record + final List startStops = program.getStartStops(); + if(startStops.isEmpty()) { // whole thing skipped... addMeeting(calendar, tz, program.getStart(), program.getStop(), program, md, true); @@ -441,16 +444,23 @@ public class RcrdIt extends ResourceConfig implements AutoCloseable { final StartStop second = startStops.get(++index); if(startStops.size() == 2 && first.getInstant().equals(program.getStart()) && second.getInstant().equals(program.getStop())) { // whole thing recorded... + Program toStop = first.getToStop(); addMeeting(calendar, tz, program.getStart(), program.getStop(), program, md, false); - final RecordingTask rt = new RecordingTask(program, program.getStart()); + RecordingTask rt = null; + if(toStop != null){ + rt = new RecordingTask(toStop, program, program.getStart()); + }else { + rt = new RecordingTask(program, program.getStart()); + } startTimers.add(rt); continue; } if(first.isStart()) { - if(first.getInstant().equals(program.getStart())) { + //Travis, uncomment me if I'm still needed + //if(first.getInstant().equals(program.getStart())) { // not started at start time, skipped first part of program - addMeeting(calendar, tz, program.getStart(), first.getInstant(), program, md, true); - } + //addMeeting(calendar, tz, program.getStart(), first.getInstant(), program, md, true); + //} Program toStop = null; Instant start = null, stop = null, lastStop = null; for(final StartStop ss : program.getStartStops()) { @@ -473,6 +483,17 @@ public class RcrdIt extends ResourceConfig implements AutoCloseable { start = stop = null; } } + + if(lastStop != null) { // todo: check if lastStop and start are the same, but shouldn't happen? + addMeeting(calendar, tz, lastStop, start, program, md, true); + } + if(start != null && stop != null) { + addMeeting(calendar, tz, start, stop, program, md, false); + + final RecordingTask rt = new RecordingTask(toStop, program, start); + startTimers.add(rt); + } + } else { log.error("holy shit should never happen, bad scheduler?"); throw new RuntimeException("holy shit should never happen, bad scheduler?"); @@ -483,7 +504,8 @@ public class RcrdIt extends ResourceConfig implements AutoCloseable { log.debug("new import done.\n\n------\n\n"); try (FileOutputStream fout = new FileOutputStream("startTimers.txt")) { - for(TimerTask tt : startTimers) { + List tmpTimers = Lists.reverse(startTimers); + for(TimerTask tt : tmpTimers) { fout.write(tt.toString().getBytes(UTF_8)); fout.write('\n'); } diff --git a/src/main/java/com/moparisthebest/rcrdit/scheduler/PartialScheduler.java b/src/main/java/com/moparisthebest/rcrdit/scheduler/PartialScheduler.java index 8d85c59..7ed598d 100644 --- a/src/main/java/com/moparisthebest/rcrdit/scheduler/PartialScheduler.java +++ b/src/main/java/com/moparisthebest/rcrdit/scheduler/PartialScheduler.java @@ -64,24 +64,24 @@ public class PartialScheduler implements Scheduler { } } // schedule top 2 (numTuners), record stuff about rest, schedule only if not already recording ouch? + + // it already ended, and stopped itself, just remove it, for both currentRecs and skippedRecs + //recs.keySet().removeIf(c -> c.getProgram().getStop().isBefore(finalCursor)); + for (final Iterator> it = currentRecs.entrySet().iterator(); it.hasNext(); ) { + final Map.Entry entry = it.next(); + final Program prog = entry.getKey(); + if (!prog.getStop().isAfter(cursor)) { + //if(prog.getStop().isBefore(finalCursor)) { + final Instant start = entry.getValue(); + prog.addStartStop(new StartStop(prog.getStop(), false)); + it.remove(); + } + } + if (!programAutoRecs.isEmpty()) { programAutoRecs.sort(Program::compareTo); - // start and stop are same minute and second final Instant finalCursor = cursor; - // it already ended, and stopped itself, just remove it, for both currentRecs and skippedRecs - //recs.keySet().removeIf(c -> c.getProgram().getStop().isBefore(finalCursor)); - for (final Iterator> it = currentRecs.entrySet().iterator(); it.hasNext(); ) { - final Map.Entry entry = it.next(); - final Program prog = entry.getKey(); - if (!prog.getStop().isAfter(finalCursor)) { - //if(prog.getStop().isBefore(finalCursor)) { - final Instant start = entry.getValue(); - prog.addStartStop(new StartStop(prog.getStop(), false)); - it.remove(); - } - } - // look at highest programAutoRecs up to the number of tuners for (int x = 0; x < Math.min(programAutoRecs.size(), numTuners); ++x) { final Program programAutoRec = programAutoRecs.get(x);