Ticket #5191: eitfixup3.patch

File eitfixup3.patch, 9.7 KB (added by john {at} pullan {dot} org, 16 years ago)
  • libs/libmythtv/eitfixup.cpp

     
     1/* vim: set expandtab tabstop=4 shiftwidth=4: */
    12// C++ headers
    23#include <algorithm>
    34
     
    2526      m_ukNew("(New\\.|\\s*(Brand New|New)\\s*(Series|Episode)\\s*[:\\.\\-])",false),
    2627      m_ukCEPQ("[:\\!\\.\\?]"),
    2728      m_ukColonPeriod("[:\\.]"),
    28       m_ukDotSpaceStart("^\\. "),
     29      m_ukDotSpaceStart("^(?:\\. | )"),
    2930      m_ukDotEnd("\\.$"),
    3031      m_ukSpaceColonStart("^[ |:]*"),
    3132      m_ukSpaceStart("^ "),
     
    3637      m_uk24ep("^\\d{1,2}:00[ap]m to \\d{1,2}:00[ap]m: "),
    3738      m_ukStarring("(?:Western\\s)?[Ss]tarring ([\\w\\s\\-']+)[Aa]nd\\s([\\w\\s\\-']+)[\\.|,](?:\\s)*(\\d{4})?(?:\\.\\s)?"),
    3839      m_ukBBC7rpt("\\[Rptd?[^]]+\\d{1,2}\\.\\d{1,2}[ap]m\\]\\."),
    39       m_ukDescriptionRemove("^(?:CBBC\\s*\\.|CBeebies\\s*\\.|Class TV\\s*:|BBC Switch\\.)"),
     40      m_ukDescriptionRemove("^(?:CBBC\\s*\\.|CBeebies\\s*\\.|Class TV\\s*:|BBC Switch(?:\\.|:))"),
    4041      m_ukTitleRemove("^(?:[tT]4:|Schools\\s*:)"),
    4142      m_ukDoubleDotEnd("\\.\\.+$"),
    4243      m_ukDoubleDotStart("^\\.\\.+"),
    4344      m_ukTime("\\d{1,2}[\\.:]\\d{1,2}\\s*(am|pm|)"),
    4445      m_ukBBC34("BBC (?:THREE|FOUR) on BBC (?:ONE|TWO)\\.",false),
    4546      m_ukYearColon("^[\\d]{4}:"),
    46       m_ukExclusionFromSubtitle("(starring|stars\\s|drama|series|sitcom)",false),
     47      m_ukExclusionFromSubtitle("(starring|stars|drama|series|sitcom|serial|^crime)",false),
    4748      m_ukCompleteDots("^\\.\\.+$"),
     49      m_uk5xNumberHyphen3xNumber("\\d\\d\\d\\d\\d-\\d\\d\\d [A-Z]"),
    4850      m_comHemCountry("^(\\(.+\\))?\\s?([^ ]+)\\s([^\\.0-9]+)"
    4951                      "(?:\\sfrån\\s([0-9]{4}))(?:\\smed\\s([^\\.]+))?\\.?"),
    5052      m_comHemDirector("[Rr]egi"),
     
    305307 */
    306308void EITFixUp::SetUKSubtitle(DBEvent &event) const
    307309{
    308     QStringList strListColon = event.description.split(":");
     310    if (!event.subtitle.isEmpty())
     311        return;
     312
     313    QStringList strListColon = QStringList::split(":",event.description,TRUE);
    309314    QStringList strListEnd;
    310315
    311316    bool fColon = false;
     
    329334         {
    330335             QString strTmp = event.description.mid(nPosition1+1,
    331336                                     nLength-nPosition1);
    332 
    333              QStringList tmp = strTmp.split(" ");
    334              if (((uint) tmp.size()) < kMaxDotToColon)
     337             QStringList tmp = strTmp.split(" ",QString::SkipEmptyParts);
     338             if (((uint) tmp.size()) <= kMaxDotToColon)
    335339                 fSingleDot = false;
    336340         }
    337341
     
    342346         }
    343347         else if (!fSingleDot)
    344348         {
    345              QStringList strListTmp;
    346              uint nTitle=0;
    347              int nTitleMax=-1;
     349             int nCount=strListColon.count();
     350             int nMaxLength=0;
     351             int nMaxTitle=0;
    348352             int i;
    349              for (i =0; (i<(int)strListColon.count()) && (nTitleMax==-1);i++)
     353             for (i=0;i<(nCount-1);i++)
    350354             {
    351                  const QStringList tmp = strListColon[i].split(" ");
    352 
    353                  nTitle += tmp.size();
    354 
    355                  if (nTitle < kMaxToTitle)
    356                      strListTmp.push_back(strListColon[i]);
    357                  else
    358                      nTitleMax=i;
     355                 QString strTmp = strListColon[i+1].stripWhiteSpace();
     356                 QChar aLetter = strTmp.at(0);
     357                 QChar bLetter = aLetter.lower();
     358                 uint nTmp=
     359                     QStringList::split(" ",strListColon[i],FALSE).count();
     360                 if ((nMaxLength+nTmp > kMaxToTitle) || (aLetter==bLetter))
     361                     break;
     362                 nMaxLength = nMaxLength+nTmp;
     363                 nMaxTitle = i;
    359364             }
    360              QString strPartial;
    361              for (i=0;i<(nTitleMax-1);i++)
    362                  strPartial+=strListTmp[i]+":";
    363              if (nTitleMax>0)
     365             if (nMaxLength)
    364366             {
    365                  strPartial+=strListTmp[nTitleMax-1];
     367                 QString strPartial;
     368                 for (i=0;i<=nMaxTitle;i++)
     369                 {
     370                     strPartial+=strListColon[i];
     371                     if (i<(nMaxTitle))
     372                          strPartial+=":";
     373                 }
    366374                 strListEnd.push_back(strPartial);
    367              }
    368              for (i=nTitleMax+1;i<(int)strListColon.count();i++)
    369                  strListEnd.push_back(strListColon[i]);
    370              fColon = true;
     375                 for (i=(nMaxTitle+1);i<nCount;i++)
     376                     strListEnd.push_back(strListColon[i]);
     377                 fColon=true;
     378             }             
    371379         }
    372380    }
     381
    373382    QStringList strListPeriod;
    374383    QStringList strListQuestion;
    375384    QStringList strListExcl;
    376385    if (!fColon)
    377386    {
    378         strListPeriod = event.description.split(".");
     387        int nLength=INT_MAX;
     388        strListPeriod = QStringList::split(".",event.description,TRUE);
     389        strListQuestion = QStringList::split("?",event.description,TRUE);
     390        strListExcl = QStringList::split("!",event.description,TRUE);
     391
    379392        if (strListPeriod.count() >1)
    380393        {
    381394            nPosition1 = event.description.find(".");
    382395            int nPosition2 = event.description.find("..");
    383396            if ((nPosition1 < nPosition2) || (nPosition2==-1))
     397            {
     398                nLength = strListPeriod[0].length(); 
    384399                strListEnd = strListPeriod;
     400            }
    385401        }
    386402
    387         strListQuestion = event.description.split("?");
    388         strListExcl = event.description.split("!");
    389         if ((strListQuestion.size() > 1) &&
    390             ((uint)strListQuestion.size() <= kMaxQuestionExclamation))
     403        if ((strListQuestion.size()>1) &&
     404                 ((uint)strListQuestion.size()<=kMaxQuestionExclamation) &&
     405                 ((int)(strListQuestion[0].length())<nLength))
    391406        {
    392407            strListEnd = strListQuestion;
    393408            strEnd = "?";
    394409        }
    395         else if ((strListExcl.size() > 1) &&
    396                  ((uint)strListExcl.size() <= kMaxQuestionExclamation))
     410        else if ((strListExcl.size()>1) &&
     411                 ((uint)strListExcl.size()<=kMaxQuestionExclamation) &&
     412                 ((int)(strListExcl[0].length())<nLength))
    397413        {
    398414            strListEnd = strListExcl;
    399415            strEnd = "!";
    400416        }
    401417        else
    402             strEnd = QString::null;
     418            strEnd = "";
    403419    }
    404420
    405421    if (!strListEnd.empty())
    406422    {
    407423        QStringList strListSpace = strListEnd[0].split(
    408424            " ", QString::SkipEmptyParts);
    409         if (fColon && ((uint)strListSpace.size() > kMaxToTitle))
     425        if (strListSpace.count() > kMaxToTitle)
    410426             return;
    411         if ((uint)strListSpace.size() > kDotToTitle)
    412              return;
    413427        if (strListSpace.grep(m_ukExclusionFromSubtitle).empty())
    414428        {
    415429             event.subtitle = strListEnd[0]+strEnd;
     
    501515    }
    502516
    503517    QRegExp tmp24ep = m_uk24ep;
    504     if (!event.title.startsWith("CSI:") && !event.title.startsWith("CD:"))
     518    if (!event.title.startsWith("CSI:") &&
     519        !event.title.startsWith("Law & Order:") &&
     520        !event.title.startsWith("CD:"))
    505521    {
    506522        if (((position1=event.title.find(m_ukDoubleDotEnd)) != -1) &&
    507523            ((position2=event.description.find(m_ukDoubleDotStart)) != -1))
     
    589605        }
    590606        else
    591607            SetUKSubtitle(event);
     608
     609        if (event.subtitle.isEmpty() &&
     610            (position1=event.description.find(m_uk5xNumberHyphen3xNumber)) &&
     611            (position1 >0) && ((uint)position1<SUBTITLE_MAX_LEN))
     612        {
     613            event.subtitle = event.description.left(position1+9);
     614            event.description = event.description.mid(position1+9);
     615        }
    592616    }
    593617
    594618    // Work out the year (if any)
     
    606630    }
    607631
    608632    // Trim leading/trailing '.'
     633    event.description.remove(m_ukDotSpaceStart);
    609634    event.subtitle.remove(m_ukDotSpaceStart);
    610635    if (event.subtitle.findRev("..") != (((int)event.subtitle.length())-2))
    611636        event.subtitle.remove(m_ukDotEnd);
    612637
     638    // Demote the subtitle if it matches the title
     639    if (!event.title.isEmpty() && !event.subtitle.isEmpty() &&
     640         event.title == event.subtitle)
     641    {
     642        event.description=event.subtitle+" "+event.description;
     643        event.subtitle=QString::null;
     644    }
     645
    613646    // Reverse the subtitle and empty description
    614647    if (event.description.isEmpty() && !event.subtitle.isEmpty())
    615648    {
  • libs/libmythtv/eitfixup.h

     
    11/*
     2 *  vim: set expandtab tabstop=4 shiftwidth=4:
    23 *  Copyright 2004 - Taylor Jacob (rtjacob at earthlink.net)
    34 */
    45
     
    1819     // max length of subtitle field in db.
    1920     static const uint SUBTITLE_MAX_LEN = 128;
    2021     // max number of words included in a subtitle
    21      static const uint kMaxToTitle = 14;
    22      // max number of words up to a period, question mark
    23      static const uint kDotToTitle = 9;
     22     static const uint kMaxToTitle = 10;
    2423     // max number of question/exclamation marks
    2524     static const uint kMaxQuestionExclamation = 2;
    2625     // max number of difference in words between a period and a colon
    27      static const uint kMaxDotToColon = 5;
     26     static const uint kMaxDotToColon = 6;
    2827
    2928  public:
    3029    enum FixUpType
     
    108107    const QRegExp m_ukYearColon;
    109108    const QRegExp m_ukExclusionFromSubtitle;
    110109    const QRegExp m_ukCompleteDots;
     110    const QRegExp m_uk5xNumberHyphen3xNumber;
    111111    const QRegExp m_comHemCountry;
    112112    const QRegExp m_comHemDirector;
    113113    const QRegExp m_comHemActor;