Skip to content

Commit

Permalink
Merge pull request #249 from rcrdnalor/issue#248
Browse files Browse the repository at this point in the history
Issue#248
  • Loading branch information
rcrdnalor committed Oct 6, 2020
2 parents 7cfaf8f + 75cf256 commit d3c5e98
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 75 deletions.
146 changes: 74 additions & 72 deletions mythtv/libs/libmythmetadata/metadatadownload.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// C/C++
#include <cstdlib>

// qt
#include <QCoreApplication>
#include <QEvent>
Expand Down Expand Up @@ -90,43 +93,51 @@ void MetadataDownload::run()
if (lookup->GetType() == kMetadataVideo ||
lookup->GetType() == kMetadataRecording)
{
if (lookup->GetSubtype() == kProbableTelevision)
// First, look for mxml and nfo files in video storage groups
if (lookup->GetType() == kMetadataVideo &&
!lookup->GetFilename().isEmpty())
{
list = handleTelevision(lookup);
if (findExactMatchCount(list, lookup->GetBaseTitle(), true) == 0)
{
// There are no exact match prospects with artwork from TV search,
// so add in movies, where we might find a better match.
list.append(handleMovie(lookup));
}
QString mxml = getMXMLPath(lookup->GetFilename());
QString nfo = getNFOPath(lookup->GetFilename());

if (!mxml.isEmpty())
list = readMXML(mxml, lookup);
else if (!nfo.isEmpty())
list = readNFO(nfo, lookup);
}
else if (lookup->GetSubtype() == kProbableMovie)

// If nothing found, create lookups based on filename
if (list.isEmpty())
{
list = handleMovie(lookup);
if (findExactMatchCount(list, lookup->GetBaseTitle(), true) == 0)
if (lookup->GetSubtype() == kProbableTelevision)
{
// There are no exact match prospects with artwork from Movie search
// so add in television, where we might find a better match.
list.append(handleTelevision(lookup));
list = handleTelevision(lookup);
if ((findExactMatchCount(list, lookup->GetBaseTitle(), true) == 0) ||
(list.size() > 1 && !lookup->GetAutomatic()))
{
// There are no exact match prospects with artwork from TV search,
// so add in movies, where we might find a better match.
// In case of manual mode and ambiguous result, add it as well.
list.append(handleMovie(lookup));
}
}
else if (lookup->GetSubtype() == kProbableMovie)
{
list = handleMovie(lookup);
if ((findExactMatchCount(list, lookup->GetBaseTitle(), true) == 0) ||
(list.size() > 1 && !lookup->GetAutomatic()))
{
// There are no exact match prospects with artwork from Movie search
// so add in television, where we might find a better match.
// In case of manual mode and ambiguous result, add it as well.
list.append(handleTelevision(lookup));
}
}
else
{
// will try both movie and TV
list = handleVideoUndetermined(lookup);
}
}
else
{
// will try both movie and TV
list = handleVideoUndetermined(lookup);
}

if ((list.isEmpty() ||
(list.size() > 1 && !lookup->GetAutomatic())) &&
lookup->GetSubtype() == kProbableTelevision)
{
list.append(handleMovie(lookup));
}
else if ((list.isEmpty() ||
(list.size() > 1 && !lookup->GetAutomatic())) &&
lookup->GetSubtype() == kProbableMovie)
{
list.append(handleTelevision(lookup));
}
}
else if (lookup->GetType() == kMetadataGame)
Expand Down Expand Up @@ -163,6 +174,8 @@ void MetadataDownload::run()
{
MetadataLookup *newlookup = bestLookup;

// pass through automatic type
newlookup->SetAutomatic(true);
// bestlookup is owned by list, we need an extra reference
newlookup->IncrRef();
newlookup->SetStep(kLookupData);
Expand All @@ -176,8 +189,31 @@ void MetadataDownload::run()
continue;
}

QCoreApplication::postEvent(m_parent,
new MetadataLookupFailure(MetadataLookupList() << lookup));
// Experimental:
// If nothing matches, always return the first found item
if (getenv("EXPERIMENTAL_METADATA_GRAB"))
{
MetadataLookup *newlookup = list.takeFirst();

// pass through automatic type
newlookup->SetAutomatic(true); // ### XXX RER
newlookup->SetStep(kLookupData);
// Type may have changed
LookupType ret = GuessLookupType(newlookup);
if (ret != kUnknownVideo)
{
newlookup->SetSubtype(ret);
}
prependLookup(newlookup);
continue;
}
else
{
// nothing more we can do in automatic mode
QCoreApplication::postEvent(m_parent,
new MetadataLookupFailure(MetadataLookupList() << lookup));
continue;
}
}

