Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2013
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 12.49 KB | None | 0 0
  1. commit 36c61a41a0ca347b2dda8f785468c045d281c20c
  2. Author: Stuart Morgan <smorgan@mythtv.org>
  3. Date:   Wed Apr 3 23:10:37 2013 +0100
  4.  
  5.     Remove XMLTV TimeOffset setting and improve xmltv date parsing
  6.    
  7.     The XMLTV spec requires that the grabber do one of two things:
  8.     1) Supply dates and times in GMT
  9.     2) Include a timezone/time offset in ISO8601 format with datetime
  10.     strings
  11.    
  12.     Since we require grabbers and xmltv files to be XMLTV compliant the
  13.     TimeOffset setting makes no sense and is only likely to cause
  14.     mis-configurations.
  15.    
  16.     The date string parsing has been improved to handling more legitimate
  17.     strings and leverages QDateTimes parsing instead of duplicating it.
  18.  
  19. diff --git a/mythtv/programs/mythfilldatabase/xmltvparser.cpp b/mythtv/programs/mythfilldatabase/xmltvparser.cpp
  20. index 8c0aa34..c87aadd 100644
  21. --- a/mythtv/programs/mythfilldatabase/xmltvparser.cpp
  22. +++ b/mythtv/programs/mythfilldatabase/xmltvparser.cpp
  23. @@ -116,108 +116,76 @@ ChannelInfo *XMLTVParser::parseChannel(QDomElement &element, QUrl &baseUrl)
  24.      return chaninfo;
  25.  }
  26.  
  27. -static int TimezoneToInt (QString timezone)
  28. -{
  29. -    // we signal an error by setting it invalid (> 840min = 14hr)
  30. -    int result = 841;
  31. -
  32. -    if (timezone.toUpper() == "UTC" || timezone.toUpper() == "GMT")
  33. -        return 0;
  34. -
  35. -    if (timezone.length() == 5)
  36. -    {
  37. -        bool ok;
  38. -
  39. -        result = timezone.mid(1,2).toInt(&ok, 10);
  40. -
  41. -        if (!ok)
  42. -            result = 841;
  43. -        else
  44. -        {
  45. -            result *= 60;
  46. -
  47. -            int min = timezone.right(2).toInt(&ok, 10);
  48. -
  49. -            if (!ok)
  50. -                result = 841;
  51. -            else
  52. -            {
  53. -                result += min;
  54. -                if (timezone.left(1) == "-")
  55. -                    result *= -1;
  56. -            }
  57. -        }
  58. -    }
  59. -    return result;
  60. -}
  61. -
  62. -// localTimezoneOffset: 841 == "None", -841 == "Auto", other == fixed offset
  63. -static void fromXMLTVDate(QString &timestr, QDateTime &dt, int localTimezoneOffset = 841)
  64. -{
  65. +static void fromXMLTVDate(QString &timestr, QDateTime &dt)
  66. +{
  67.      if (timestr.isEmpty())
  68.      {
  69.          LOG(VB_XMLTV, LOG_ERR, "Found empty Date/Time in XMLTV data, ignoring");
  70.          return;
  71.      }
  72. +    
  73. +    // The XMLTV spec requires dates to either be in UTC/GMT or to specify a
  74. +    // valid timezone. We are sticking to the spec and require all grabbers
  75. +    // to comply.
  76. +    dt.setTimeSpec(Qt::UTC);
  77.  
  78.      QStringList split = timestr.split(" ");
  79.      QString ts = split[0];
  80. -    bool ok;
  81. -    int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0;
  82. +    QDateTime tmpDT;
  83. +    tmpDT.setTimeSpec(Qt::LocalTime);
  84.  
  85.      if (ts.length() == 14)
  86.      {
  87. -        year  = ts.left(4).toInt(&ok, 10);
  88. -        month = ts.mid(4,2).toInt(&ok, 10);
  89. -        day   = ts.mid(6,2).toInt(&ok, 10);
  90. -        hour  = ts.mid(8,2).toInt(&ok, 10);
  91. -        min   = ts.mid(10,2).toInt(&ok, 10);
  92. -        sec   = ts.mid(12,2).toInt(&ok, 10);
  93. +        tmpDT = QDateTime::fromString(ts, "yyyyMMddHHmmss");
  94.      }
  95.      else if (ts.length() == 12)
  96.      {
  97. -        year  = ts.left(4).toInt(&ok, 10);
  98. -        month = ts.mid(4,2).toInt(&ok, 10);
  99. -        day   = ts.mid(6,2).toInt(&ok, 10);
  100. -        hour  = ts.mid(8,2).toInt(&ok, 10);
  101. -        min   = ts.mid(10,2).toInt(&ok, 10);
  102. -        sec   = 0;
  103. +        tmpDT = QDateTime::fromString(ts, "yyyyMMddHHmm");
  104.      }
  105. -    else
  106. +    else if (ts.length() == 8)
  107. +    {
  108. +        tmpDT = QDateTime::fromString(ts, "yyyyMMdd");
  109. +    }
  110. +    else if (ts.length() == 6)
  111. +    {
  112. +        tmpDT = QDateTime::fromString(ts, "yyyyMM");
  113. +    }
  114. +    else if (ts.length() == 4)
  115. +    {
  116. +        tmpDT = QDateTime::fromString(ts, "yyyy");
  117. +    }
  118. +
  119. +    if (!tmpDT.isValid())
  120.      {
  121.          LOG(VB_GENERAL, LOG_ERR,
  122.              QString("Ignoring unknown timestamp format: %1")
  123.                  .arg(ts));
  124.          return;
  125.      }
  126. -
  127. -    dt = QDateTime(QDate(year, month, day),QTime(hour, min, sec),
  128. -                   Qt::LocalTime);
  129. -
  130. -    if ((split.size() > 1) && (localTimezoneOffset <= 840))
  131. +    
  132. +    if (split.size() > 1)
  133.      {
  134.          QString tmp = split[1].trimmed();
  135. -
  136. -        int ts_offset = TimezoneToInt(tmp);
  137. -        if (abs(ts_offset) > 840)
  138. -        {
  139. -            ts_offset = 0;
  140. -            localTimezoneOffset = 841;
  141. -        }
  142. -        dt = dt.addSecs(-ts_offset * 60);
  143. -    }
  144. -
  145. -    if (localTimezoneOffset < -840)
  146. -    {
  147. -        dt.setTimeSpec(Qt::UTC);
  148. +        // While this seems like a hack, it's better than what was done before
  149. +        QString isoDateString = QString("%1 %2").arg(tmpDT.toString(Qt::ISODate))
  150. +                                                .arg(tmp);
  151. +        dt = QDateTime::fromString(isoDateString, Qt::ISODate);
  152.      }
  153. -    else if (abs(localTimezoneOffset) <= 840)
  154. +    
  155. +    if (!dt.isValid())
  156.      {
  157. -        dt = dt.addSecs(localTimezoneOffset * 60 );
  158. +        static bool warned_once_on_implicit_utc = false;
  159. +        if (!warned_once_on_implicit_utc)
  160. +        {
  161. +            LOG(VB_XMLTV, LOG_ERR, "No explicit time zone found, "
  162. +                "guessing implicit UTC! Please consider enhancing "
  163. +                "the guide source to provice explicit UTC or local "
  164. +                "time instead.");
  165. +            warned_once_on_implicit_utc = true;
  166. +        }
  167. +        dt = tmpDT;
  168.      }
  169.  
  170. -    dt = dt.toUTC();
  171. -
  172.      timestr = MythDate::toString(dt, MythDate::kFilename);
  173.  }
  174.  
  175. @@ -286,19 +254,18 @@ static void parseAudio(QDomElement &element, ProgInfo *pginfo)
  176.      }
  177.  }
  178.  
  179. -ProgInfo *XMLTVParser::parseProgram(
  180. -    QDomElement &element, int localTimezoneOffset)
  181. +ProgInfo *XMLTVParser::parseProgram(QDomElement &element)
  182.  {
  183.      QString uniqueid, season, episode;
  184.      int dd_progid_done = 0;
  185.      ProgInfo *pginfo = new ProgInfo();
  186.  
  187.      QString text = element.attribute("start", "");
  188. -    fromXMLTVDate(text, pginfo->starttime, localTimezoneOffset);
  189. +    fromXMLTVDate(text, pginfo->starttime);
  190.      pginfo->startts = text;
  191.  
  192.      text = element.attribute("stop", "");
  193. -    fromXMLTVDate(text, pginfo->endtime, localTimezoneOffset);
  194. +    fromXMLTVDate(text, pginfo->endtime);
  195.      pginfo->endts = text;
  196.  
  197.      text = element.attribute("channel", "");
  198. @@ -422,8 +389,7 @@ ProgInfo *XMLTVParser::parseProgram(
  199.                  if (!prevdate.isEmpty())
  200.                  {
  201.                      QDateTime date;
  202. -                    fromXMLTVDate(prevdate, date,
  203. -                                localTimezoneOffset);
  204. +                    fromXMLTVDate(prevdate, date);
  205.                      pginfo->originalairdate = date.date();
  206.                  }
  207.              }
  208. @@ -610,28 +576,6 @@ bool XMLTVParser::parseFile(
  209.  
  210.      f.close();
  211.  
  212. -    // now we calculate the localTimezoneOffset, so that we can fix
  213. -    // the programdata if needed
  214. -    QString config_offset = gCoreContext->GetSetting("TimeOffset", "None");
  215. -    // we disable this feature by setting it invalid (> 840min = 14hr)
  216. -    int localTimezoneOffset = 841;
  217. -
  218. -    if (config_offset == "Auto")
  219. -    {
  220. -        // we mark auto with the -ve of the disable magic number
  221. -        localTimezoneOffset = -841;
  222. -    }
  223. -    else if (config_offset != "None")
  224. -    {
  225. -        localTimezoneOffset = TimezoneToInt(config_offset);
  226. -        if (abs(localTimezoneOffset) > 840)
  227. -        {
  228. -            LOG(VB_XMLTV, LOG_ERR, QString("Ignoring invalid TimeOffset %1")
  229. -                .arg(config_offset));
  230. -            localTimezoneOffset = 841;
  231. -        }
  232. -    }
  233. -
  234.      QDomElement docElem = doc.documentElement();
  235.  
  236.      QUrl baseUrl(docElem.attribute("source-data-url", ""));
  237. @@ -664,7 +608,7 @@ bool XMLTVParser::parseFile(
  238.              }
  239.              else if (e.tagName() == "programme")
  240.              {
  241. -                ProgInfo *pginfo = parseProgram(e, localTimezoneOffset);
  242. +                ProgInfo *pginfo = parseProgram(e);
  243.  
  244.                  if (pginfo->startts == pginfo->endts)
  245.                  {
  246. diff --git a/mythtv/programs/mythfilldatabase/xmltvparser.h b/mythtv/programs/mythfilldatabase/xmltvparser.h
  247. index bcb67f1..eae1a99 100644
  248. --- a/mythtv/programs/mythfilldatabase/xmltvparser.h
  249. +++ b/mythtv/programs/mythfilldatabase/xmltvparser.h
  250. @@ -19,7 +19,7 @@ class XMLTVParser
  251.      XMLTVParser();
  252.  
  253.      ChannelInfo *parseChannel(QDomElement &element, QUrl &baseUrl);
  254. -    ProgInfo *parseProgram(QDomElement &element, int localTimezoneOffset);
  255. +    ProgInfo *parseProgram(QDomElement &element);
  256.      bool parseFile(QString filename, ChannelInfoList *chanlist,
  257.                     QMap<QString, QList<ProgInfo> > *proglist);
  258.  
  259. diff --git a/mythtv/programs/mythtv-setup/backendsettings.cpp b/mythtv/programs/mythtv-setup/backendsettings.cpp
  260. index d75e72e..4ebfe6f 100644
  261. --- a/mythtv/programs/mythtv-setup/backendsettings.cpp
  262. +++ b/mythtv/programs/mythtv-setup/backendsettings.cpp
  263. @@ -273,90 +273,6 @@ static HostLineEdit *MiscStatusScript()
  264.      return he;
  265.  }
  266.  
  267. -static void init_time_offsets(GlobalComboBox *gc)
  268. -{
  269. -    gc->addSelection("None");
  270. -    gc->addSelection("Auto");
  271. -    gc->addSelection("+0030");
  272. -    gc->addSelection("+0100");
  273. -    gc->addSelection("+0130");
  274. -    gc->addSelection("+0200");
  275. -    gc->addSelection("+0230");
  276. -    gc->addSelection("+0300");
  277. -    gc->addSelection("+0330");
  278. -    gc->addSelection("+0400");
  279. -    gc->addSelection("+0430");
  280. -    gc->addSelection("+0500");
  281. -    gc->addSelection("+0530");
  282. -    gc->addSelection("+0600");
  283. -    gc->addSelection("+0630");
  284. -    gc->addSelection("+0700");
  285. -    gc->addSelection("+0730");
  286. -    gc->addSelection("+0800");
  287. -    gc->addSelection("+0830");
  288. -    gc->addSelection("+0900");
  289. -    gc->addSelection("+0930");
  290. -    gc->addSelection("+1000");
  291. -    gc->addSelection("+1030");
  292. -    gc->addSelection("+1100");
  293. -    gc->addSelection("+1130");
  294. -    gc->addSelection("+1200");
  295. -    gc->addSelection("-1100");
  296. -    gc->addSelection("-1030");
  297. -    gc->addSelection("-1000");
  298. -    gc->addSelection("-0930");
  299. -    gc->addSelection("-0900");
  300. -    gc->addSelection("-0830");
  301. -    gc->addSelection("-0800");
  302. -    gc->addSelection("-0730");
  303. -    gc->addSelection("-0700");
  304. -    gc->addSelection("-0630");
  305. -    gc->addSelection("-0600");
  306. -    gc->addSelection("-0530");
  307. -    gc->addSelection("-0500");
  308. -    gc->addSelection("-0430");
  309. -    gc->addSelection("-0400");
  310. -    gc->addSelection("-0330");
  311. -    gc->addSelection("-0300");
  312. -    gc->addSelection("-0230");
  313. -    gc->addSelection("-0200");
  314. -    gc->addSelection("-0130");
  315. -    gc->addSelection("-0100");
  316. -    gc->addSelection("-0030");
  317. -}
  318. -
  319. -static GlobalComboBox *TimeOffset()
  320. -{
  321. -    GlobalComboBox *gc = new GlobalComboBox("TimeOffset");
  322. -    gc->setLabel(QObject::tr("Your local time zone (for XMLTV)"));
  323. -    init_time_offsets(gc);
  324. -    QString helptext = QObject::tr(
  325. -        "Used if the XMLTV data comes from a different time zone than your "
  326. -        "own and modifies the date and time before insertion into the "
  327. -        "database. 'Auto' converts the XMLTV time to local time using your "
  328. -        "computer's time zone. "
  329. -        "'None' ignores the XMLTV time zone, interpreting times as local.");
  330. -    gc->setHelpText(helptext);
  331. -    return gc;
  332. -};
  333. -
  334. -#if 0
  335. -static GlobalComboBox *EITTimeOffset()
  336. -{
  337. -    GlobalComboBox *gc = new GlobalComboBox("EITTimeOffset");
  338. -    gc->setLabel(QObject::tr("Time offset for EIT listings"));
  339. -    init_time_offsets(gc);
  340. -    gc->setValue(1);
  341. -    QString helptext = QObject::tr(
  342. -        "Adjust the relative time zone of the EIT EPG data. "
  343. -        "'Auto' converts the EIT time to local time using your "
  344. -        "computer's time zone. "
  345. -        "'None' ignores the EIT time zone, interpreting times as local.");
  346. -    gc->setHelpText(helptext);
  347. -    return gc;
  348. -};
  349. -#endif
  350. -
  351.  static GlobalSpinBox *EITTransportTimeout()
  352.  {
  353.      GlobalSpinBox *gc = new GlobalSpinBox("EITTransportTimeout", 1, 15, 1);
  354. @@ -918,7 +834,6 @@ BackendSettings::BackendSettings() {
  355.      locale->addChild(TVFormat());
  356.      locale->addChild(VbiFormat());
  357.      locale->addChild(FreqTable());
  358. -    locale->addChild(TimeOffset());
  359.      addChild(locale);
  360.  
  361.      VerticalConfigurationGroup* group2 = new VerticalConfigurationGroup(false);
  362. @@ -947,7 +862,6 @@ BackendSettings::BackendSettings() {
  363.  
  364.      VerticalConfigurationGroup* group2a1 = new VerticalConfigurationGroup(false);
  365.      group2a1->setLabel(QObject::tr("EIT Scanner Options"));
  366. -    //group2a1->addChild(EITTimeOffset());
  367.      group2a1->addChild(EITTransportTimeout());
  368.      group2a1->addChild(EITCrawIdleStart());
  369.      addChild(group2a1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement