Ticket #1203: channel-import-3.patch

File channel-import-3.patch, 4.6 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    }
    449466    for (iter=channels.begin();iter!=channels.end();iter++)
     467        if ((*iter).lcn > maxchannum) maxchannum = (*iter).lcn;
     468
     469
     470    for (iter=channels.begin();iter!=channels.end();iter++)
    450471    {
    451         int chanid = findChannel(*iter);
     472        int mplexid;
     473        int chanid = findChannel(*iter, mplexid);
    452474        if (chanid < 0)
    453475        {
    454476            query.prepare("INSERT INTO channel (chanid, channum, "
     
    458480                  ":NAME,:MPLEXID,:SERVICEID);");
    459481
    460482            query.bindValue(":CHANID",generateNewChanID(sourceid));
    461             query.bindValue(":CHANNUM",(*iter).lcn==-1 ? (*iter).serviceid:(*iter).lcn);
     483
     484            // If the channel number is unknown, generate a unique number
     485            int channum;
     486            if ((*iter).lcn==-1)
     487                channum = ++maxchannum;
     488            else
     489                channum = (*iter).lcn;
     490
     491            query.bindValue(":CHANNUM", channum);
    462492            query.bindValue(":SOURCEID",sourceid);
    463493            query.bindValue(":CALLSIGN",(*iter).name.utf8());
    464494            query.bindValue(":NAME",(*iter).name.utf8());
     
    471501                MythContext::DBError("Adding new DVB Channel", query);
    472502            emit updateText(QObject::tr("Adding %1").arg((*iter).name));
    473503        }
     504        else if (mplexid == 32767)
     505        {
     506            query.prepare("UPDATE channel SET "
     507                          "    mplexid = :MPLEXID, "
     508                          "    serviceid = :SERVICEID "
     509                          "WHERE chanid = :CHANID;");
     510
     511            query.bindValue(":MPLEXID", multiplexes[(*iter).mplexnumber].mplexid);
     512            query.bindValue(":SERVICEID", (*iter).serviceid);
     513            query.bindValue(":CHANID", chanid);
     514
     515            if (!query.exec())
     516                MythContext::DBError("Updating DVB Channel", query);
     517
     518            if (!query.isActive())
     519                MythContext::DBError("Updating DVB Channel", query);
     520            emit updateText(QObject::tr("Updating %1").arg((*iter).name));
     521        }
    474522        else
    475523            emit updateText(QObject::tr("Skipping %1").arg((*iter).name));
    476524    }
    477525}
    478 
    479 
  • 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