bool XMLTVParser::parseFile( QString filename, QList<ChanInfo> *chanlist, QMap<QString, QList<ProgInfo> > *proglist) { QDomDocument doc; QFile f; if (!dash_open(f, filename, QIODevice::ReadOnly)) { VERBOSE(VB_IMPORTANT, QString("Error unable to open '%1' for reading.") .arg(filename)); return false; } QString errorMsg = "unknown"; int errorLine = 0; int errorColumn = 0; if (!doc.setContent(&f, &errorMsg, &errorLine, &errorColumn)) { VERBOSE(VB_IMPORTANT, QString("Error in %1:%2: %3") .arg(errorLine).arg(errorColumn).arg(errorMsg)); f.close(); return true; } f.close(); // now we calculate the localTimezoneOffset, so that we can fix // the programdata if needed QString config_offset = gCoreContext->GetSetting("TimeOffset", "None"); // we disable this feature by setting it invalid (> 840min = 14hr) int localTimezoneOffset = 841; if (config_offset == "Auto") { // we mark auto with the -ve of the disable magic number localTimezoneOffset = -841; } else if (config_offset != "None") { localTimezoneOffset = TimezoneToInt(config_offset); if (abs(localTimezoneOffset) > 840) { VERBOSE(VB_XMLTV, QString("Ignoring invalid TimeOffset %1") .arg(config_offset)); localTimezoneOffset = 841; } } QDomElement docElem = doc.documentElement(); QUrl baseUrl(docElem.attribute("source-data-url", "")); QUrl sourceUrl(docElem.attribute("source-info-url", "")); if (sourceUrl.toString() == "http://labs.zap2it.com/") { VERBOSE(VB_IMPORTANT, "Don't use tv_grab_na_dd, use the" "internal datadirect grabber."); exit(GENERIC_EXIT_SETUP_ERROR); } QString aggregatedTitle; QString aggregatedDesc; QString groupingTitle; QString groupingDesc; QDomNode n = docElem.firstChild(); while (!n.isNull()) { QDomElement e = n.toElement(); if (!e.isNull()) { if (e.tagName() == "channel") { ChanInfo *chinfo = parseChannel(e, baseUrl); chanlist->push_back(*chinfo); delete chinfo; } else if (e.tagName() == "programme") { ProgInfo *pginfo = parseProgram(e, localTimezoneOffset); if (pginfo->startts == pginfo->endts) { /* Not a real program : just a grouping marker */ if (!pginfo->title.isEmpty()) groupingTitle = pginfo->title + " : "; if (!pginfo->description.isEmpty()) groupingDesc = pginfo->description + " : "; } else { if (pginfo->clumpidx.isEmpty()) { if (!groupingTitle.isEmpty()) { pginfo->title.prepend(groupingTitle); groupingTitle.clear(); } if (!groupingDesc.isEmpty()) { pginfo->description.prepend(groupingDesc); groupingDesc.clear(); } (*proglist)[pginfo->channel].push_back(*pginfo); } else { /* append all titles/descriptions from one clump */ if (pginfo->clumpidx.toInt() == 0) { aggregatedTitle.clear(); aggregatedDesc.clear(); } if (!pginfo->title.isEmpty()) { if (!aggregatedTitle.isEmpty()) aggregatedTitle.append(" | "); aggregatedTitle.append(pginfo->title); } if (!pginfo->description.isEmpty()) { if (!aggregatedDesc.isEmpty()) aggregatedDesc.append(" | "); aggregatedDesc.append(pginfo->description); } if (pginfo->clumpidx.toInt() == pginfo->clumpmax.toInt() - 1) { pginfo->title = aggregatedTitle; pginfo->description = aggregatedDesc; (*proglist)[pginfo->channel].push_back(*pginfo); } } } delete pginfo; } } n = n.nextSibling(); } return true; }
// localTimezoneOffset: 841 == "None", -841 == "Auto", other == fixed offset void fromXMLTVDate(QString ×tr, QDateTime &dt, int localTimezoneOffset = 841) { if (timestr.isEmpty()) { cerr << "Ignoring empty timestamp." << endl; return; } QStringList split = QStringList::split(" ", timestr); QString ts = split[0]; bool ok; int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0; if (ts.length() == 14) { year = ts.left(4).toInt(&ok, 10); month = ts.mid(4,2).toInt(&ok, 10); day = ts.mid(6,2).toInt(&ok, 10); hour = ts.mid(8,2).toInt(&ok, 10); min = ts.mid(10,2).toInt(&ok, 10); sec = ts.mid(12,2).toInt(&ok, 10); } else if (ts.length() == 12) { year = ts.left(4).toInt(&ok, 10); month = ts.mid(4,2).toInt(&ok, 10); day = ts.mid(6,2).toInt(&ok, 10); hour = ts.mid(8,2).toInt(&ok, 10); min = ts.mid(10,2).toInt(&ok, 10); sec = 0; } else { cerr << "Ignoring unknown timestamp format: " << ts << endl; return; } dt = QDateTime(QDate(year, month, day),QTime(hour, min, sec)); if ((split.size() > 1) && (localTimezoneOffset <= 840)) { QString tmp = split[1]; tmp.stripWhiteSpace(); int ts_offset = TimezoneToInt(tmp); if (abs(ts_offset) > 840) { ts_offset = 0; localTimezoneOffset = 841; } dt = dt.addSecs(-ts_offset * 60); } if (localTimezoneOffset < -840) { dt = MythUTCToLocal(dt); } else if (abs(localTimezoneOffset) <= 840) { dt = dt.addSecs(localTimezoneOffset * 60 ); } timestr = dt.toString("yyyyMMddhhmmss"); }
// localTimezoneOffset: 841 == "None", -841 == "Auto", other == fixed offset static void fromXMLTVDate(QString ×tr, QDateTime &dt, int localTimezoneOffset = 841) { if (timestr.isEmpty()) { VERBOSE(VB_XMLTV, "Found empty Date/Time in XMLTV data, ignoring"); return; } QStringList split = timestr.split(" "); QString ts = split[0]; bool ok; int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0; if (ts.length() == 14) { year = ts.left(4).toInt(&ok, 10); month = ts.mid(4,2).toInt(&ok, 10); day = ts.mid(6,2).toInt(&ok, 10); hour = ts.mid(8,2).toInt(&ok, 10); min = ts.mid(10,2).toInt(&ok, 10); sec = ts.mid(12,2).toInt(&ok, 10); } else if (ts.length() == 12) { year = ts.left(4).toInt(&ok, 10); month = ts.mid(4,2).toInt(&ok, 10); day = ts.mid(6,2).toInt(&ok, 10); hour = ts.mid(8,2).toInt(&ok, 10); min = ts.mid(10,2).toInt(&ok, 10); sec = 0; } else { VERBOSE(VB_IMPORTANT, QString("Ignoring unknown timestamp format: %1") .arg(ts)); return; } dt = QDateTime(QDate(year, month, day),QTime(hour, min, sec)); if ((split.size() > 1) && (localTimezoneOffset <= 840)) { QString tmp = split[1].trimmed(); int ts_offset = TimezoneToInt(tmp); if (abs(ts_offset) > 840) { ts_offset = 0; localTimezoneOffset = 841; } dt = dt.addSecs(-ts_offset * 60); } if (localTimezoneOffset < -840) { dt = MythUTCToLocal(dt); } else if (abs(localTimezoneOffset) <= 840) { dt = dt.addSecs(localTimezoneOffset * 60 ); } timestr = dt.toString("yyyyMMddhhmmss"); }
// localTimezoneOffset: 841 == "None", -841 == "Auto", other == fixed offset static void fromXMLTVDate(QString ×tr, QDateTime &dt, int localTimezoneOffset = 841) { if (timestr.isEmpty()) { LOG(VB_XMLTV, LOG_ERR, "Found empty Date/Time in XMLTV data, ignoring"); return; } QStringList split = timestr.split(" "); QString ts = split[0]; bool ok; int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0; if (ts.length() == 14) { year = ts.left(4).toInt(&ok, 10); month = ts.mid(4,2).toInt(&ok, 10); day = ts.mid(6,2).toInt(&ok, 10); hour = ts.mid(8,2).toInt(&ok, 10); min = ts.mid(10,2).toInt(&ok, 10); sec = ts.mid(12,2).toInt(&ok, 10); } else if (ts.length() == 12) { year = ts.left(4).toInt(&ok, 10); month = ts.mid(4,2).toInt(&ok, 10); day = ts.mid(6,2).toInt(&ok, 10); hour = ts.mid(8,2).toInt(&ok, 10); min = ts.mid(10,2).toInt(&ok, 10); sec = 0; } else { LOG(VB_GENERAL, LOG_ERR, QString("Ignoring unknown timestamp format: %1") .arg(ts)); return; } dt = QDateTime(QDate(year, month, day),QTime(hour, min, sec), Qt::LocalTime); if ((split.size() > 1) && (localTimezoneOffset <= 840)) { QString tmp = split[1].trimmed(); int ts_offset = TimezoneToInt(tmp); if (abs(ts_offset) > 840) { ts_offset = 0; localTimezoneOffset = 841; } dt = dt.addSecs(-ts_offset * 60); } if (localTimezoneOffset < -840) { dt.setTimeSpec(Qt::UTC); } else if (abs(localTimezoneOffset) <= 840) { dt = dt.addSecs(localTimezoneOffset * 60 ); } dt = dt.toUTC(); timestr = MythDate::toString(dt, MythDate::kFilename); }