Ticket #4327: eitfixup12.patch

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

Experimental fix for the EIT

  • libs/libmythtv/eitfixup.cpp

     
    1717      m_bellPPVDescriptionAllDay("^\\(.*\\sEastern\\)"),
    1818      m_bellPPVDescriptionAllDay2("^\\([0-9].*am-[0-9].*am\\sET\\)"),
    1919      m_bellPPVDescriptionEventId("\\([0-9]{5}\\)"),
    20       m_ukSubtitle("\\[.*S\\]"),
    2120      m_ukThen("\\s*(Then|Followed by) 60 Seconds\\.", false),
    22       m_ukNew("\\s*(Brand New|New)\\s*(Series|Episode)\\s*[:\\.\\-]",false),
     21      m_ukNew("(New\\.|\\s*(Brand New|New)\\s*(Series|Episode)\\s*[:\\.\\-])",false),
    2322      m_ukT4("^[tT]4:"),
    24       m_ukEQ("[:\\!\\?]"),
    25       m_ukEPQ("[:\\!\\.\\?]"),
    26       m_ukPStart("^\\.+"),
    27       m_ukPEnd("\\.+$"),
     23      m_ukCEPQ("[:\\!\\.\\?]"),
     24      m_ukDotSpaceStart("^[\\. ]+"),
     25      m_ukDotSpaceEnd("[\\. ]+$"),
    2826      m_ukSeries1("\\s*(\\d{1,2})/(\\d{1,2})"),
    2927      m_ukSeries2("\\((Part|Pt)\\s+(\\d{1,2})\\s+of\\s+(\\d{1,2})\\)", false),
    3028      m_ukSeries3("\\s*Episode\\s+(\\d{1,2})\\s+of\\s+(\\d{1,2})\\.", false),
     
    3230             "\\[(SL)(,AD){,1}(,(S)){,1}\\]"),
    3331      m_ukYear("[\\[\\(]([\\d]{4})[\\)\\]]"),
    3432      m_uk24ep("^\\d{1,2}:00[ap]m to \\d{1,2}:00[ap]m: "),
    35       m_ukStarring("(?:Western\\s)?[Ss]tarring ([\\w\\s\\-']+)[Aa]nd\\s([\\w\\s\\-']+)[\\.|,](?:\\s)*(\\d{4})?(?:\\.\\s)?"),
     33      m_ukStarring2("(?:Western\\s)?[Ss]tarring ([\\w\\s\\-']+)[Aa]nd\\s([\\w\\s\\-']+)[\\.|,](?:\\s)*(\\d{4})?(?:\\.\\s)?"),
     34      m_ukStarring1("star(ring|s)",false),
    3635      m_ukBBC7rpt("\\[Rptd?[^]]+\\d{1,2}\\.\\d{1,2}[ap]m\\]\\."),
    3736      m_ukCBBC("^CBBC\\s*[\\.]"),
    3837      m_ukCBeebies("^CBeebies\\s*[\\.]"),
    39       m_ukStarring1("star(ring|s)"),
    4038      m_ukDoubleDotEnd("\\.\\.+$"),
    4139      m_ukDoubleDotStart("^\\.\\.+"),
    42       m_ukDotSpaceStart("^\\. "),
    4340      m_ukTime("\\d{1,2}[\\.:]\\d{1,2}\\s*(am|pm|)"),
    4441      m_ukBBC34("BBC [THREE|FOUR] on BBC [ONE|TWO]\\.",false),
    4542      m_ukBBCSwitch("BBC Switch\\."),
    46       m_ukYearColon("^\\d\\d\\d\\d:"),
     43      m_ukYearColon("^[\\d]{4}:"),
    4744      m_comHemCountry("^(\\(.+\\))?\\s?([^ ]+)\\s([^\\.0-9]+)"
    4845                      "(?:\\sfrån\\s([0-9]{4}))(?:\\smed\\s([^\\.]+))?\\.?"),
    4946      m_comHemDirector("[Rr]egi"),
     
    299296
    300297void EITFixUp::SetUKSubtitle(DBEvent &event) const
    301298{
    302     QStringList strList1;
    303     int position1;
    304     int position2;
     299    QStringList strList1 = QStringList::split(".",event.description,TRUE);
     300    QStringList strList2 = QStringList::split("?",event.description,TRUE);
     301    QStringList strList3 = QStringList::split("!",event.description,TRUE);
     302    QStringList strList4 = QStringList::split(":",event.description,TRUE);
     303    QStringList strList;
    305304
    306     if ((position1 = event.description.find(m_ukEQ)) != -1)
     305    bool fColon = false;
     306    QString strEnd;
     307    if (strList4.count()>1)
    307308    {
    308         position2 = event.description.find(":",position1+1);
    309         if (position2 != -1)
     309        fColon = true;
     310        strList = strList4;
     311    }
     312    else
     313    {
     314        if (strList3.count()>1)
    310315        {
    311              strList1 = QStringList::split(" ",
    312                             event.description.mid(position1+1,
    313                             position2-position1+1));
    314              if (strList1.count() < kDotToTitle)
    315              {
    316                  event.subtitle = event.description.left(position2);
    317                  event.description = event.description.mid(position2 + 1);
    318              }
    319              else
    320              {
    321                  event.subtitle = event.description.left(position1);
    322                  event.description = event.description.mid(position1 + 1);
    323              }
     316            strList = strList3;
     317            strEnd = "!";
    324318        }
    325         else
     319        if (strList2.count()>1)
    326320        {
    327             strList1 = QStringList::split(" ",
    328                             event.description.left(position1));
    329             if (strList1.count() < kDotToTitle)
     321            strList = strList3;
     322            strEnd = "?";
     323        }
     324        if (strList1.count()>1)
     325           strList = strList1;
     326    }
     327
     328    if (strList.count())
     329    {
     330        strList1 = QStringList::split(" ",strList[0]);
     331        if (fColon || (strList1.count() < kDotToTitle))
     332        {
     333            if ((strList1.grep("Drama",false).count()==0) &&
     334                (strList1.grep("sitcom",false).count()==0) &&
     335                (strList1.grep("Series",false).count()==0) &&
     336                (strList1.grep(m_ukStarring1).count()==0))
    330337            {
    331                 if ((uint)position1 < SUBTITLE_MAX_LEN)
    332                 {
    333                      event.subtitle = event.description.left(position1);
    334                      event.description = event.description.mid(position1+1);
    335                 }
     338                 event.subtitle = strList[0]+strEnd;
     339                 event.description=
     340                              event.description.mid(strList[0].length()+1);
    336341            }
    337342        }
    338343    }
     
    347352    int position2;
    348353    QString strFull;
    349354
    350     position1 = event.description.find(m_ukSubtitle);
    351     if (position1 != -1)
    352     {
    353         event.subtitleType |= SUB_NORMAL;
    354         event.description.remove(m_ukSubtitle);
    355     }
    356 
     355    bool isMovie = event.category.startsWith("Movie",false);
    357356    // BBC three case (could add another record here ?)
    358357    event.description = event.description.remove(m_ukThen);
    359358    event.description = event.description.remove(m_ukNew);
     
    372371    // BBC 7 [Rpt of ...] case.
    373372    event.description = event.description.remove(m_ukBBC7rpt);
    374373
     374    // Remove [AD,S] etc.
     375    event.description = event.description.remove(m_ukCC);
     376
    375377    event.title = event.title.stripWhiteSpace();
    376378    event.description = event.description.stripWhiteSpace();
    377379
    378     QRegExp tmp24ep = m_uk24ep;
    379     if (!event.title.startsWith("CSI:") && !event.title.startsWith("CD:"))
    380     {
    381         if (((position1=event.title.find(m_ukDoubleDotEnd)) != -1) &&
    382             ((position2=event.description.find(m_ukDoubleDotStart)) != -1))
    383         {
    384             strFull = event.title.remove(m_ukDoubleDotEnd)+" "+
    385                   event.description.remove(m_ukDoubleDotStart);
    386             if ((position1 = strFull.find(m_ukEPQ)) != -1)
    387             {
    388                  if (strFull[position1] == '!' || strFull[position1] == '?' ||
    389                      strFull[position1] == '.')
    390                      position1++;
    391                  event.title = strFull.left(position1);
    392                  event.description = strFull.mid(position1 + 1);
    393                  SetUKSubtitle(event);
    394             }
    395             if ((position1 = strFull.find(m_ukYear)) != -1)
    396             {
    397                 // Looks like they are using the airdate as a delimiter
    398                 if ((uint)position1 < SUBTITLE_MAX_LEN)
    399                 {
    400                     event.description = event.title.mid(position1);
    401                     event.title = event.title.left(position1);
    402                 }
    403             }
    404         }
    405         else if ((position1 = tmp24ep.search(event.description)) != -1)
    406         {
    407             // Special case for episodes of 24.
    408             // -2 from the length cause we don't want ": " on the end
    409             event.subtitle = event.description.mid(position1,
    410                                 tmp24ep.cap(0).length() - 2);
    411             event.description = event.description.remove(tmp24ep.cap(0));
    412         }
    413         else if ((position1 = event.description.find(m_ukTime)) == -1)
    414         {
    415             if (event.title.find(m_ukYearColon) < 0)
    416             {
    417                 if (((position1 = event.title.find(":")) != -1) &&
    418                     (event.description.find(":") < 0 ))
    419                 {
    420                     if ((uint)position1 < SUBTITLE_MAX_LEN)
    421                     {
    422                         event.subtitle = event.title.mid(position1 + 1);
    423                         event.title = event.title.left(position1);
    424                     }
    425                 }
    426                 else
    427                     SetUKSubtitle(event);
    428             }
    429         }
    430     }
    431 
    432     if ((event.description.find(m_ukTime) == -1) && (event.subtitle.isEmpty()))
    433     {
    434        QStringList strList1 = QStringList::split(".",event.description,TRUE);
    435        QStringList strList2 = QStringList::split("?",event.description,TRUE);
    436        if (strList1.count()>1 || strList2.count()>1)
    437        {
    438            QString strEnd;
    439            if (strList1[0].length() > strList2[0].length())
    440            {
    441                strList1=strList2;
    442                strEnd="?";
    443            }
    444            strList2 = QStringList::split(" ",strList1[0]);
    445            if (strList2.count() < kDotToTitle)
    446            {
    447                QStringList strList3 = strList2.grep("Drama",false);
    448                QStringList strList4 = strList2.grep("sitcom",false);
    449                QStringList strList5 = strList2.grep(m_ukStarring1);
    450                QStringList strList6 = strList2.grep("Series",false);
    451                if ((strList3.count()==0) && (strList4.count()==0) &&
    452                    (strList5.count()==0) && (strList6.count()==0))
    453                {
    454                     event.subtitle = strList1[0]+strEnd;
    455                     event.description=
    456                                  event.description.mid(strList1[0].length()+1);
    457                }
    458            }
    459        }
    460     }
    461 
    462     QRegExp tmpStarring = m_ukStarring;
    463     if (tmpStarring.search(event.subtitle) != -1)
    464     {
    465         // If the "Starring..." string got promoted to subtitle move it back.
    466         event.description.prepend(". ");
    467         event.description.prepend(tmpStarring.cap(0));
    468         event.subtitle.remove(tmpStarring.cap(0));
    469     }
    470     tmpStarring = m_ukStarring;
    471     if (tmpStarring.search(event.description) != -1)
    472     {
    473         // if we match this we've captured 2 actors and an (optional) airdate
    474         event.AddPerson(DBPerson::kActor, tmpStarring.cap(1));
    475         event.AddPerson(DBPerson::kActor, tmpStarring.cap(2));
    476         if (tmpStarring.cap(3).length() > 0)
    477         {
    478             event.airdate = tmpStarring.cap(3);
    479             bool ok;
    480             uint y = tmpStarring.cap(3).toUInt(&ok);
    481             if (ok)
    482                 event.originalairdate = QDate(y, 1, 1);
    483         }
    484     }
    485 
    486380    // Work out the episode numbers (if any)
    487381    bool    series  = false;
    488382    QRegExp tmpExp1 = m_ukSeries1;
     
    501395            series = true;
    502396        }
    503397    }
    504     else if ((position1 = tmpExp1.search(event.subtitle)) != -1)
    505     {
    506         if ((tmpExp1.cap(1).toUInt() <= tmpExp1.cap(2).toUInt())
    507             && tmpExp1.cap(2).toUInt()<=50)
    508         {
    509             event.partnumber = tmpExp1.cap(1).toUInt();
    510             event.parttotal  = tmpExp1.cap(2).toUInt();
    511             // Remove from the subtitle
    512             event.subtitle = event.subtitle.left(position1) +
    513                 event.subtitle.mid(position1 + tmpExp1.cap(0).length());
    514             series = true;
    515         }
    516     }
    517398    else if ((position1 = tmpExp1.search(event.description)) != -1)
    518399    {
    519400        if ((tmpExp1.cap(1).toUInt() <= tmpExp1.cap(2).toUInt())
     
    548429    if (series)
    549430        event.category_type = kCategorySeries;
    550431
    551     // Work out the closed captions and Audio descriptions  (if any)
    552     QStringList captures;
    553     QStringList::const_iterator it;
    554     QRegExp tmpUKCC = m_ukCC;
    555     if ((position1 = tmpUKCC.search(event.description)) != -1)
     432    QRegExp tmpStarring2 = m_ukStarring2;
     433    if (tmpStarring2.search(event.description) != -1)
    556434    {
    557         // Enumerate throught and see if we have subtitles, don't modify
    558         // the description as we might destroy other useful information
    559         captures = tmpUKCC.capturedTexts();
    560         for (it = captures.begin(); it != captures.end(); ++it)
     435        // if we match this we've captured 2 actors and an (optional) airdate
     436        event.AddPerson(DBPerson::kActor, tmpStarring2.cap(1));
     437        event.AddPerson(DBPerson::kActor, tmpStarring2.cap(2));
     438        if (tmpStarring2.cap(3).length() > 0)
    561439        {
    562             if (*it == "S")
    563                 event.subtitleType |= SUB_NORMAL;
     440            event.airdate = tmpStarring2.cap(3);
     441            bool ok;
     442            uint y = tmpStarring2.cap(3).toUInt(&ok);
     443            if (ok)
     444                event.originalairdate = QDate(y, 1, 1);
    564445        }
    565446    }
    566     else if ((position1 = tmpUKCC.search(event.subtitle)) != -1)
     447
     448    QRegExp tmp24ep = m_uk24ep;
     449    if (!event.title.startsWith("CSI:") && !event.title.startsWith("CD:"))
    567450    {
    568         captures = tmpUKCC.capturedTexts();
    569         for (it = captures.begin(); it != captures.end(); ++it)
     451        if (((position1=event.title.find(m_ukDoubleDotEnd)) != -1) &&
     452            ((position2=event.description.find(m_ukDoubleDotStart)) != -1))
    570453        {
    571             if (*it == "S")
    572                 event.subtitleType |= SUB_NORMAL;
     454            QString strPart=event.title.remove(m_ukDoubleDotEnd)+" ";
     455            strFull = strPart + event.description.remove(m_ukDoubleDotStart);
     456            if (isMovie &&
     457                ((position1 = strFull.find(m_ukCEPQ,strPart.length())) != -1))
     458            {
     459                 if (strFull[position1] == '!' || strFull[position1] == '?' ||
     460                     strFull[position1] == '.')
     461                     position1++;
     462                 event.title = strFull.left(position1);
     463                 event.description = strFull.mid(position1 + 1);
     464            }
     465            else if ((position1 = strFull.find(m_ukCEPQ)) != -1)
     466            {
     467                 if (strFull[position1] == '!' || strFull[position1] == '?' ||
     468                     strFull[position1] == '.')
     469                     position1++;
     470                 event.title = strFull.left(position1);
     471                 event.description = strFull.mid(position1 + 1);
     472                 SetUKSubtitle(event);
     473            }
     474            if ((position1 = strFull.find(m_ukYear)) != -1)
     475            {
     476                // Looks like they are using the airdate as a delimiter
     477                if ((uint)position1 < SUBTITLE_MAX_LEN)
     478                {
     479                    event.description = event.title.mid(position1);
     480                    event.title = event.title.left(position1);
     481                }
     482            }
    573483        }
    574 
    575         // We remove [AD,S] from the subtitle.
    576         QString stmp = event.subtitle;
    577         int     itmp = position1 + tmpUKCC.cap(0).length();
    578         event.subtitle = stmp.left(position1) + stmp.mid(itmp);
     484        else if ((position1 = tmp24ep.search(event.description)) != -1)
     485        {
     486            // Special case for episodes of 24.
     487            // -2 from the length cause we don't want ": " on the end
     488            event.subtitle = event.description.mid(position1,
     489                                tmp24ep.cap(0).length() - 2);
     490            event.description = event.description.remove(tmp24ep.cap(0));
     491        }
     492        else if ((position1 = event.description.find(m_ukTime)) == -1)
     493        {
     494            if (!isMovie && (event.title.find(m_ukYearColon) < 0))
     495            {
     496                if (((position1 = event.title.find(":")) != -1) &&
     497                    (event.description.find(":") < 0 ))
     498                {
     499                    if ((uint)position1 < SUBTITLE_MAX_LEN)
     500                    {
     501                        event.subtitle = event.title.mid(position1 + 1);
     502                        event.title = event.title.left(position1);
     503                    }
     504                }
     505                else
     506                    SetUKSubtitle(event);
     507            }
     508        }
    579509    }
    580510
     511    if (!isMovie && (event.description.find(m_ukTime) == -1) &&
     512        (event.subtitle.isEmpty()))
     513        SetUKSubtitle(event);
     514
    581515    // Work out the year (if any)
    582516    QRegExp tmpUKYear = m_ukYear;
    583517    if ((position1 = tmpUKYear.search(event.description)) != -1)
     
    593527    }
    594528
    595529    // Trim trailing '.'
    596     event.title.remove(m_ukPEnd);
    597     event.subtitle.remove(m_ukPEnd);
     530    event.title.remove(m_ukDotSpaceEnd);
    598531    event.subtitle.remove(m_ukDotSpaceStart);
     532    event.subtitle.remove(m_ukDotSpaceEnd);
     533    event.description.remove(m_ukDotSpaceStart);
    599534}
    600535
    601536/** \fn EITFixUp::FixPBS(DBEvent&) const
  • libs/libmythtv/eitfixup.h

     
    7979    const QRegExp m_bellPPVDescriptionAllDay;
    8080    const QRegExp m_bellPPVDescriptionAllDay2;
    8181    const QRegExp m_bellPPVDescriptionEventId;
    82     const QRegExp m_ukSubtitle;
    8382    const QRegExp m_ukThen;
    8483    const QRegExp m_ukNew;
    8584    const QRegExp m_ukT4;
    86     const QRegExp m_ukEQ;
    87     const QRegExp m_ukEPQ;
    88     const QRegExp m_ukPStart;
    89     const QRegExp m_ukPEnd;
     85    const QRegExp m_ukCEPQ;
     86    const QRegExp m_ukDotSpaceStart;
     87    const QRegExp m_ukDotSpaceEnd;
    9088    const QRegExp m_ukSeries1;
    9189    const QRegExp m_ukSeries2;
    9290    const QRegExp m_ukSeries3;
    9391    const QRegExp m_ukCC;
    9492    const QRegExp m_ukYear;
    9593    const QRegExp m_uk24ep;
    96     const QRegExp m_ukStarring;
     94    const QRegExp m_ukStarring2;
     95    const QRegExp m_ukStarring1;
    9796    const QRegExp m_ukBBC7rpt;
    9897    const QRegExp m_ukCBBC;
    9998    const QRegExp m_ukCBeebies;
    100     const QRegExp m_ukStarring1;
    10199    const QRegExp m_ukDoubleDotEnd;
    102100    const QRegExp m_ukDoubleDotStart;
    103     const QRegExp m_ukDotSpaceStart;
    104101    const QRegExp m_ukTime;
    105102    const QRegExp m_ukBBC34;
    106103    const QRegExp m_ukBBCSwitch;