Index: libs/libmythtv/dvbconfparser.cpp
===================================================================
--- libs/libmythtv/dvbconfparser.cpp	(revision 8859)
+++ libs/libmythtv/dvbconfparser.cpp	(working copy)
@@ -156,6 +156,8 @@
     if (i == end || !c.modulation.parseConf(*i++)) return false;
     // We need the program number in the transport stream,
     // otherwise we cannot "tune" to the program.
+    if (i == end ) return false; else i++;   // Ignore video pid
+    if (i == end ) return false; else i++;   // Ignore audio pid
     if (i != end) c.serviceid = (*i++).toInt(); else return false;
 
     channels.append(c);
@@ -349,12 +351,11 @@
     return -1;
 }
 
-int DVBConfParser::findChannel(const DVBConfParser::Channel& c)
+int DVBConfParser::findChannel(const DVBConfParser::Channel& c, int& mplexid)
 {
     MSqlQuery query(MSqlQuery::InitCon());
-    query.prepare("SELECT chanid FROM channel where mplexid=:MPLEXID AND "
+    query.prepare("SELECT chanid, mplexid FROM channel WHERE "
                   "sourceid=:SOURCEID AND callsign=:CALLSIGN;");
-    query.bindValue(":MPLEXID",multiplexes[c.mplexnumber].mplexid);
     query.bindValue(":SOURCEID",sourceid);
     query.bindValue(":CALLSIGN",c.name.utf8());
 
@@ -365,6 +366,7 @@
     if (query.size() > 0)
     {
        query.next();
+       mplexid = query.value(1).toInt();
        return query.value(0).toInt();
     }
     return -1;
@@ -446,9 +448,29 @@
        else
            multiplexes[i].mplexid = mplexid;
     }
+
+    // If the channel number cannot be determined from the config
+    // file, assign temporary unique numbers. First determine the
+    // highest channel number already assigned.
+    int maxchannum = 0;
+    query.prepare("SELECT MAX(channum) FROM channel;");
+    if (!query.exec())
+        MythContext::DBError("Getting highest channel number.", query);
+    if (!query.isActive())
+        MythContext::DBError("Getting highest channel number.", query);
+    if (query.size() > 0)
+    {
+        query.next();
+        maxchannum = query.value(0).toInt();
+    }
     for (iter=channels.begin();iter!=channels.end();iter++)
+        if ((*iter).lcn > maxchannum) maxchannum = (*iter).lcn;
+
+
+    for (iter=channels.begin();iter!=channels.end();iter++)
     {
-        int chanid = findChannel(*iter);
+        int mplexid;
+        int chanid = findChannel(*iter, mplexid);
         if (chanid < 0)
         {
             query.prepare("INSERT INTO channel (chanid, channum, "
@@ -458,7 +480,15 @@
                   ":NAME,:MPLEXID,:SERVICEID);");
 
             query.bindValue(":CHANID",generateNewChanID(sourceid));
-            query.bindValue(":CHANNUM",(*iter).lcn==-1 ? (*iter).serviceid:(*iter).lcn);
+
+            // If the channel number is unknown, generate a unique number
+            int channum;
+            if ((*iter).lcn==-1)
+                channum = ++maxchannum;
+            else
+                channum = (*iter).lcn;
+
+            query.bindValue(":CHANNUM", channum);
             query.bindValue(":SOURCEID",sourceid);
             query.bindValue(":CALLSIGN",(*iter).name.utf8());
             query.bindValue(":NAME",(*iter).name.utf8());
@@ -471,9 +501,25 @@
                 MythContext::DBError("Adding new DVB Channel", query);
             emit updateText(QObject::tr("Adding %1").arg((*iter).name));
         }
+        else if (mplexid == 32767)
+        {
+            query.prepare("UPDATE channel SET "
+                          "    mplexid = :MPLEXID, "
+                          "    serviceid = :SERVICEID "
+                          "WHERE chanid = :CHANID;");
+
+            query.bindValue(":MPLEXID", multiplexes[(*iter).mplexnumber].mplexid);
+            query.bindValue(":SERVICEID", (*iter).serviceid);
+            query.bindValue(":CHANID", chanid);
+
+            if (!query.exec())
+                MythContext::DBError("Updating DVB Channel", query);
+
+            if (!query.isActive())
+                MythContext::DBError("Updating DVB Channel", query);
+            emit updateText(QObject::tr("Updating %1").arg((*iter).name));
+        }
         else
             emit updateText(QObject::tr("Skipping %1").arg((*iter).name));
     }
 }
-
-
Index: libs/libmythtv/dvbconfparser.h
===================================================================
--- libs/libmythtv/dvbconfparser.h	(revision 8859)
+++ libs/libmythtv/dvbconfparser.h	(working copy)
@@ -113,7 +113,7 @@
     bool parseConfATSC(QStringList& tokens);
     void processChannels();
     int findMultiplex(const Multiplex& m);
-    int findChannel(const Channel& c);
+    int findChannel(const Channel& c, int& mplexid);
     int generateNewChanID(int sourceID);
 };
 
