8#include <QRegularExpression>
22#define LOC QString("Metadata Grabber: ")
25static const QRegularExpression
kRetagRef { R
"(^([a-zA-Z0-9_\-\.]+\.[a-zA-Z0-9]{1,3})[:_](.*))" };
39 .m_setting=
"MovieGrabber",
40 .m_def=
"metadata/Movie/tmdb3.py" } },
42 .m_setting=
"TelevisionGrabber",
43 .m_def=
"metadata/Television/ttvdb4.py" } },
45 .m_setting=
"mythgame.MetadataGrabber",
46 .m_def=
"metadata/Game/giantbomb.py" } },
66 QString tmptype =
type.toLower();
90 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"Clearing grabber cache");
94 for (
const auto& grabberType : std::as_const(
grabberTypes))
96 QString path = (grabberType.m_path).arg(
GetShareDir());
97 QDir dir = QDir(path);
100 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
101 QString(
"No script directory %1").arg(path));
104 QStringList scripts = dir.entryList(QDir::Executable | QDir::Files);
105 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
106 QString(
"Found %1 scripts in %2").arg(scripts.count()).arg(path));
107 if (scripts.count() == 0)
112 for (
const auto& name : std::as_const(scripts))
114 QString cmd = QDir(path).filePath(name);
124 LOG(VB_GENERAL, LOG_DEBUG,
LOC +
"Failed " + name);
135 for (
const auto& item : std::as_const(tmpGrabberList))
138 retGrabberList.append(item);
141 return retGrabberList;
162 auto grabber =
GetType(defaultType);
163 if (!grabber.m_valid)
167 name = QString(
"Type %1").arg(defaultType);
168 LOG(VB_GENERAL, LOG_INFO,
169 QString(
"Grabber '%1' is not configured. Do you need to set PYTHONPATH?").arg(name));
176 QString tmptype =
type.toLower();
198 for (
const auto& item : std::as_const(list))
199 if (item.GetPath().endsWith(cmd))
204 QString fullcmd = QString(
"%1%2").arg(
GetShareDir(), cmd);
221 for (
const auto& item : std::as_const(list))
223 if (item.GetCommand() == tag)
232 for (
const auto& item : std::as_const(list))
234 if (item.Accepts(tag))
248 static QMutex s_reLock;
249 QMutexLocker lock(&s_reLock);
252 if (match.hasMatch())
253 tag = match.captured(1);
268 static QMutex s_reLock;
269 QMutexLocker lock(&s_reLock);
273 if (match.hasMatch())
274 return match.captured(2);
279 m_fullcommand(std::move(path))
304 QByteArray result = grabber.
ReadAll();
305 if (result.isEmpty())
310#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
311 doc.setContent(result,
true);
313 doc.setContent(result, QDomDocument::ParseOption::UseNamespaceProcessing);
315 QDomElement root = doc.documentElement();
351 m_name = item.firstChildElement(
"name").text();
352 m_author = item.firstChildElement(
"author").text();
353 m_thumbnail = item.firstChildElement(
"thumbnail").text();
354 m_command = item.firstChildElement(
"command").text();
355 m_description = item.firstChildElement(
"description").text();
356 m_version = item.firstChildElement(
"version").text().toFloat();
357 m_typestring = item.firstChildElement(
"type").text().toLower();
364 QDomElement accepts = item.firstChildElement(
"accepts");
365 if (!accepts.isNull())
367 while (!accepts.isNull())
370 accepts = accepts.nextSiblingElement(
"accepts");
398 LOG(VB_GENERAL, LOG_INFO, QString(
"Running Grabber: %1 %2")
405 QByteArray result = grabber.
ReadAll();
406 if (!result.isEmpty())
409#if QT_VERSION < QT_VERSION_CHECK(6,5,0)
410 doc.setContent(result,
true);
412 doc.setContent(result, QDomDocument::ParseOption::UseNamespaceProcessing);
414 QDomElement root = doc.documentElement();
415 QDomElement item = root.firstChildElement(
"item");
417 while (!item.isNull())
429 item = item.nextSiblingElement(
"item");
446 metadataMap[
"name"] =
m_name;
451 metadataMap[
"version"] = QString::number(
m_version);
490 [[maybe_unused]]
const QString &title,
491 const QString &subtitle,
525 << QString::number(season)
526 << QString::number(episode);
QString GetSetting(const QString &key, const QString &defaultval="")
QString GetLanguage(void)
Returns two character ISO-639 language descriptor for UI language.
MythLocale * GetLocale(void) const
QString GetCountryCode() const
uint Wait(std::chrono::seconds timeout=0s)
void Run(std::chrono::seconds timeout=0s)
Runs a command inside the /bin/sh shell. Returns immediately.
virtual int DecrRef(void)
Decrements reference count and deletes on 0.
@ GENERIC_EXIT_OK
Exited with no error.
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
QString GetShareDir(void)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
@ kMSStdOut
allow access to stdout
@ kMSRunShell
run process through shell
QHash< QString, QString > InfoMap
QDateTime current(bool stripped)
Returns current Date and Time in UTC.