Ticket #9417: automate-xmltvid-filldefaultvalue.diff

File automate-xmltvid-filldefaultvalue.diff, 5.9 KB (added by laurent@…, 2 years ago)

Automate xmltvid filldefaultvalue.diff

  • mythtv/programs/mythfilldatabase/channeldata.cpp

    diff --git a/mythtv/programs/mythfilldatabase/channeldata.cpp b/mythtv/programs/mythfilldatabase/channeldata.cpp
    index 7ffb729..c11080f 100644
    a b  
    2525#include "channeldata.h" 
    2626#include "fillutil.h" 
    2727 
     28 
    2829static void get_atsc_stuff(QString channum, int sourceid, int freqid, 
    2930                           int &major, int &minor, long long &freq) 
    3031{ 
    unsigned int ChannelData::promptForChannelUpdates( 
    127128    return(chanid); 
    128129} 
    129130 
     131 
     132 
     133 
     134QString ChannelData::normalizeChannelKey(QString chanName) 
     135{ 
     136    QString result; 
     137    for (int i=0;i<chanName.length();i++) 
     138    { 
     139        if (chanName[i]!=32) 
     140            result+= chanName[i].toLower(); 
     141    } 
     142    return result; 
     143} 
     144 
     145QHash<QString, QString> ChannelData::channelList(int sourceId) 
     146{ 
     147    QHash<QString, QString> chanList; 
     148    MSqlQuery query(MSqlQuery::InitCon()); 
     149 
     150 
     151    query.prepare( 
     152              "SELECT name, callsign " 
     153              "FROM channel " 
     154              "WHERE sourceid = :SOURCEID"); 
     155 
     156     query.bindValue(":SOURCEID", sourceId); 
     157 
     158     if (!query.exec()) 
     159     { 
     160          MythDB::DBError("handleChannels", query); 
     161          return chanList; 
     162     } 
     163     else 
     164     { 
     165         while (query.next()) 
     166         { 
     167             QString chanName = query.value(0).toString(); 
     168             QString callSign = query.value(1).toString(); 
     169             QString key  = normalizeChannelKey(chanName); 
     170             chanList[key] = chanName; 
     171         } 
     172     } 
     173 
     174     return chanList; 
     175} 
     176 
     177bool ChannelData::findExistingChannel(int sourceId, ChanInfo chanInfo, MSqlQuery &query, QHash<QString, QString> existingChan) 
     178{ 
     179   query.prepare( 
     180          "SELECT chanid,   name, callsign, channum, " 
     181          "       finetune, icon, freqid,   tvformat " 
     182          "FROM channel " 
     183          "WHERE xmltvid  = :XMLTVID AND " 
     184          "      sourceid = :SOURCEID"); 
     185  query.bindValue(":XMLTVID",  chanInfo.xmltvid); 
     186  query.bindValue(":SOURCEID", sourceId); 
     187 
     188  if (!query.exec()) 
     189  { 
     190      MythDB::DBError("handleChannels", query); 
     191      return false; 
     192  } 
     193  else if (query.next()) 
     194  { 
     195      return true; 
     196  } 
     197 
     198  QString searchKey = normalizeChannelKey(chanInfo.name); 
     199  QString chanName = existingChan[searchKey]; 
     200 
     201  query.prepare( 
     202            "SELECT chanid,   name, callsign, channum, " 
     203            "       finetune, icon, freqid,   tvformat " 
     204            "FROM channel " 
     205            "WHERE (name  = :NAME OR" 
     206            "      callsign = :CALLSIGN) AND " 
     207            "      sourceid = :SOURCEID"); 
     208  query.bindValue(":NAME",  chanName); 
     209  query.bindValue(":CALLSIGN",  chanName); 
     210  query.bindValue(":SOURCEID", sourceId); 
     211 
     212  if (!query.exec()) 
     213  { 
     214       MythDB::DBError("handleChannels", query); 
     215       return false; 
     216  } 
     217  else if (query.next()) 
     218  { 
     219       return true; 
     220  } 
     221 
     222  return false; 
     223} 
     224 
     225 
    130226void ChannelData::handleChannels(int id, QList<ChanInfo> *chanlist) 
    131227{ 
     228//  VERBOSE(VB_IMPORTANT, QString("Failed to fetch icon from '%1'").arg((*i).iconpath)); 
     229 
     230 
     231    QHash<QString, QString> existingChan = channelList(id); 
    132232    QString fileprefix = SetupIconCacheDirectory(); 
    133233 
    134234    QDir::setCurrent(fileprefix); 
    void ChannelData::handleChannels(int id, QList<ChanInfo> *chanlist) 
    189289            } 
    190290        } 
    191291 
    192         query.prepare( 
    193             "SELECT chanid,   name, callsign, channum, " 
    194             "       finetune, icon, freqid,   tvformat " 
    195             "FROM channel " 
    196             "WHERE xmltvid  = :XMLTVID AND " 
    197             "      sourceid = :SOURCEID"); 
    198         query.bindValue(":XMLTVID",  (*i).xmltvid); 
    199         query.bindValue(":SOURCEID", id); 
    200292 
    201         if (!query.exec()) 
    202         { 
    203             MythDB::DBError("handleChannels", query); 
    204         } 
    205         else if (query.next()) 
     293        bool find = findExistingChannel(id, *i, query,existingChan); 
     294        if (find) 
    206295        { 
    207296            QString chanid = query.value(0).toString(); 
    208297            if (interactive) 
    void ChannelData::handleChannels(int id, QList<ChanInfo> *chanlist) 
    311400                    if (!subquery.exec()) 
    312401                        MythDB::DBError("Channel icon change", subquery); 
    313402                } 
     403                else 
     404                { 
     405                    if (localfile.isEmpty()) 
     406                        localfile = query.value(5).toString(); 
     407                    MSqlQuery subquery(MSqlQuery::InitCon()); 
     408 
     409                    subquery.prepare("UPDATE channel SET icon = :ICON " 
     410                            ", xmltvid:= :XMLTVID WHERE " 
     411                                     "chanid = :CHANID;"); 
     412                    subquery.bindValue(":ICON", localfile); 
     413                    subquery.bindValue(":XMLTVID", (*i).xmltvid); 
     414                    subquery.bindValue(":CHANID", chanid); 
     415 
     416                    if (!subquery.exec()) 
     417                        MythDB::DBError("Channel icon change", subquery); 
     418                } 
    314419            } 
    315420        } 
    316421        else 
    void ChannelData::handleChannels(int id, QList<ChanInfo> *chanlist) 
    319424            long long freq; 
    320425            get_atsc_stuff((*i).chanstr, id, (*i).freqid.toInt(), major, minor, freq); 
    321426 
     427 
    322428            if (interactive && ((minor == 0) || (freq > 0))) 
    323429            { 
    324430                cout << "### " << endl; 
  • mythtv/programs/mythfilldatabase/channeldata.h

    diff --git a/mythtv/programs/mythfilldatabase/channeldata.h b/mythtv/programs/mythfilldatabase/channeldata.h
    index 1de8ce0..ce25cff 100644
    a b class ChannelData 
    4444    unsigned int promptForChannelUpdates( 
    4545        QList<ChanInfo>::iterator chaninfo, unsigned int chanid); 
    4646 
     47    bool findExistingChannel(int sourceId, ChanInfo chanInfo, MSqlQuery &query,QHash<QString, QString> existingChan); 
     48    QHash<QString, QString> channelList(int sourceId); 
     49    QString normalizeChannelKey(QString chanName); 
     50 
     51 
    4752  public: 
    4853    bool    interactive; 
    4954    bool    non_us_updating;