Ticket #1203: channel-import-3.patch
File channel-import-3.patch, 4.6 KB (added by , 18 years ago) |
---|
-
libs/libmythtv/dvbconfparser.cpp
156 156 if (i == end || !c.modulation.parseConf(*i++)) return false; 157 157 // We need the program number in the transport stream, 158 158 // 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 159 161 if (i != end) c.serviceid = (*i++).toInt(); else return false; 160 162 161 163 channels.append(c); … … 349 351 return -1; 350 352 } 351 353 352 int DVBConfParser::findChannel(const DVBConfParser::Channel& c )354 int DVBConfParser::findChannel(const DVBConfParser::Channel& c, int& mplexid) 353 355 { 354 356 MSqlQuery query(MSqlQuery::InitCon()); 355 query.prepare("SELECT chanid FROM channel where mplexid=:MPLEXID AND"357 query.prepare("SELECT chanid, mplexid FROM channel WHERE " 356 358 "sourceid=:SOURCEID AND callsign=:CALLSIGN;"); 357 query.bindValue(":MPLEXID",multiplexes[c.mplexnumber].mplexid);358 359 query.bindValue(":SOURCEID",sourceid); 359 360 query.bindValue(":CALLSIGN",c.name.utf8()); 360 361 … … 365 366 if (query.size() > 0) 366 367 { 367 368 query.next(); 369 mplexid = query.value(1).toInt(); 368 370 return query.value(0).toInt(); 369 371 } 370 372 return -1; … … 446 448 else 447 449 multiplexes[i].mplexid = mplexid; 448 450 } 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 } 449 466 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++) 450 471 { 451 int chanid = findChannel(*iter); 472 int mplexid; 473 int chanid = findChannel(*iter, mplexid); 452 474 if (chanid < 0) 453 475 { 454 476 query.prepare("INSERT INTO channel (chanid, channum, " … … 458 480 ":NAME,:MPLEXID,:SERVICEID);"); 459 481 460 482 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); 462 492 query.bindValue(":SOURCEID",sourceid); 463 493 query.bindValue(":CALLSIGN",(*iter).name.utf8()); 464 494 query.bindValue(":NAME",(*iter).name.utf8()); … … 471 501 MythContext::DBError("Adding new DVB Channel", query); 472 502 emit updateText(QObject::tr("Adding %1").arg((*iter).name)); 473 503 } 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 } 474 522 else 475 523 emit updateText(QObject::tr("Skipping %1").arg((*iter).name)); 476 524 } 477 525 } 478 479 -
libs/libmythtv/dvbconfparser.h
113 113 bool parseConfATSC(QStringList& tokens); 114 114 void processChannels(); 115 115 int findMultiplex(const Multiplex& m); 116 int findChannel(const Channel& c );116 int findChannel(const Channel& c, int& mplexid); 117 117 int generateNewChanID(int sourceID); 118 118 }; 119 119