Ticket #5191: eitfixup1.patch

File eitfixup1.patch, 8.2 KB (added by john {at} pullan {dot} org, 16 years ago)

fixup patches

  • libs/libmythtv/eitfixup.cpp

     
    2121      m_ukNew("(New\\.|\\s*(Brand New|New)\\s*(Series|Episode)\\s*[:\\.\\-])",false),
    2222      m_ukCEPQ("[:\\!\\.\\?]"),
    2323      m_ukColonPeriod("[:\\.]"),
    24       m_ukDotSpaceStart("^\\. "),
     24      m_ukDotSpaceStart("^(?:\\. | )"),
    2525      m_ukDotEnd("\\.$"),
    2626      m_ukSpaceColonStart("^[ |:]*"),
    2727      m_ukSpaceStart("^ "),
     
    4141      m_ukYearColon("^[\\d]{4}:"),
    4242      m_ukExclusionFromSubtitle("(starring|stars\\s|drama|series|sitcom)",false),
    4343      m_ukCompleteDots("^\\.\\.+$"),
     44      m_uk5xNumberHyphen3xNumber("\\d\\d\\d\\d\\d-\\d\\d\\d [A-Z]"),
    4445      m_comHemCountry("^(\\(.+\\))?\\s?([^ ]+)\\s([^\\.0-9]+)"
    4546                      "(?:\\sfrån\\s([0-9]{4}))(?:\\smed\\s([^\\.]+))?\\.?"),
    4647      m_comHemDirector("[Rr]egi"),
     
    300301 */
    301302void EITFixUp::SetUKSubtitle(DBEvent &event) const
    302303{
     304    if (!event.subtitle.isEmpty())
     305        return;
     306
    303307    QStringList strListColon = QStringList::split(":",event.description,TRUE);
    304308    QStringList strListEnd;
    305309
     
    325329             QString strTmp = event.description.mid(nPosition1+1,
    326330                                     nLength-nPosition1);
    327331
    328              if (QStringList::split(" ", strTmp ,TRUE).count()< kMaxDotToColon)
     332             if (QStringList::split(" ", strTmp ,TRUE).count()<=kMaxDotToColon)
    329333                 fSingleDot = false;
    330334         }
    331335
     
    336340         }
    337341         else if (!fSingleDot)
    338342         {
    339              QStringList strListTmp;
    340              uint nTitle=0;
    341              int nTitleMax=-1;
     343             int nCount=strListColon.count();
     344             int nMaxLength=0;
     345             int nMaxTitle=0;
    342346             int i;
    343              for (i =0; (i<(int)strListColon.count()) && (nTitleMax==-1);i++)
     347             for (i=0;i<(nCount-1);i++)
    344348             {
    345                  if ((nTitle+=
    346                      QStringList::split(" ",strListColon[i],TRUE).count())
    347                           <kMaxToTitle)
    348                      strListTmp.push_back(strListColon[i]);
    349                  else
    350                      nTitleMax=i;
     349                 QString strTmp = strListColon[i+1].stripWhiteSpace();
     350                 QChar aLetter = strTmp.at(0);
     351                 QChar bLetter = aLetter.lower();
     352                 uint nTmp=
     353                     QStringList::split(" ",strListColon[i],FALSE).count();
     354                 if ((nMaxLength+nTmp > kMaxToTitle) || (aLetter==bLetter))
     355                     break;
     356                 nMaxLength = nMaxLength+nTmp;
     357                 nMaxTitle = i;
    351358             }
    352              QString strPartial;
    353              for (i=0;i<(nTitleMax-1);i++)
    354                  strPartial+=strListTmp[i]+":";
    355              if (nTitleMax>0)
     359             if (nMaxLength)
    356360             {
    357                  strPartial+=strListTmp[nTitleMax-1];
     361                 QString strPartial;
     362                 for (i=0;i<=nMaxTitle;i++)
     363                 {
     364                     strPartial+=strListColon[i];
     365                     if (i<(nMaxTitle))
     366                          strPartial+=":";
     367                 }
    358368                 strListEnd.push_back(strPartial);
    359              }
    360              for (i=nTitleMax+1;i<(int)strListColon.count();i++)
    361                  strListEnd.push_back(strListColon[i]);
    362              fColon = true;
     369                 for (i=(nMaxTitle+1);i<nCount;i++)
     370                     strListEnd.push_back(strListColon[i]);
     371                 fColon=true;
     372             }             
    363373         }
    364374    }
    365375    QStringList strListPeriod;
     
    367377    QStringList strListExcl;
    368378    if (!fColon)
    369379    {
     380        int nLength=INT_MAX;
    370381        strListPeriod = QStringList::split(".",event.description,TRUE);
     382        strListQuestion = QStringList::split("?",event.description,TRUE);
     383        strListExcl = QStringList::split("!",event.description,TRUE);
     384
    371385        if (strListPeriod.count() >1)
    372386        {
    373387            nPosition1 = event.description.find(".");
    374388            int nPosition2 = event.description.find("..");
    375389            if ((nPosition1 < nPosition2) || (nPosition2==-1))
     390            {
     391                nLength = strListPeriod[0].length(); 
    376392                strListEnd = strListPeriod;
     393            }
    377394        }
    378395
    379         strListQuestion = QStringList::split("?",event.description,TRUE);
    380         strListExcl = QStringList::split("!",event.description,TRUE);
    381396        if ((strListQuestion.count()>1) &&
    382                  (strListQuestion.count()<=kMaxQuestionExclamation))
     397                 (strListQuestion.count()<=kMaxQuestionExclamation) &&
     398                 ((int)(strListQuestion[0].length())<nLength))
    383399        {
    384400            strListEnd = strListQuestion;
    385401            strEnd = "?";
    386402        }
    387403        else if ((strListExcl.count()>1) &&
    388                  (strListExcl.count()<=kMaxQuestionExclamation))
     404                 (strListExcl.count()<=kMaxQuestionExclamation) &&
     405                 ((int)(strListExcl[0].length())<nLength))
    389406        {
    390407            strListEnd = strListExcl;
    391408            strEnd = "!";
     
    397414    if (strListEnd.count())
    398415    {
    399416        QStringList strListSpace = QStringList::split(" ",strListEnd[0]);
    400         if (fColon && (strListSpace.count() > kMaxToTitle))
     417        if (strListSpace.count() > kMaxToTitle)
    401418             return;
    402         if (strListSpace.count() > kDotToTitle)
    403              return;
     419
    404420        if (strListSpace.grep(m_ukExclusionFromSubtitle).count()==0)
    405421        {
    406422             event.subtitle = strListEnd[0]+strEnd;
     
    492508    }
    493509
    494510    QRegExp tmp24ep = m_uk24ep;
    495     if (!event.title.startsWith("CSI:") && !event.title.startsWith("CD:"))
     511    if (!event.title.startsWith("CSI:") &&
     512        !event.title.startsWith("Law & Order:") &&
     513        !event.title.startsWith("CD:"))
    496514    {
    497515        if (((position1=event.title.find(m_ukDoubleDotEnd)) != -1) &&
    498516            ((position2=event.description.find(m_ukDoubleDotStart)) != -1))
     
    580598        }
    581599        else
    582600            SetUKSubtitle(event);
     601/*
     602        if (event.subtitle.isEmpty() &&
     603            (position1=event.description.find(m_uk5xNumberHyphen3xNumber)) &&
     604            (position1 >0) && ((uint)position1<SUBTITLE_MAX_LEN))
     605        {
     606            event.subtitle = event.description.left(position1+9);
     607            event.description = event.description.mid(position1+9);
     608        }
     609*/
    583610    }
    584611
    585612    // Work out the year (if any)
     
    597624    }
    598625
    599626    // Trim leading/trailing '.'
     627    event.description.remove(m_ukDotSpaceStart);
    600628    event.subtitle.remove(m_ukDotSpaceStart);
    601629    if (event.subtitle.findRev("..") != (((int)event.subtitle.length())-2))
    602630        event.subtitle.remove(m_ukDotEnd);
    603631
     632    // Demote the subtitle if it matches the title
     633    if (!event.title.isEmpty() && !event.subtitle.isEmpty() &&
     634         event.title == event.subtitle)
     635    {
     636        event.description=event.subtitle+" "+event.description;
     637        event.subtitle=QString::null;
     638    }
     639
    604640    // Reverse the subtitle and empty description
    605641    if (event.description.isEmpty() && !event.subtitle.isEmpty())
    606642    {
  • libs/libmythtv/eitfixup.h

     
    1818     // max length of subtitle field in db.
    1919     static const uint SUBTITLE_MAX_LEN = 128;
    2020     // 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;
     21     static const uint kMaxToTitle = 10;
    2422     // max number of question/exclamation marks
    2523     static const uint kMaxQuestionExclamation = 2;
    2624     // max number of difference in words between a period and a colon
    27      static const uint kMaxDotToColon = 5;
     25     static const uint kMaxDotToColon = 6;
    2826
    2927  public:
    3028    enum FixUpType
     
    108106    const QRegExp m_ukYearColon;
    109107    const QRegExp m_ukExclusionFromSubtitle;
    110108    const QRegExp m_ukCompleteDots;
     109    const QRegExp m_uk5xNumberHyphen3xNumber;
    111110    const QRegExp m_comHemCountry;
    112111    const QRegExp m_comHemDirector;
    113112    const QRegExp m_comHemActor;