LOG(VB_GENERAL, LOG_INFO,
Expand Down Expand Up @@ -565,32 +601,15 @@ MetadataLookupList MetadataDownload::handleGame(MetadataLookup *lookup)
/**
* handleMovie:
* attempt to find movie data via the following (in order)
* 1- Local MXML
* 2- Local NFO
* 1- Local MXML: already done before
* 2- Local NFO: already done
* 3- By title
* 4- By inetref (if present)
*/
MetadataLookupList MetadataDownload::handleMovie(MetadataLookup *lookup)
{
MetadataLookupList list;

QString mxml;
QString nfo;

if (!lookup->GetFilename().isEmpty())
{
mxml = getMXMLPath(lookup->GetFilename());
nfo = getNFOPath(lookup->GetFilename());
}

if (!mxml.isEmpty())
list = readMXML(mxml, lookup);
else if (!nfo.isEmpty())
list = readNFO(nfo, lookup);

if (!list.isEmpty())
return list;

MetaGrabberScript grabber =
MetaGrabberScript::GetGrabber(kGrabberMovie, lookup);

Expand Down Expand Up @@ -619,8 +638,8 @@ MetadataLookupList MetadataDownload::handleMovie(MetadataLookup *lookup)
/**
* handleTelevision
* attempt to find television data via the following (in order)
* 1- Local MXML
* 2- Local NFO
* 1- Local MXML: already done before
* 2- Local NFO: already done
* 3- By inetref with subtitle
* 4- By inetref with season and episode
* 5- By inetref
Expand All @@ -631,23 +650,6 @@ MetadataLookupList MetadataDownload::handleTelevision(MetadataLookup *lookup)
{
MetadataLookupList list;

QString mxml;
QString nfo;

if (!lookup->GetFilename().isEmpty())
{
mxml = getMXMLPath(lookup->GetFilename());
nfo = getNFOPath(lookup->GetFilename());
}

if (!mxml.isEmpty())
list = readMXML(mxml, lookup);
else if (!nfo.isEmpty())
list = readNFO(nfo, lookup);

if (!list.isEmpty())
return list;

MetaGrabberScript grabber =
MetaGrabberScript::GetGrabber(kGrabberTelevision, lookup);
bool searchcollection = false;
Expand Down
27 changes: 25 additions & 2 deletions mythtv/programs/mythfrontend/videodlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
// for ImageDLFailureEvent
#include "metadataimagedownload.h"

#define LOC_MML QString("Manual Metadata Lookup: ")

static const QString sLocation = "MythVideo";

namespace
Expand Down Expand Up @@ -3503,12 +3505,33 @@ void VideoDialog::ToggleWatched()
}
}

void VideoDialog::OnVideoSearchListSelection(const RefCountHandler<MetadataLookup>& lookup)
void VideoDialog::OnVideoSearchListSelection(RefCountHandler<MetadataLookup> lookup)
{
if (!lookup)
return;

OnVideoSearchDone(lookup);
if(!lookup->GetInetref().isEmpty() && lookup->GetInetref() != "00000000")
{
LOG(VB_GENERAL, LOG_INFO, LOC_MML +
QString("Selected Item: Type: %1%2 : Subtype: %3%4%5 : InetRef: %6")
.arg(lookup->GetType() == kMetadataVideo ? "Video" : "")
.arg(lookup->GetType() == kMetadataRecording ? "Recording" : "")
.arg(lookup->GetSubtype() == kProbableMovie ? "Movie" : "")
.arg(lookup->GetSubtype() == kProbableTelevision ? "Television" : "")
.arg(lookup->GetSubtype() == kUnknownVideo ? "Unknown" : "")
.arg(lookup->GetInetref()));

lookup->SetStep(kLookupData);
lookup->IncrRef();
m_metadataFactory->Lookup(lookup);
}
else
{
LOG(VB_GENERAL, LOG_ERR, LOC_MML +
QString("Selected Item has no InetRef Number!"));

OnVideoSearchDone(lookup);
}
}

void VideoDialog::OnParentalChange(int amount)
Expand Down
2 changes: 1 addition & 1 deletion mythtv/programs/mythfrontend/videodlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class VideoDialog : public MythScreenType
void OnParentalChange(int amount);

// Called when the underlying data for an item changes
void OnVideoSearchListSelection(const RefCountHandler<MetadataLookup>& lookup);
void OnVideoSearchListSelection(RefCountHandler<MetadataLookup> lookup);

void doVideoScan();

Expand Down

0 comments on commit d3c5e98

Please sign in to comment.