Index: scheduler.h
===================================================================
--- scheduler.h	(revision 14616)
+++ scheduler.h	(working copy)
@@ -102,11 +102,13 @@
 
     bool IsSameProgram(const ProgramInfo *a, const ProgramInfo *b) const;
 
-    bool FindNextConflict(const RecList &cardlist,
+    int  FindNextConflict(const RecList &cardlist,
                           const ProgramInfo *p, RecConstIter &iter,
                           bool openEnd = false) const;
-    const ProgramInfo *FindConflict(const QMap<int, RecList> &reclists,
-                                    const ProgramInfo *p, bool openEnd = false) const;
+    const ProgramInfo *FindConflict(
+        const QMap<int, RecList> &reclists, const ProgramInfo *p,
+        bool openEnd = false, int *preference = NULL) const;
+
     void MarkOtherShowings(ProgramInfo *p);
     void MarkShowingsList(RecList &showinglist, ProgramInfo *p);
     void BackupRecStatus(void);
Index: scheduler.cpp
===================================================================
--- scheduler.cpp	(revision 14617)
+++ scheduler.cpp	(working copy)
@@ -278,6 +278,9 @@
             return a->recstartts < b->recstartts;
     }
 
+    if (a->title != b->title)
+	return a->title < b->title;
+
     if (a->inputid != b->inputid)
         return a->inputid < b->inputid;
 
@@ -793,12 +796,13 @@
     return cache_is_same_program[X] = a->IsSameProgram(*b);
 }
 
-bool Scheduler::FindNextConflict(
+int Scheduler::FindNextConflict(
     const RecList     &cardlist,
     const ProgramInfo *p,
     RecConstIter      &j,
     bool               openEnd) const
 {
+    bool found_ideal = false;
     bool is_conflict_dbg = false;
 
     for ( ; j != cardlist.end(); j++)
@@ -855,25 +859,27 @@
             GetSharedInputGroup(p->inputid, q->inputid) &&
             p->GetMplexID() && (p->GetMplexID() == q->GetMplexID()))
         {
+	    found_ideal = true;
             continue;
         }
 
         if (is_conflict_dbg)
             cout << "\n  Found conflict" << endl;
 
-        return true;
+        return -1;
     }
 
     if (is_conflict_dbg)
         cout << "\n  No conflict" << endl;
 
-    return false;
+    // Actually... give multiplex/inputgroup overlaps a priority.
+    return (found_ideal) ? 1 : 0;
 }
 
 const ProgramInfo *Scheduler::FindConflict(
     const QMap<int, RecList> &reclists,
     const ProgramInfo        *p,
-    bool openend) const
+    bool openend, int *preference) const
 {
     bool is_conflict_dbg = false;
 
@@ -888,10 +894,13 @@
 
         const RecList &cardlist = *it;
         RecConstIter k = cardlist.begin();
-        if (FindNextConflict(cardlist, p, k, openend))
-        {
+        int result = FindNextConflict(cardlist, p, k, openend);
+        if (result < 0)
             return *k;
-        }
+
+        // The more group overlaps the better.
+        if (preference)
+            *preference += result;
     }
 
     return NULL;
@@ -1067,6 +1076,9 @@
 
     bool openEnd = (bool)gContext->GetNumSetting("SchedOpenEnd", 0);
 
+    int bestpreference = -1;
+    ProgramInfo *best_program = NULL;
+
     RecIter i = worklist.begin();
     while (i != worklist.end())
     {
@@ -1075,9 +1087,40 @@
             MarkOtherShowings(p);
         else if (p->recstatus == rsUnknown)
         {
-            const ProgramInfo *conflict = FindConflict(cardlistmap, p, openEnd);
+            int preference = 0;
+            const ProgramInfo *conflict = FindConflict(
+                cardlistmap, p, openEnd, &preference);
             if (!conflict)
             {
+                // Decide if this is the best choice,
+                // but don't set it stone yet.
+                if (preference > bestpreference)
+                {
+                    bestpreference = preference;
+                    best_program = p;
+                }
+            }
+            else
+            {
+                retrylist.push_front(p);
+                PrintRec(p, "  #");
+                PrintRec(conflict, "     !");
+            }
+        }
+
+        int lastpri = p->recpriority;
+        QDateTime lastrecstart = p->recstartts;
+        const QString &lastchanid = p->chanid;
+        i++;
+
+        // If we've moved on to a different program, or the end,
+        // save the best showing. 
+        if (i == worklist.end() || lastrecstart != (*i)->recstartts ||
+            lastchanid != (*i)->chanid)
+        {
+            p = best_program;
+            if (bestpreference > -1)
+            {
                 p->recstatus = rsWillRecord;
 
                 if (p->recstartts < schedTime.addSecs(90))
@@ -1093,16 +1136,9 @@
                 MarkOtherShowings(p);
                 PrintRec(p, "  +");
             }
-            else
-            {
-                retrylist.push_front(p);
-                PrintRec(p, "  #");
-                PrintRec(conflict, "     !");
-            }
+            bestpreference = -1;
         }
 
-        int lastpri = p->recpriority;
-        i++;
         if (i == worklist.end() || lastpri != (*i)->recpriority)
         {
             MoveHigherRecords();
