Go to the documentation of this file.
5 #include <QCoreApplication>
23 (QEvent::Type) QEvent::registerEventType();
26 (QEvent::Type) QEvent::registerEventType();
105 else if (!nfo.isEmpty())
152 if (list.count() == 1 && list[0]->GetStep() ==
kLookupSearch)
169 if (list[0]->GetAutomatic() && list.count() > 1
194 if (qEnvironmentVariableIsSet(
"EXPERIMENTAL_METADATA_GRAB"))
212 QCoreApplication::postEvent(
m_parent,
217 LOG(VB_GENERAL, LOG_INFO,
218 QString(
"Returning Metadata Results: %1 %2 %3")
221 QCoreApplication::postEvent(
m_parent,
228 LOG(VB_GENERAL, LOG_INFO,
229 QString(
"Metadata Lookup Failed: No Results %1 %2 %3")
237 QCoreApplication::postEvent(
m_parent,
247 const QString &originaltitle,
250 unsigned int exactMatches = 0;
251 unsigned int exactMatchesWithArt = 0;
253 for (
auto lkup : qAsConst(list))
256 if ((QString::compare(lkup->GetTitle(), originaltitle, Qt::CaseInsensitive) == 0))
264 exactMatchesWithArt++;
271 return exactMatchesWithArt;
276 const QString &originaltitle)
280 QDate exactTitleDate;
281 float exactTitlePopularity = 0.0F;
282 int exactMatches = 0;
283 int exactMatchesWithArt = 0;
284 bool foundMatchWithArt =
false;
287 for (
auto lkup : qAsConst(list))
289 QString
title = lkup->GetTitle();
290 LOG(VB_GENERAL, LOG_INFO, QString(
"Comparing metadata title '%1' [%2] to recording title '%3'")
292 .
arg(lkup->GetReleaseDate().toString())
293 .arg(originaltitle));
295 if (QString::compare(
title, originaltitle, Qt::CaseInsensitive) == 0)
297 bool hasArtwork = ((!(lkup->GetArtwork(
kArtworkFanart)).empty()) ||
301 LOG(VB_GENERAL, LOG_INFO, QString(
"'%1', popularity = %2, ReleaseDate = %3")
303 .
arg(lkup->GetPopularity())
304 .arg(lkup->GetReleaseDate().toString()));
312 if ((ret ==
nullptr) ||
314 ((!foundMatchWithArt) ||
315 ((lkup->GetPopularity() > exactTitlePopularity)) ||
316 ((exactTitlePopularity == 0.0F) && (lkup->GetReleaseDate() > exactTitleDate)))))
318 exactTitleDate = lkup->GetReleaseDate();
319 exactTitlePopularity = lkup->GetPopularity();
325 foundMatchWithArt =
true;
326 exactMatchesWithArt++;
330 titles.append(
title);
333 LOG(VB_GENERAL, LOG_DEBUG, QString(
"exactMatches = %1, exactMatchesWithArt = %2")
335 .
arg(exactMatchesWithArt));
339 if (exactMatches > 0)
341 if (exactMatches == 1)
343 LOG(VB_GENERAL, LOG_INFO, QString(
"Single exact title match for '%1'")
344 .
arg(originaltitle));
348 LOG(VB_GENERAL, LOG_INFO,
349 QString(
"Multiple exact title matches found for '%1'. "
350 "Selecting most popular or most recent [%2]")
352 .
arg(exactTitleDate.toString()));
358 QString bestTitle =
nearestName(originaltitle, titles);
361 if (bestTitle.isEmpty())
363 LOG(VB_GENERAL, LOG_ERR,
364 QString(
"No adequate match or multiple "
365 "matches found for %1. Update manually.")
366 .
arg(originaltitle));
370 LOG(VB_GENERAL, LOG_INFO, QString(
"Best Title Match For %1: %2")
371 .
arg(originaltitle).
arg(bestTitle));
374 for (
auto item : qAsConst(list))
376 if (item->GetTitle() == bestTitle)
393 LOG(VB_GENERAL, LOG_INFO, QString(
"Running Grabber: %1 %2")
398 QByteArray result = grabber.
ReadAll();
399 if (!result.isEmpty())
402 doc.setContent(result,
true);
403 QDomElement
root =
doc.documentElement();
404 QDomElement item =
root.firstChildElement(
"item");
406 while (!item.isNull())
412 item = item.nextSiblingElement(
"item");
442 LOG(VB_GENERAL, LOG_INFO,
443 QString(
"Movie grabber not functional. Aborting this run."));
454 LOG(VB_GENERAL, LOG_INFO,
455 QString(
"Television grabber not functional. Aborting this run."));
468 LOG(VB_GENERAL, LOG_INFO,
469 QString(
"Matching MXML file found. Parsing %1 for metadata...")
480 bool loaded = rf->SaveAs(mxmlraw);
484 if (
doc.setContent(mxmlraw,
true))
487 QDomElement
root =
doc.documentElement();
488 item =
root.firstChildElement(
"item");
492 LOG(VB_GENERAL, LOG_ERR,
493 QString(
"Corrupt or invalid MXML file."));
515 LOG(VB_GENERAL, LOG_INFO,
516 QString(
"Matching NFO file found. Parsing %1 for metadata...")
529 bool loaded = rf->SaveAs(nforaw);
535 if (
doc.setContent(nforaw,
true))
538 item =
doc.documentElement();
542 LOG(VB_GENERAL, LOG_ERR,
543 QString(
"Invalid NFO file found."));
653 bool searchcollection =
false;
677 searchcollection =
true;
679 else if (list.isEmpty())
685 searchcollection =
true;
713 if (!searchcollection && list.isEmpty() &&
726 for (
auto it = list.begin(); it != list.end(); ++it)
728 (*it)->SetIsCollection(searchcollection);
750 if (list.count() == 1)
781 if (origseason == 0 && origepisode == 0)
789 if (list.count() == 1)
809 QString ext = QFileInfo(qurl.path()).suffix();
814 newname =
filename +
"/" + QFileInfo(qurl.path()).fileName() +
"." +
type;
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
static void error(const char *str,...)
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
QDomDocument doc("MYTHARCHIVEITEM")
static bool Exists(const QString &url, struct stat *fileinfo)
RefCountHandler< T > takeFirstAndDecr(void)
Removes the first item in the list and returns it.
arg(title).arg(filename).arg(doDelete))
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
void Run(time_t timeout=0)
Runs a command inside the /bin/sh shell. Returns immediately.
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
T * takeFirst(void)
Removes the first item in the list and returns it.
bool isRunning(void) const
bool wait(unsigned long time=ULONG_MAX)
Wait for the MThread to exit, with a maximum timeout.
virtual int IncrRef(void)
Increments reference count.
@ kMSStdOut
allow access to stdout
uint Wait(time_t timeout=0)