Ticket #13159: mythtv-13159-PreferExactTitleMatchesForMetadata.patch

File mythtv-13159-PreferExactTitleMatchesForMetadata.patch, 6.2 KB (added by simon.sinister@…, 6 years ago)

This patch provides better selection of metadata

  • mythtv/libs/libmythmetadata/metadatacommon.cpp

    diff --git a/mythtv/libs/libmythmetadata/metadatacommon.cpp b/mythtv/libs/libmythmetadata/metadatacommon.cpp
    index d28d54e..14f1a9e 100644
    a b MetadataLookup::MetadataLookup( 
    219219    m_artwork(artwork),
    220220    m_downloads(downloads)
    221221{
     222    QString manRecSuffix = QString(" (%1)").arg(QObject::tr("Manual Record"));
     223    m_base_title = title;
     224    m_base_title.replace(manRecSuffix,"");
    222225}
    223226
    224227// ProgramInfo-style constructor
    MetadataLookup::MetadataLookup( 
    312315    m_popularity = 0;
    313316    m_budget = 0;
    314317    m_revenue = 0;
     318    QString manRecSuffix = QString(" (%1)").arg(QObject::tr("Manual Record"));
     319    m_base_title = title;
     320    m_base_title.replace(manRecSuffix,"");
    315321}
    316322
    317323// XBMC NFO-style constructor
    MetadataLookup::MetadataLookup( 
    388394    m_artwork(artwork),
    389395    m_downloads(downloads)
    390396{
     397    QString manRecSuffix = QString(" (%1)").arg(QObject::tr("Manual Record"));
     398    m_base_title = title;
     399    m_base_title.replace(manRecSuffix,"");
    391400}
    392401
    393402MetadataLookup::~MetadataLookup()
  • mythtv/libs/libmythmetadata/metadatadownload.cpp

    diff --git a/mythtv/libs/libmythmetadata/metadatadownload.cpp b/mythtv/libs/libmythmetadata/metadatadownload.cpp
    index bf5d4fb..5c6194b 100644
    a b MetadataLookup* MetadataDownload::findBestMatch(MetadataLookupList list, 
    204204{
    205205    QStringList titles;
    206206    MetadataLookup *ret = NULL;
     207    QDate exactTitleDate;
    207208
    208209    // Build a list of all the titles
    209210    int exactMatches = 0;
    210211    for (MetadataLookupList::const_iterator i = list.begin();
    211212            i != list.end(); ++i)
    212213    {
    213         QString title = (*i)->GetBaseTitle();
    214         if (title == originaltitle)
     214        QString title = (*i)->GetTitle();
     215        LOG(VB_GENERAL, LOG_INFO, QString("Comparing metadata title '%1' to recording title '%2'")
     216                .arg(title)
     217                .arg(originaltitle));
     218        if (QString::compare(title, originaltitle, Qt::CaseInsensitive) == 0)
    215219        {
    216             ret = (*i);
     220            // We have an exact match on the title (ignoring case). After
     221            // the first exact match, prefer any more recently released one.
     222            if ((ret == NULL) || ((*i)->GetReleaseDate() > exactTitleDate))
     223            {
     224                exactTitleDate = (*i)->GetReleaseDate();
     225                ret = (*i);
     226            }
    217227            exactMatches++;
    218228        }
    219229
    MetadataLookup* MetadataDownload::findBestMatch(MetadataLookupList list, 
    226236    {
    227237        if (exactMatches == 1)
    228238        {
    229             LOG(VB_GENERAL, LOG_INFO, QString("Single Exact Title Match For %1")
     239            LOG(VB_GENERAL, LOG_INFO, QString("Single exact title match for '%1'")
    230240                    .arg(originaltitle));
    231             return ret;
    232241        }
    233242        else
    234243        {
    235             LOG(VB_GENERAL, LOG_ERR,
    236                 QString("Multiple exact title matches found for %1. "
    237                         "Need to match on other criteria.")
    238                     .arg(originaltitle));
    239             return NULL;
     244            LOG(VB_GENERAL, LOG_INFO,
     245                QString("Multiple exact title matches found for '%1'. "
     246                        "Selecting most recent [%2]")
     247                    .arg(originaltitle)
     248                    .arg(exactTitleDate.toString()));
    240249        }
     250        return ret;
    241251    }
    242252
    243253    // Apply Levenshtein distance algorithm to determine closest match
    MetadataLookup* MetadataDownload::findBestMatch(MetadataLookupList list, 
    260270    MetadataLookupList::const_iterator i = list.begin();
    261271    for (; i != list.end(); ++i)
    262272    {
    263         if ((*i)->GetBaseTitle() == bestTitle)
     273        if ((*i)->GetTitle() == bestTitle)
    264274        {
    265275            ret = (*i);
    266276            break;
  • mythtv/programs/mythmetadatalookup/lookup.cpp

    diff --git a/mythtv/programs/mythmetadatalookup/lookup.cpp b/mythtv/programs/mythmetadatalookup/lookup.cpp
    index 6de23a1..eb3c2ab 100644
    a b void LookerUpper::customEvent(QEvent *levent) 
    246246        if (list.count() > 1)
    247247        {
    248248            int yearindex = -1;
     249            MetadataLookup *exactTitleMeta = NULL;
     250            QDate exactTitleDate;
    249251
    250252            for (int p = 0; p != list.size(); ++p)
    251253            {
    252254                ProgramInfo *pginfo = list[p]->GetData().value<ProgramInfo *>();
    253255
     256                if (pginfo && (QString::compare(pginfo->GetTitle(), list[p]->GetBaseTitle(), Qt::CaseInsensitive)) == 0)
     257                {
     258                    // We have an exact match on the title (ignoring case)
     259                    if ((exactTitleMeta == NULL) ||
     260                        (list[p]->GetReleaseDate() > exactTitleDate))
     261                    {
     262                        // remember the most recently released exact match
     263                        exactTitleDate = list[p]->GetReleaseDate();
     264                        exactTitleMeta = list[p];
     265                    }
     266                }
     267
    254268                if (pginfo && !pginfo->GetSeriesID().isEmpty() &&
    255269                    pginfo->GetSeriesID() == (list[p])->GetTMSref())
    256270                {
    void LookerUpper::customEvent(QEvent *levent) 
    291305                return;
    292306            }
    293307
     308            if (exactTitleMeta != NULL)
     309            {
     310                LOG(VB_GENERAL, LOG_INFO, QString("Most recent exact match released %1").arg(exactTitleDate.toString()));
     311                MetadataLookup *lookup = exactTitleMeta;
     312                ProgramInfo *pginfo = exactTitleMeta->GetData().value<ProgramInfo *>();
     313                if (lookup->GetSubtype() != kProbableGenericTelevision)
     314                    pginfo->SaveSeasonEpisode(lookup->GetSeason(), lookup->GetEpisode());
     315                pginfo->SaveInetRef(lookup->GetInetref());
     316                m_busyRecList.removeAll(pginfo);
     317                return;
     318            }
     319
    294320            LOG(VB_GENERAL, LOG_INFO, "Unable to match this title, too many possible matches. "
    295321                                      "You may wish to manually set the season, episode, and "
    296322                                      "inetref in the 'Watch Recordings' screen.");