Ticket #5191: eitfixup4.patch

File eitfixup4.patch, 10.3 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]"),
     50      m_ukTerminus("\\d"),
    4851      m_comHemCountry("^(\\(.+\\))?\\s?([^ ]+)\\s([^\\.0-9]+)"
    4952                      "(?:\\sfrån\\s([0-9]{4}))(?:\\smed\\s([^\\.]+))?\\.?"),
    5053      m_comHemDirector("[Rr]egi"),
     
    305308 */
    306309void EITFixUp::SetUKSubtitle(DBEvent &event) const
    307310{
    308     QStringList strListColon = event.description.split(":");
     311    if (!event.subtitle.isEmpty())
     312        return;
     313
     314    QStringList strListColon = QStringList::split(":",event.description,TRUE);
    309315    QStringList strListEnd;
    310316
    311317    bool fColon = false;
     
    329335         {
    330336             QString strTmp = event.description.mid(nPosition1+1,
    331337                                     nLength-nPosition1);
    332 
    333              QStringList tmp = strTmp.split(" ");
    334              if (((uint) tmp.size()) < kMaxDotToColon)
     338             QStringList tmp = strTmp.split(" ",QString::SkipEmptyParts);
     339             if (((uint) tmp.size()) <= kMaxDotToColon)
    335340                 fSingleDot = false;
    336341         }
    337342
     
    342347         }
    343348         else if (!fSingleDot)
    344349         {
    345              QStringList strListTmp;
    346              uint nTitle=0;
    347              int nTitleMax=-1;
     350             int nCount=strListColon.count();
     351             int nMaxLength=0;
     352             int nMaxTitle=0;
    348353             int i;
    349              for (i =0; (i<(int)strListColon.count()) && (nTitleMax==-1);i++)
     354             for (i=0;i<(nCount-1);i++)
    350355             {
    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;
     356                 QString strTmp = strListColon[i+1].stripWhiteSpace();
     357                 QChar aLetter = strTmp.at(0);
     358                 QChar bLetter = aLetter.lower();
     359                 uint nTmp=
     360                     QStringList::split(" ",strListColon[i],FALSE).count();
     361                 if ((nMaxLength+nTmp > kMaxToTitle) || (aLetter==bLetter))
     362                     break;
     363                 nMaxLength = nMaxLength+nTmp;
     364                 nMaxTitle = i;
    359365             }
    360              QString strPartial;
    361              for (i=0;i<(nTitleMax-1);i++)
    362                  strPartial+=strListTmp[i]+":";
    363              if (nTitleMax>0)
     366             if (nMaxLength)
    364367             {
    365                  strPartial+=strListTmp[nTitleMax-1];
     368                 QString strPartial;
     369                 for (i=0;i<=nMaxTitle;i++)
     370                 {
     371                     strPartial+=strListColon[i];
     372                     if (i<(nMaxTitle))
     373                          strPartial+=":";
     374                 }
    366375                 strListEnd.push_back(strPartial);
    367              }
    368              for (i=nTitleMax+1;i<(int)strListColon.count();i++)
    369                  strListEnd.push_back(strListColon[i]);
    370              fColon = true;
     376                 for (i=(nMaxTitle+1);i<nCount;i++)
     377                     strListEnd.push_back(strListColon[i]);
     378                 fColon=true;
     379             }             
    371380         }
    372381    }
     382
    373383    QStringList strListPeriod;
    374384    QStringList strListQuestion;
    375385    QStringList strListExcl;
    376386    if (!fColon)
    377387    {
    378         strListPeriod = event.description.split(".");
     388        int nLength=INT_MAX;
     389        strListPeriod = QStringList::split(".",event.description,TRUE);
     390        strListQuestion = QStringList::split("?",event.description,TRUE);
     391        strListExcl = QStringList::split("!",event.description,TRUE);
     392
    379393        if (strListPeriod.count() >1)
    380394        {
    381395            nPosition1 = event.description.find(".");
    382396            int nPosition2 = event.description.find("..");
    383397            if ((nPosition1 < nPosition2) || (nPosition2==-1))
     398            {
     399                nLength = strListPeriod[0].length(); 
    384400                strListEnd = strListPeriod;
     401            }
    385402        }
    386403
    387         strListQuestion = event.description.split("?");
    388         strListExcl = event.description.split("!");
    389         if ((strListQuestion.size() > 1) &&
    390             ((uint)strListQuestion.size() <= kMaxQuestionExclamation))
     404        if ((strListQuestion.size()>1) &&
     405                 ((uint)strListQuestion.size()<=kMaxQuestionExclamation) &&
     406                 ((int)(strListQuestion[0].length())<nLength))
    391407        {
    392408            strListEnd = strListQuestion;
    393409            strEnd = "?";
    394410        }
    395         else if ((strListExcl.size() > 1) &&
    396                  ((uint)strListExcl.size() <= kMaxQuestionExclamation))
     411        else if ((strListExcl.size()>1) &&
     412                 ((uint)strListExcl.size()<=kMaxQuestionExclamation) &&
     413                 ((int)(strListExcl[0].length())<nLength))
    397414        {
    398415            strListEnd = strListExcl;
    399416            strEnd = "!";
    400417        }
    401418        else
    402             strEnd = QString::null;
     419            strEnd = "";
    403420    }
    404421
    405422    if (!strListEnd.empty())
    406423    {
    407424        QStringList strListSpace = strListEnd[0].split(
    408425            " ", QString::SkipEmptyParts);
    409         if (fColon && ((uint)strListSpace.size() > kMaxToTitle))
     426        if (strListSpace.count() > (int)kMaxToTitle)
    410427             return;
    411         if ((uint)strListSpace.size() > kDotToTitle)
    412              return;
    413428        if (strListSpace.grep(m_ukExclusionFromSubtitle).empty())
    414429        {
    415430             event.subtitle = strListEnd[0]+strEnd;
     
    501516    }
    502517
    503518    QRegExp tmp24ep = m_uk24ep;
    504     if (!event.title.startsWith("CSI:") && !event.title.startsWith("CD:"))
     519    if (!event.title.startsWith("CSI:") &&
     520        !event.title.startsWith("Law & Order:") &&
     521        !event.title.startsWith("CD:"))
    505522    {
    506523        if (((position1=event.title.find(m_ukDoubleDotEnd)) != -1) &&
    507524            ((position2=event.description.find(m_ukDoubleDotStart)) != -1))
     
    558575                        event.title.setLength(position1);
    559576                        event.subtitle = strTmp+event.subtitle;
    560577                    }
    561                     else if ((uint)position1 < SUBTITLE_MAX_LEN)
     578                    else if (
     579                        (event.title.mid(position1+1).find(m_ukTerminus)!=0) &&
     580                        ((uint)position1 < SUBTITLE_MAX_LEN))
    562581                    {
    563582                        event.subtitle = event.title.mid(position1 + 1);
    564583                        event.title = event.title.left(position1);
     
    589608        }
    590609        else
    591610            SetUKSubtitle(event);
     611
     612        if (event.subtitle.isEmpty() &&
     613            (position1=event.description.find(m_uk5xNumberHyphen3xNumber)) &&
     614            (position1 >0) && ((uint)position1<SUBTITLE_MAX_LEN))
     615        {
     616            event.subtitle = event.description.left(position1+9);
     617            event.description = event.description.mid(position1+9);
     618        }
    592619    }
    593620
    594621    // Work out the year (if any)
     
    606633    }
    607634
    608635    // Trim leading/trailing '.'
     636    event.description.remove(m_ukDotSpaceStart);
    609637    event.subtitle.remove(m_ukDotSpaceStart);
    610638    if (event.subtitle.findRev("..") != (((int)event.subtitle.length())-2))
    611639        event.subtitle.remove(m_ukDotEnd);
    612640
     641    // Demote the subtitle if it matches the title
     642    if (!event.title.isEmpty() && !event.subtitle.isEmpty() &&
     643         event.title == event.subtitle)
     644    {
     645        event.description=event.subtitle+" "+event.description;
     646        event.subtitle=QString::null;
     647    }
     648
    613649    // Reverse the subtitle and empty description
    614650    if (event.description.isEmpty() && !event.subtitle.isEmpty())
    615651    {
  • 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;
     111    const QRegExp m_ukTerminus;
    111112    const QRegExp m_comHemCountry;
    112113    const QRegExp m_comHemDirector;
    113114    const QRegExp m_comHemActor;