Go to the documentation of this file.
5 #include <QCoreApplication>
24 (QEvent::Type) QEvent::registerEventType();
27 (QEvent::Type) QEvent::registerEventType();
106 else if (!nfo.isEmpty())
153 if (list.count() == 1 && list[0]->GetStep() ==
kLookupSearch)
170 if (list[0]->GetAutomatic() && list.count() > 1
195 if (qEnvironmentVariableIsSet(
"EXPERIMENTAL_METADATA_GRAB"))
213 QCoreApplication::postEvent(
m_parent,
218 LOG(VB_GENERAL, LOG_INFO,
219 QString(
"Returning Metadata Results: %1 %2 %3")
222 QCoreApplication::postEvent(
m_parent,
229 LOG(VB_GENERAL, LOG_INFO,
230 QString(
"Metadata Lookup Failed: No Results %1 %2 %3")
238 QCoreApplication::postEvent(
m_parent,
248 const QString &originaltitle,
251 unsigned int exactMatches = 0;
252 unsigned int exactMatchesWithArt = 0;
254 for (
const auto& lkup : qAsConst(list))
257 if ((QString::compare(lkup->GetTitle(), originaltitle, Qt::CaseInsensitive) == 0))
265 exactMatchesWithArt++;
272 return exactMatchesWithArt;
277 const QString &originaltitle)
281 QDate exactTitleDate;
282 float exactTitlePopularity = 0.0F;
283 int exactMatches = 0;
284 int exactMatchesWithArt = 0;
285 bool foundMatchWithArt =
false;
288 for (
const auto& lkup : qAsConst(list))
291 LOG(VB_GENERAL, LOG_INFO, QString(
"Comparing metadata title '%1' [%2] to recording title '%3'")
292 .arg(title, lkup->GetReleaseDate().toString(), originaltitle));
294 if (QString::compare(title, originaltitle, Qt::CaseInsensitive) == 0)
296 bool hasArtwork = ((!(lkup->GetArtwork(
kArtworkFanart)).empty()) ||
300 LOG(VB_GENERAL, LOG_INFO, QString(
"'%1', popularity = %2, ReleaseDate = %3")
302 .arg(lkup->GetPopularity())
303 .arg(lkup->GetReleaseDate().toString()));
311 if ((ret ==
nullptr) ||
313 ((!foundMatchWithArt) ||
314 ((lkup->GetPopularity() > exactTitlePopularity)) ||
315 ((exactTitlePopularity == 0.0F) && (lkup->GetReleaseDate() > exactTitleDate)))))
317 exactTitleDate = lkup->GetReleaseDate();
318 exactTitlePopularity = lkup->GetPopularity();
324 foundMatchWithArt =
true;
325 exactMatchesWithArt++;
329 titles.append(title);
332 LOG(VB_GENERAL, LOG_DEBUG, QString(
"exactMatches = %1, exactMatchesWithArt = %2")
334 .arg(exactMatchesWithArt));
338 if (exactMatches > 0)
340 if (exactMatches == 1)
342 LOG(VB_GENERAL, LOG_INFO, QString(
"Single exact title match for '%1'")
343 .arg(originaltitle));
347 LOG(VB_GENERAL, LOG_INFO,
348 QString(
"Multiple exact title matches found for '%1'. "
349 "Selecting most popular or most recent [%2]")
350 .arg(originaltitle, exactTitleDate.toString()));
356 QString bestTitle =
nearestName(originaltitle, titles);
359 if (bestTitle.isEmpty())
361 LOG(VB_GENERAL, LOG_ERR,
362 QString(
"No adequate match or multiple "
363 "matches found for %1. Update manually.")
364 .arg(originaltitle));
368 LOG(VB_GENERAL, LOG_INFO, QString(
"Best Title Match For %1: %2")
369 .arg(originaltitle, bestTitle));
372 for (
const auto& item : qAsConst(list))
374 if (item->GetTitle() == bestTitle)
391 LOG(VB_GENERAL, LOG_INFO, QString(
"Running Grabber: %1 %2")
392 .arg(cmd,
args.join(
" ")));
396 QByteArray result = grabber.
ReadAll();
397 if (!result.isEmpty())
400 doc.setContent(result,
true);
401 QDomElement root = doc.documentElement();
402 QDomElement item = root.firstChildElement(
"item");
404 while (!item.isNull())
410 item = item.nextSiblingElement(
"item");
440 LOG(VB_GENERAL, LOG_INFO,
441 QString(
"Movie grabber not functional. Aborting this run."));
452 LOG(VB_GENERAL, LOG_INFO,
453 QString(
"Television grabber not functional. Aborting this run."));
466 LOG(VB_GENERAL, LOG_INFO,
467 QString(
"Matching MXML file found. Parsing %1 for metadata...")
478 bool loaded = rf->SaveAs(mxmlraw);
482 if (doc.setContent(mxmlraw,
true))
485 QDomElement root = doc.documentElement();
486 item = root.firstChildElement(
"item");
490 LOG(VB_GENERAL, LOG_ERR,
491 QString(
"Corrupt or invalid MXML file."));
513 LOG(VB_GENERAL, LOG_INFO,
514 QString(
"Matching NFO file found. Parsing %1 for metadata...")
527 bool loaded = rf->SaveAs(nforaw);
533 if (doc.setContent(nforaw,
true))
536 item = doc.documentElement();
540 LOG(VB_GENERAL, LOG_ERR,
541 QString(
"Invalid NFO file found."));
651 bool searchcollection =
false;
665 if (list.isEmpty() && (!lookup->
GetSubtitle().isEmpty()))
675 searchcollection =
true;
677 else if (list.isEmpty())
683 searchcollection =
true;
711 if (!searchcollection && list.isEmpty() &&
724 for (
auto it = list.begin(); it != list.end(); ++it)
726 (*it)->SetIsCollection(searchcollection);
748 if (list.count() == 1)
779 if (origseason == 0 && origepisode == 0)
787 if (list.count() == 1)
807 QString ext = QFileInfo(qurl.path()).suffix();
812 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.
static bool Exists(const QString &url, struct stat *fileinfo)
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
RefCountHandler< T > takeFirstAndDecr(void)
Removes the first item in the list and returns it.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
uint Wait(std::chrono::seconds timeout=0s)
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
void Run(std::chrono::seconds timeout=0s)
Runs a command inside the /bin/sh shell. Returns immediately.
virtual int IncrRef(void)
Increments reference count.
@ kMSStdOut
allow access to stdout