Index: scheduler.h
===================================================================
--- scheduler.h	(revision 14392)
+++ scheduler.h	(working copy)
@@ -87,10 +87,12 @@
     void PruneOverlaps(void);
     void BuildListMaps(void);
     void ClearListMaps(void);
-    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, int *preference) const;
+    const ProgramInfo *FindConflict(const QMap<int, RecList> &reclists,
                                     const ProgramInfo *p, bool openEnd = false) const;
     void MarkOtherShowings(ProgramInfo *p);
     void MarkShowingsList(RecList &showinglist, ProgramInfo *p);
Index: scheduler.cpp
===================================================================
--- scheduler.cpp	(revision 14392)
+++ scheduler.cpp	(working copy)
@@ -278,6 +278,11 @@
             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;
 
@@ -751,12 +756,14 @@
     recordidlistmap.clear();
 }
 
-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++)
@@ -813,19 +820,26 @@
             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.
+    if(found_ideal)
+    {
+        return 1;
+    }else{
+    	return 0;
+    }
 }
 
 const ProgramInfo *Scheduler::FindConflict(
@@ -833,6 +847,15 @@
     const ProgramInfo        *p,
     bool openend) const
 {
+    int preference = 0;
+    return FindConflict(reclists, p, openend, &preference);
+}
+
+const ProgramInfo *Scheduler::FindConflict(
+    const QMap<int, RecList> &reclists,
+    const ProgramInfo        *p,
+    bool openend, int *preference) const
+{
     bool is_conflict_dbg = false;
 
     QMap<int, RecList>::const_iterator it = reclists.begin();
@@ -846,10 +869,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.
+	*preference += result;
     }
 
     return NULL;
@@ -1050,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())
     {
@@ -1058,9 +1087,38 @@
             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)
             {
+		cout << QString(" No conflict, preference %2 ").arg(preference);
+                // 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 char* 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))
@@ -1081,16 +1139,10 @@
                 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();
