Ticket #1203: channel-import-2.patch

File channel-import-2.patch, 4.8 KB (added by bolek-mythtv@…, 18 years ago)
  • libs/libmythtv/dvbconfparser.cpp

     
    156156    if (i == end || !c.modulation.parseConf(*i++)) return false;
    157157    // We need the program number in the transport stream,
    158158    // otherwise we cannot "tune" to the program.
     159    if (i == end ) return false; else i++;   // Ignore video pid
     160    if (i == end ) return false; else i++;   // Ignore audio pid
    159161    if (i != end) c.serviceid = (*i++).toInt(); else return false;
    160162
    161163    channels.append(c);
     
    349351    return -1;
    350352}
    351353
    352 int DVBConfParser::findChannel(const DVBConfParser::Channel& c)
     354int DVBConfParser::findChannel(const DVBConfParser::Channel& c, int& mplexid)
    353355{
    354356    MSqlQuery query(MSqlQuery::InitCon());
    355     query.prepare("SELECT chanid FROM channel where mplexid=:MPLEXID AND "
     357    query.prepare("SELECT chanid, mplexid FROM channel WHERE "
    356358                  "sourceid=:SOURCEID AND callsign=:CALLSIGN;");
    357     query.bindValue(":MPLEXID",multiplexes[c.mplexnumber].mplexid);
    358359    query.bindValue(":SOURCEID",sourceid);
    359360    query.bindValue(":CALLSIGN",c.name.utf8());
    360361
     
    365366    if (query.size() > 0)
    366367    {
    367368       query.next();
     369       mplexid = query.value(1).toInt();
    368370       return query.value(0).toInt();
    369371    }
    370372    return -1;
     
    446448       else
    447449           multiplexes[i].mplexid = mplexid;
    448450    }
     451
     452    // If the channel number cannot be determined from the config
     453    // file, assign temporary unique numbers. First determine the
     454    // highest channel number already assigned.
     455    int maxchannum = 0;
     456    query.prepare("SELECT MAX(channum) FROM channel;");
     457    if (!query.exec())
     458        MythContext::DBError("Getting highest channel number.", query);
     459    if (!query.isActive())
     460        MythContext::DBError("Getting highest channel number.", query);
     461    if (query.size() > 0)
     462    {
     463        query.next();
     464        maxchannum = query.value(0).toInt();
     465    }
     466
    449467    for (iter=channels.begin();iter!=channels.end();iter++)
    450468    {
    451         int chanid = findChannel(*iter);
     469        int mplexid;
     470        int chanid = findChannel(*iter, mplexid);
    452471        if (chanid < 0)
    453472        {
    454473            query.prepare("INSERT INTO channel (chanid, channum, "
     
    458477                  ":NAME,:MPLEXID,:SERVICEID);");
    459478
    460479            query.bindValue(":CHANID",generateNewChanID(sourceid));
    461             query.bindValue(":CHANNUM",(*iter).lcn==-1 ? (*iter).serviceid:(*iter).lcn);
     480
     481            // If the channel number is unknown, generate a unique number
     482            int channum;
     483            if ((*iter).lcn==-1)
     484                channum = ++maxchannum;
     485            else
     486            {
     487                channum = (*iter).lcn;
     488                if (channum > maxchannum) maxchannum = channum;
     489            }
     490            query.bindValue(":CHANNUM", channum);
    462491            query.bindValue(":SOURCEID",sourceid);
    463492            query.bindValue(":CALLSIGN",(*iter).name.utf8());
    464493            query.bindValue(":NAME",(*iter).name.utf8());
     
    471500                MythContext::DBError("Adding new DVB Channel", query);
    472501            emit updateText(QObject::tr("Adding %1").arg((*iter).name));
    473502        }
     503        else if (mplexid == 32767)
     504        {
     505            query.prepare("UPDATE channel SET "
     506                          "    name = :NAME, "
     507                          "    callsign = :CALLSIGN, "
     508                          "    mplexid = :MPLEXID, "
     509                          "    serviceid = :SERVICEID "
     510                          "WHERE chanid = :CHANID;");
     511
     512            query.bindValue(":CALLSIGN", (*iter).name.utf8());
     513            query.bindValue(":NAME", (*iter).name.utf8());
     514            query.bindValue(":MPLEXID", multiplexes[(*iter).mplexnumber].mplexid);
     515            query.bindValue(":SERVICEID", (*iter).serviceid);
     516            query.bindValue(":CHANID", chanid);
     517
     518            if (!query.exec())
     519                MythContext::DBError("Updating DVB Channel", query);
     520
     521            if (!query.isActive())
     522                MythContext::DBError("Updating DVB Channel", query);
     523            emit updateText(QObject::tr("Updating %1").arg((*iter).name));
     524        }
    474525        else
    475526            emit updateText(QObject::tr("Skipping %1").arg((*iter).name));
    476527    }
  • libs/libmythtv/dvbconfparser.h

     
    113113    bool parseConfATSC(QStringList& tokens);
    114114    void processChannels();
    115115    int findMultiplex(const Multiplex& m);
    116     int findChannel(const Channel& c);
     116    int findChannel(const Channel& c, int& mplexid);
    117117    int generateNewChanID(int sourceID);
    118118};
    119119