Ticket #1884: comhem-fixup.diff

File comhem-fixup.diff, 17.2 KB (added by torbjorn.jansson@…, 19 years ago)

the patch

  • libs/libmythtv/eit.cpp

     
    279279    QString lsubtitle = subtitle;
    280280    QString ldesc     = description;
    281281    QString lcategory = category;
     282    QString lairdate  = airdate;
     283    QDate loriginalairdate = originalairdate;
    282284
    283285    if (match.title.length() >= ltitle.length())
    284286        ltitle = match.title;
     
    292294    if (lcategory.isEmpty() && !match.category.isEmpty())
    293295        lcategory = match.category;
    294296
     297    if (lairdate.isEmpty() && !match.airdate.isEmpty())
     298        lairdate = match.airdate;
     299
     300    if (loriginalairdate.isNull() && !match.originalairdate.isNull())
     301        loriginalairdate = match.originalairdate;
     302
    295303    uint tmp = category_type;
    296304    if (!category_type && match.category_type)
    297305        tmp = match.category_type;
     
    317325        "    closecaptioned = :CC,        subtitled     = :SUBTITLED, "
    318326        "    stereo         = :STEREO,    hdtv          = :HDTV, "
    319327        "    partnumber     = :PARTNO,    parttotal     = :PARTTOTAL, "
    320         "    listingsource  = :LSOURCE "
     328        "    listingsource  = :LSOURCE,   airdate       = :AIRDATE, "
     329        "    originalairdate = :ORGAIRDATE "
    321330        "WHERE chanid    = :CHANID AND "
    322331        "      starttime = :OLDSTART ");
    323332
     
    337346    query.bindValue(":PARTNO",      lpartnumber);
    338347    query.bindValue(":PARTTOTAL",   lparttotal);
    339348    query.bindValue(":LSOURCE",     1);
     349    query.bindValue(":AIRDATE",     lairdate=="" ? "0000" : lairdate);
     350    query.bindValue(":ORGAIRDATE",  loriginalairdate);
    340351
    341352    if (!query.exec())
    342353    {
     
    458469        "  starttime,      endtime, "
    459470        "  closecaptioned, subtitled,      stereo,          hdtv, "
    460471        "  partnumber,     parttotal, "
    461         "  listingsource ) "
     472        "  listingsource,  airdate,        originalairdate ) "
    462473        "VALUES ("
    463474        " :CHANID,        :TITLE,         :SUBTITLE,       :DESCRIPTION, "
    464475        " :CATEGORY,      :CATTYPE, "
    465476        " :STARTTIME,     :ENDTIME, "
    466477        " :CC,            :SUBTITLED,     :STEREO,         :HDTV, "
    467478        " :PARTNUMBER,    :PARTTOTAL, "
    468         " :LSOURCE ) ");
     479        " :LSOURCE,       :AIRDATE,       :ORGAIRDATE ) ");
    469480
    470481    QString cattype = myth_category_type_to_string(category_type);
    471482
     
    484495    query.bindValue(":PARTNUMBER",  partnumber);
    485496    query.bindValue(":PARTTOTAL",   parttotal);
    486497    query.bindValue(":LSOURCE",     1);
     498    query.bindValue(":AIRDATE",     airdate=="" ? "0000" : airdate);
     499    query.bindValue(":ORGAIRDATE",  originalairdate);
    487500
    488501    if (!query.exec())
    489502    {
  • libs/libmythtv/eit.h

     
    123123    QDateTime     starttime;
    124124    QDateTime     endtime;
    125125    QDate         originalairdate;
     126    QString       airdate;          // movie year / production year
    126127    DBCredits    *credits;
    127128    uint32_t      chanid;
    128129    uint16_t      partnumber;
  • libs/libmythtv/eitfixup.cpp

     
    2222      m_ukCC("\\[(AD)(,(S)){,1}(,SL){,1}\\]|\\[(S)(,AD){,1}(,SL){,1}\\]|"
    2323             "\\[(SL)(,AD){,1}(,(S)){,1}\\]"),
    2424      m_ukYear("[\\[\\(]([\\d]{4})[\\)\\]]"),
    25       m_comHemCountry("^(.+)\\.\\s(.+)\\.\\s(?:([0-9]{2,4})\\.\\s*)?"),
    26       m_comHemPEnd("\\.$"),
     25      m_comHemCountry("^(\\(.+\\))?\\s?([^ ]+)\\s([^\\.0-9]+)(?:\\sfrån\\s([0-9]{4}))(?:\\smed\\s([^\\.]+))?\\.?"),
    2726      m_comHemDirector("[Rr]egi"),
    28       m_comHemActor("[Ss]kådespelare"),
    29       m_comHemSub("[.\?] "),
     27      m_comHemActor("[Ss]kådespelare|[Ii] rollerna"),
     28      m_comHemHost("[Pp]rogramledare"),
     29      m_comHemSub("[.\\?\\!] "),
    3030      m_comHemRerun1("[Rr]epris\\sfrån\\s([^\\.]+)(?:\\.|$)"),
    31       m_comHemRerun2("([0-9]+)/([0-9]+)(?:\\s-\\s([0-9]{4}))?")
     31      m_comHemRerun2("([0-9]+)/([0-9]+)(?:\\s-\\s([0-9]{4}))?"),
     32      m_comHemTT("[Tt]ext-[Tt][Vv]"),
     33      m_comHemPersSeparator("(, |\\soch\\s)"),
     34      m_comHemPersons("\\s?([Rr]egi|[Ss]kådespelare|[Pp]rogramledare|[Ii] rollerna):\\s([^\\.]+)\\."),
     35      m_comHemSubEnd("\\s?\\.\\s?$"),
     36      m_comHemSeries1("\\s?(?:[dD]el|[eE]pisode)\\s([0-9]+)(?:\\s?(?:/|:|av)\\s?([0-9]+))?\\."),
     37      m_comHemSeries2("\\s?-?\\s?([Dd]el\\s+([0-9]+))"),
     38      m_comHemTSub("\\s+-\\s+([^\\-]+)")
    3239{
    3340}
    3441
     
    370377 */
    371378void EITFixUp::FixComHem(DBEvent &event, bool process_subtitle) const
    372379{
    373     // the format of the subtitle is:
    374     // country. category. year.
    375     // the year is optional and if the subtitle is
    376     // empty the same information is in the Description instead.
    377 
    378     if (event.subtitle.length() == 0 && event.description.length() > 0)
     380    // Reverse what EITFixUp::Fix() did
     381    if (event.subtitle.isEmpty() && !event.description.isEmpty())
    379382    {
    380383        event.subtitle = event.description;
    381384        event.description = "";
    382385    }
    383386
    384     // try to find country category and year
    385     QRegExp tmpCountry = m_comHemCountry;
    386     int pos = tmpCountry.search(event.subtitle);
    387     if (pos != -1)
     387    // Remove subtitle, it contains the category and we already know that
     388    event.subtitle = "";
     389
     390    bool isSeries = false;
     391    // Try to find episode numbers
     392    int pos;
     393    QRegExp tmpSeries1 = m_comHemSeries1;
     394    QRegExp tmpSeries2 = m_comHemSeries2;
     395    if ((pos = tmpSeries2.search(event.title)) != -1)
    388396    {
    389         QStringList list = tmpCountry.capturedTexts();
    390 
    391         // sometimes the category is empty, in that case use the category from
    392         // the subtitle. this category is in swedish and all others
    393         // are in english
    394         if (event.category.length() == 0)
     397        QStringList list = tmpSeries2.capturedTexts();
     398        event.partnumber = list[2].toUInt();
     399        event.title = event.title.replace(list[0],"");
     400    }
     401    else if ((pos = tmpSeries1.search(event.description)) != -1)
     402    {
     403        QStringList list = tmpSeries1.capturedTexts();
     404        if (!list[1].isEmpty())
    395405        {
    396             event.category = list[2].stripWhiteSpace();
     406            event.partnumber = list[1].toUInt();
    397407        }
     408        if (!list[2].isEmpty())
     409        {
     410            event.parttotal = list[2].toUInt();
     411        }
    398412
    399         if (list[3].length() > 0)
     413        // Remove the episode numbers, but only if it's not at the begining
     414        // of the description (subtitle code might use it)
     415        if(pos > 0)
     416            event.description = event.description.replace(list[0],"");
     417        isSeries = true;
     418    }
     419
     420    // Add partnumber/parttotal to subtitle
     421    // This will be overwritten if we find a better subtitle
     422    if (event.partnumber > 0)
     423    {
     424        event.subtitle = QString("Del %1").arg(event.partnumber);
     425        if (event.parttotal > 0)
    400426        {
    401             bool ok;
    402             uint y = list[3].stripWhiteSpace().toUInt(&ok);
    403             if (ok)
    404                 event.originalairdate = QDate(y, 1, 1);
     427            event.subtitle += QString(" av %1").arg(event.parttotal);
    405428        }
     429    }
    406430
    407         // not 100% sure about this one.
    408         event.subtitle = "";
     431    // Move subtitle info from title to subtitle
     432    QRegExp tmpTSub = m_comHemTSub;
     433    if (tmpTSub.search(event.title) != -1)
     434    {
     435        event.subtitle = tmpTSub.cap(1);
     436        event.title = event.title.replace(tmpTSub.cap(0),"");
    409437    }
    410438
     439    // No need to continue without a description.
    411440    if (event.description.length() <= 0)
    412441        return;
    413442
    414     // everything up to the first 3 spaces is duplicated from title and
    415     // subtitle so remove it
    416     pos = event.description.find("   ");
     443    // Try to find country category, year and possibly other information
     444    // from the begining of the description
     445    QRegExp tmpCountry = m_comHemCountry;
     446    pos = tmpCountry.search(event.description);
    417447    if (pos != -1)
    418448    {
    419         event.description =
    420             event.description.mid(pos + 3).stripWhiteSpace();
    421         //fprintf(stdout, "EITFixUp::FixStyle4: New: %s\n",
    422         //event.description.mid(pos + 3).stripWhiteSpace().ascii());
    423     }
     449        QStringList list = tmpCountry.capturedTexts();
     450        QString replacement;
    424451
    425     // in the description at this point everything up to the first 4 spaces
    426     // in a row is a list of director(s) and actors.
    427     // different lists are separated by 3 spaces in a row
    428     // end of all lists is when there is 4 spaces in a row
    429     bool bDontRemove = false;
    430     pos = event.description.find("    ");
    431     if (pos != -1)
    432     {
    433         QStringList lists;
    434         lists = QStringList::split("   ", event.description.left(pos));
    435         QStringList::iterator it;
    436         for (it = lists.begin(); it != lists.end(); it++)
     452        // Original title, usually english title
     453        // note: list[1] contains extra () around the text that needs removing
     454        if (list[1].length() > 0)
    437455        {
    438             (*it).remove(m_comHemPEnd);
    439             QStringList list = QStringList::split(": ", *it);
    440             if (list.count() != 2)
     456            replacement = list[1] + " ";
     457            //store it somewhere?
     458        }
     459
     460        // Countr(y|ies)
     461        if (list[2].length() > 0)
     462        {
     463            replacement += list[2] + " ";
     464            //store it somewhere?
     465        }
     466
     467        // Category
     468        if (list[3].length() > 0)
     469        {
     470            replacement += list[3] + ".";
     471            if(event.category.isEmpty())
    441472            {
    442                 // oops, improperly formated list, ignore it
    443                 //fprintf(stdout,"EITFixUp::FixStyle4:"
    444                 //"%s is not a properly formated list of persons\n",
    445                 //(*it).ascii());
    446                 bDontRemove = true;
    447                 continue;
     473                event.category = list[3];
    448474            }
    449475
    450             if (list[0].find(m_comHemDirector) != -1)
     476            if(list[3].find("serie")!=-1)
    451477            {
    452                 // director(s)
    453                 QStringList persons = QStringList::split(", ",list[1]);
    454                 for (QStringList::const_iterator it2 = persons.begin();
    455                      it2 != persons.end(); it2++)
    456                 {
    457                     event.AddPerson(DBPerson::kDirector, *it2);
    458                 }
    459                 continue;
     478                isSeries = true;
    460479            }
     480        }
    461481
    462             if (list[0].find(m_comHemActor) != -1)
     482        // Year
     483        if (list[4].length() > 0)
     484        {
     485            event.airdate = list[4].stripWhiteSpace();
     486        }
     487
     488        // Actors
     489        if (list[5].length() > 0)
     490        {
     491            QStringList actors;
     492            actors=QStringList::split(m_comHemPersSeparator,list[5]);
     493            for(QStringList::size_type i=0;i<actors.count();i++)
    463494            {
    464                 // actor(s)
    465                 QStringList persons = QStringList::split(", ", list[1]);
    466                 for (QStringList::const_iterator it2 = persons.begin();
    467                      it2 != persons.end(); it2++)
    468                 {
    469                     event.AddPerson(DBPerson::kActor, *it2);
    470                 }
    471                 continue;
     495                event.AddPerson(DBPerson::kActor, actors[i]);
    472496            }
     497        }
    473498
    474             // unknown type, posibly a new one that
    475             // this code shoud be updated to handle
    476             VERBOSE(VB_EIT, "EITFixUp::FixComHem: " +
    477                     QString("%1 is not actor or director")
    478                     .arg(list[0]));
    479             bDontRemove = true;
     499        // Remove year and actors.
     500        // The reason category is left in the description is because otherwise
     501        // the country would look wierd like "Amerikansk. Rest of description."
     502        event.description = event.description.replace(list[0],replacement);
     503    }
     504
     505    if (isSeries)
     506        event.category_type = kCategorySeries;
     507
     508    // Look for additional persons in the description
     509    QRegExp tmpPersons = m_comHemPersons;
     510    while(pos = tmpPersons.search(event.description),pos!=-1)
     511    {
     512        DBPerson::Role role;
     513        QStringList list = tmpPersons.capturedTexts();
     514       
     515        QRegExp tmpDirector = m_comHemDirector;
     516        QRegExp tmpActor = m_comHemActor;
     517        QRegExp tmpHost = m_comHemHost;
     518        if (tmpDirector.search(list[1])!=-1)
     519        {
     520            role = DBPerson::kDirector;
    480521        }
    481         // remove list of persons from description if
    482         // we coud parse it properly
    483         if (!bDontRemove)
     522        else if(tmpActor.search(list[1])!=-1)
    484523        {
    485             event.description = event.description.mid(pos).stripWhiteSpace();
     524            role = DBPerson::kActor;
    486525        }
    487     }
     526        else if(tmpHost.search(list[1])!=-1)
     527        {
     528            role = DBPerson::kHost;
     529        }
    488530
    489     //fprintf(stdout, "EITFixUp::FixStyle4: Number of persons: %d\n",
    490     //event.Credits.count());
     531        QStringList actors;
     532        actors = QStringList::split(m_comHemPersSeparator, list[2]);
     533        for(QStringList::size_type i=0;i<actors.count();i++)
     534        {
     535            event.AddPerson(role, actors[i]);
     536        }
    491537
    492     /*
    493       a regexp like this coud be used to get the episode number, shoud be at
    494       the begining of the description
    495       "^(?:[dD]el|[eE]pisode)\\s([0-9]+)(?:\\s?(?:/|:|av)\\s?([0-9]+))?\\."
    496     */
     538        // Remove it
     539        event.description=event.description.replace(list[0],"");
     540    }
    497541
    498542    // Is this event on a channel we shoud look for a subtitle?
     543    // The subtitle is the first sentence in the description, but the
     544    // subtitle can't be the only thing in the description and it must be
     545    // shorter than 55 characters or we risk picking up the wrong thing.
    499546    if (process_subtitle)
    500547    {
    501548        int pos = event.description.find(m_comHemSub);
     
    508555        }
    509556    }
    510557
     558    // Teletext subtitles?
     559    int position = event.description.find(m_comHemTT);
     560    if (position != -1)
     561    {
     562        event.flags |= DBEvent::kSubtitled;
     563    }
     564
    511565    // Try to findout if this is a rerun and if so the date.
    512566    QRegExp tmpRerun1 = m_comHemRerun1;
    513567    if (tmpRerun1.search(event.description) == -1)
    514568        return;
    515569
     570    // Rerun from today
    516571    QStringList list = tmpRerun1.capturedTexts();
    517572    if (list[1] == "i dag")
    518573    {
     
    520575        return;
    521576    }
    522577
     578    // Rerun from yesterday afternoon
    523579    if (list[1] == "eftermiddagen")
    524580    {
    525581        event.originalairdate = event.starttime.date().addDays(-1);
    526582        return;
    527583    }
    528584
     585    // Rerun with day, month and possibly year specified
    529586    QRegExp tmpRerun2 = m_comHemRerun2;
    530587    if (tmpRerun2.search(list[1]) != -1)
    531588    {
     
    546603            if (date > event.starttime.date())
    547604                date = date.addYears(-1);
    548605            event.originalairdate = date;
    549             //fprintf(stdout, "EITFixUp::FixStyle4: "
    550             //"OriginalAirDate set to: %s for '%s'\n",
    551             //event.OriginalAirDate.toString(Qt::ISODate).ascii(),
    552             //event.description.ascii());
    553606        }
    554607        return;
    555608    }
    556     // unknown date, posibly only a year.
    557     //fprintf(stdout,"EITFixUp::FixStyle4: "
    558     //"unknown rerun date: %s\n",list[1].ascii());
    559609}
    560610
    561611/** \fn EITFixUp::FixAUStar(DBEvent&) const
  • libs/libmythtv/eithelper.cpp

     
    201201void EITHelper::AddEIT(const DVBEventInformationTable *eit)
    202202{
    203203    uint descCompression = (eit->TableID() > 0x80) ? 2 : 1;
    204     uint fix = fixup[eit->OriginalNetworkID() << 16];
     204    uint fix = fixup[(int)eit->OriginalNetworkID() << 16];
    205205    fix |= fixup[(((uint64_t)eit->TSID()) << 32) |
    206206                 (eit->OriginalNetworkID() << 16)];
    207     fix |= fixup[(eit->OriginalNetworkID() << 16) | eit->ServiceID()];
     207    fix |= fixup[(((int)eit->OriginalNetworkID()) << 16) | ((int)eit->ServiceID())];
    208208    fix |= EITFixUp::kFixGenericDVB;
    209209
    210210    uint networkid = eit->OriginalNetworkID();
     
    452452    {
    453453        // Check to see if we are interseted in this channel
    454454        bool useOnAirGuide = query.value(1).toBool();
    455         return (useOnAirGuide) ? query.value(0).toInt() : -1;       
     455        return (useOnAirGuide) ? query.value(0).toInt() : -1;
    456456    }
    457457
    458458    return -1;
  • libs/libmythtv/eitfixup.h

     
    6767    const QRegExp m_ukCC;
    6868    const QRegExp m_ukYear;
    6969    const QRegExp m_comHemCountry;
    70     const QRegExp m_comHemPEnd;
    7170    const QRegExp m_comHemDirector;
    7271    const QRegExp m_comHemActor;
     72    const QRegExp m_comHemHost;
    7373    const QRegExp m_comHemSub;
    7474    const QRegExp m_comHemRerun1;
    7575    const QRegExp m_comHemRerun2;
     76    const QRegExp m_comHemTT;
     77    const QRegExp m_comHemPersSeparator;
     78    const QRegExp m_comHemPersons;
     79    const QRegExp m_comHemSubEnd;
     80    const QRegExp m_comHemSeries1;
     81    const QRegExp m_comHemSeries2;
     82    const QRegExp m_comHemTSub;
    7683};
    7784
    7885#endif // EITFIXUP_H