Go to the documentation of this file.
4 #include <QCoreApplication>
19 #define LOC QString("NetContent: ")
31 QMutexLocker locker(&
m_lock);
41 LOG(VB_GENERAL, LOG_ERR,
LOC +
42 QString(
"Internet Content Source %1 cannot run, file missing.")
47 LOG(VB_GENERAL, LOG_INFO,
LOC +
48 QString(
"Internet Content Source %1 completed download, "
49 "beginning processing...").arg(
m_title));
51 QByteArray result = getTree.
ReadAll();
54 #if QT_VERSION < QT_VERSION_CHECK(6,5,0)
55 domDoc.setContent(result,
true);
57 domDoc.setContent(result, QDomDocument::ParseOption::UseNamespaceProcessing);
59 QDomElement root = domDoc.documentElement();
60 QDomElement channel = root.firstChildElement(
"channel");
64 while (!channel.isNull())
67 channel = channel.nextSiblingElement(
"channel");
70 LOG(VB_GENERAL, LOG_INFO,
LOC +
71 QString(
"Internet Content Source %1 completed processing, "
72 "marking as updated.").arg(
m_title));
76 LOG(VB_GENERAL, LOG_ERR,
LOC +
77 QString(
"Internet Content Source %1 crashed while grabbing tree.")
87 const QString &pathThumb, QDomElement& domElem,
90 QMutexLocker locker(&
m_lock);
96 QDomElement fileitem = domElem.firstChildElement(
"item");
97 while (!fileitem.isNull())
100 fileitem = fileitem.nextSiblingElement(
"item");
103 while (!articles.isEmpty())
106 pathThumb, articles.takeFirst(),
type);
110 QDomElement diritem = domElem.firstChildElement(
"directory");
111 while (!diritem.isNull())
113 QDomElement subfolder = diritem;
114 QString dirname = diritem.attribute(
"name");
115 QString dirthumb = diritem.attribute(
"thumbnail");
116 dirname.replace(
"/",
"|");
122 pathToUse = QString(
"%1/%2").arg(path, dirname);
129 diritem = diritem.nextSiblingElement(
"directory");
134 : m_timer(new QTimer()),
135 m_updateFreq(
gCoreContext->GetDurSetting<std::chrono::hours>(
"netsite.updateFreq", 24h))
168 QMutexLocker locker(&
m_lock);
212 "netsite.updateFreq", 24h);
219 LOG(VB_GENERAL, LOG_INFO,
LOC +
220 QString(
"Internet Content Source %1 Updating...")
248 const QString &pagenum)
252 LOG(VB_GENERAL, LOG_DEBUG,
"Search::executeSearch");
260 const QString& cmd = script;
264 if (!pagenum.isEmpty())
266 args.append(QString(
"-p"));
267 args.append(pagenum);
271 const QString& term = query;
274 LOG(VB_GENERAL, LOG_INFO,
LOC +
275 QString(
"Internet Search Query: %1 %2").arg(cmd,
args.join(
" ")));
293 QDomNodeList entries =
m_document.elementsByTagName(
"channel");
295 if (entries.count() == 0)
303 QDomNode itemNode = entries.item(0);
305 QDomNode Node = itemNode.namedItem(QString(
"numresults"));
312 QDomNodeList count =
m_document.elementsByTagName(
"item");
314 if (count.count() == 0)
320 Node = itemNode.namedItem(QString(
"returned"));
327 QDomNodeList items =
m_document.elementsByTagName(
"item");
329 if (items.count() == 0)
335 Node = itemNode.namedItem(QString(
"startindex"));
338 m_numIndex = Node.toElement().text().toUInt();
345 Node = itemNode.namedItem(QString(
"nextpagetoken"));
355 Node = itemNode.namedItem(QString(
"prevpagetoken"));
370 LOG(VB_GENERAL, LOG_WARNING,
LOC +
"Internet Search Timeout");
388 LOG(VB_GENERAL, LOG_INFO,
LOC +
389 "Internet Search Successfully Completed");
392 #if QT_VERSION < QT_VERSION_CHECK(6,5,0)
395 m_document.setContent(
m_data, QDomDocument::ParseOption::UseNamespaceProcessing);
412 #if QT_VERSION < QT_VERSION_CHECK(6,5,0)
415 m_document.setContent(
m_data, QDomDocument::ParseOption::UseNamespaceProcessing);
bool needsUpdate(GrabberScript *script, std::chrono::hours updateFreq)
const ArticleType & GetType() const
MythSystemLegacy * m_searchProcess
void finishedSearch(Search *item)
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
bool insertTreeArticleInDB(const QString &feedtitle, const QString &path, const QString &paththumb, ResultItem *item, ArticleType type)
void Term(bool force=false)
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
std::chrono::hours m_updateFreq
ResultItem::resultList m_videoList
const QString & GetTitle() const
void parseDBTree(const QString &feedtitle, const QString &path, const QString &pathThumb, QDomElement &domElem, ArticleType type)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
void SetData(QByteArray data)
GrabberDownloadThread(QObject *parent)
GrabberScript::scriptList findAllDBTreeGrabbers()
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
bool markTreeUpdated(GrabberScript *script, const QDateTime &curTime)
void SetCommand(const QString &command, uint flags)
Resets an existing MythSystemLegacy object to a new command.
@ GENERIC_EXIT_OK
Exited with no error.
static QString ShellEscape(const QString &in)
std::enable_if_t< std::chrono::__is_duration< T >::value, T > GetDurSetting(const QString &key, T defaultval=T::zero())
@ GENERIC_EXIT_CMD_NOT_FOUND
Command not found.
uint Wait(std::chrono::seconds timeout=0s)
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
GrabberDownloadThread * gdt
void run(void) override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
@ kMSRunShell
run process through shell
@ kMSRunBackground
run child in the background
~GrabberManager() override
~GrabberScript() override
bool clearTreeItems(const QString &feedcommand)
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
static ResultItem * ParseItem(const QDomElement &item)
void searchTimedOut(Search *item)
~GrabberDownloadThread() override
void slotProcessSearchExit(void)
This is a wrapper around QThread that does several additional things.
bool isRunning(void) const
QList< ResultItem * > resultList
QList< GrabberScript * > m_scripts
static ResultItem::resultList parseRSS(const QDomDocument &domDoc)
void Run(std::chrono::seconds timeout=0s)
Runs a command inside the /bin/sh shell. Returns immediately.
void executeSearch(const QString &script, const QString &query, const QString &pagenum="")
@ kMSStdOut
allow access to stdout
@ GENERIC_EXIT_TIMEOUT
Process timed out.