Index: sourceutil.h
===================================================================
--- sourceutil.h	(revision 10276)
+++ sourceutil.h	(working copy)
@@ -16,6 +16,7 @@
                                         QString &passwd,  QString &lineupid);
     static bool    IsAnalog(uint sourceid);
     static bool    UpdateChannelsFromListings(uint sourceid);
+    static QString GetLineupType(uint sourceid);
 };
 
 #endif //_SOURCEUTIL_H_
Index: sourceutil.cpp
===================================================================
--- sourceutil.cpp	(revision 10276)
+++ sourceutil.cpp	(working copy)
@@ -3,10 +3,13 @@
 // Qt headers
 #include <qregexp.h>
 
+#include <map>
+
 // MythTV headers
 #include "sourceutil.h"
 #include "mythdbcon.h"
 #include "util.h"
+#include "mythcontext.h"
 
 QString SourceUtil::GetChannelSeparator(uint sourceid)
 {
@@ -118,3 +121,40 @@
                         "--sourceid %1").arg(sourceid));
     return true;
 }
+
+/// Returns the lineup type given a source ID.
+/// \param [in] sourceid The lineup source ID.
+/// \returns A string with the TMSDataDirect lineup type or "Unknown"
+/// \remarks This function relies on temporary tables which are only valid
+///          when mythfilldatabase is processing a lineup.
+QString SourceUtil::GetLineupType(uint sourceid)
+{
+    typedef std::map<uint, QString> smap;
+    static smap sid_cache;
+
+    smap::iterator p = sid_cache.find(sourceid);
+    if (p != sid_cache.end())
+    {
+        return p->second;
+    }
+
+    MSqlQuery query(MSqlQuery::DDCon());
+    query.prepare(
+        "SELECT `type` FROM dd_lineup "
+        "LEFT JOIN videosource ON dd_lineup.lineupid = videosource.lineupid "
+        "WHERE sourceid = :SOURCEID;");
+    query.bindValue(":SOURCEID", sourceid);
+
+    if (query.exec() && query.next())
+    {
+        QString type(query.value(0).toString());
+        sid_cache.insert(smap::value_type(sourceid, type));
+        return type;
+    }
+    else
+    {
+        VERBOSE(VB_IMPORTANT, QString("Error: Source ID has no lineup type."));
+    }
+
+    return "Unknown";
+}
Index: datadirect.cpp
===================================================================
--- datadirect.cpp	(revision 10276)
+++ datadirect.cpp	(working copy)
@@ -31,7 +31,7 @@
 static void    get_atsc_stuff(QString channum, int sourceid, int freqid,
                               int &major, int &minor, long long &freq);
 static uint    create_atscsrcid(QString chan_major, QString chan_minor);
-static QString process_dd_station(uint sourceid,
+static QString process_dd_station(uint sourceid, QString lineup_type,
                                   QString  chan_major, QString  chan_minor,
                                   QString &tvformat,   uint    &freqid,
                                   uint    &atscsrcid);
@@ -675,6 +675,8 @@
     if (dd_station_info.size() == 0)
         return true;
 
+    QString lineup_type = SourceUtil::GetLineupType(sourceid);
+
     MSqlQuery chan_update_q(MSqlQuery::DDCon());
     chan_update_q.prepare(
         "UPDATE channel "
@@ -691,7 +693,8 @@
         QString chan_minor = dd_station_info.value(5).toString();
         QString tvformat   = QString::null;
         QString channum    = process_dd_station(
-            sourceid, chan_major, chan_minor, tvformat, freqid, atscsrcid);
+            sourceid, lineup_type, chan_major, chan_minor, tvformat, freqid,
+            atscsrcid);
 
         chan_update_q.bindValue(":CALLSIGN",  dd_station_info.value(0));
         chan_update_q.bindValue(":NAME",      dd_station_info.value(1));
@@ -1759,11 +1762,11 @@
 static uint create_atscsrcid(QString chan_major, QString chan_minor)
 {
     bool ok;
-    uint major = chan_major.toUInt(&ok), atscsrcid = 0;
+    uint atscsrcid = chan_major.toUInt(&ok);
     if (!ok)
-        return atscsrcid;
+        return 0;
 
-    atscsrcid = major << 8;
+    atscsrcid <<= 8;
     if (chan_minor.isEmpty())
         return atscsrcid;
 
@@ -1771,7 +1774,7 @@
 }
 
 static QString process_dd_station(
-    uint sourceid, QString chan_major, QString chan_minor,
+    uint sourceid, QString lineup_type, QString chan_major, QString chan_minor,
     QString &tvformat, uint &freqid, uint &atscsrcid)
 {
     QString channum = chan_major;
@@ -1781,11 +1784,19 @@
     if (atscsrcid & 0xff)
     {
         tvformat = "atsc";
-        channum += SourceUtil::GetChannelSeparator(sourceid) + chan_minor;
+        channum += "_" + chan_minor;
     }
 
-    if (!freqid && !(atscsrcid & 0xff))
-        freqid = chan_major.toInt();
+    if (lineup_type == "LocalBroadcast")
+    {
+        if (!freqid && !(atscsrcid & 0xff))
+            freqid = chan_major.toInt();
+    }
+    else
+    {
+        // lose the freqid lest someone be fool enough to use it
+        freqid = channum.toInt();
+    }
 
     return channum;
 }
@@ -1800,7 +1811,8 @@
     uint atscsrcid;
     QString tvformat;
     QString channum = process_dd_station(
-        sourceid, chan_major, chan_minor, tvformat, freqid, atscsrcid);
+        sourceid, SourceUtil::GetLineupType(sourceid), chan_major, chan_minor,
+        tvformat, freqid, atscsrcid);
 
     // First check if channel already in DB, but without xmltvid
     MSqlQuery query(MSqlQuery::DDCon());
