Ticket #1203: channel-import-2.patch
File channel-import-2.patch, 4.8 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 } 466 449 467 for (iter=channels.begin();iter!=channels.end();iter++) 450 468 { 451 int chanid = findChannel(*iter); 469 int mplexid; 470 int chanid = findChannel(*iter, mplexid); 452 471 if (chanid < 0) 453 472 { 454 473 query.prepare("INSERT INTO channel (chanid, channum, " … … 458 477 ":NAME,:MPLEXID,:SERVICEID);"); 459 478 460 479 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); 462 491 query.bindValue(":SOURCEID",sourceid); 463 492 query.bindValue(":CALLSIGN",(*iter).name.utf8()); 464 493 query.bindValue(":NAME",(*iter).name.utf8()); … … 471 500 MythContext::DBError("Adding new DVB Channel", query); 472 501 emit updateText(QObject::tr("Adding %1").arg((*iter).name)); 473 502 } 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 } 474 525 else 475 526 emit updateText(QObject::tr("Skipping %1").arg((*iter).name)); 476 527 } -
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